Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python code
- import numpy as np
- import matplotlib.pyplot as plt
- dur = 20
- fs = 1024
- freq = np.arange(1, 500, 1)
- t1 = np.arange(0, dur, 1/fs)
- x1 = np.sum([np.sin(2*np.pi*f*t1) for f in freq], axis=0)
- nfft = 1024
- X1 = np.fft.fft(x1, nfft)[:nfft//2]
- f1 = np.arange(0, nfft//2) * fs / nfft
- plt.figure()
- plt.title('Baseline FFT Output')
- plt.plot(f1, np.abs(X1))
- plt.grid()
- plt.xlim([0, nfft/2])
- plt.show()
- step = 10
- x2 = x1[::step] # some kind of downsampling??
- fs2 = fs/10
- nfft = 1024
- X2 = np.fft.fft(x2, nfft)[:nfft//2]
- f2 = np.arange(0, nfft//2) * fs2 / nfft
- plt.figure(figsize=(10,5))
- plt.title('New FFT Output')
- plt.plot(f2, np.abs(X2) / nfft)
- plt.xlabel('Hz')
- plt.grid()
- plt.xlim([0, 18])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement