Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as pl
- from scipy.fftpack import fft, ifft, fftfreq
- ######################################################################################################
- SAMPLE_RATE = 1024
- WINDOW_SIZE = 1024
- N = 1024
- fr1 = 50 #frequency 1
- fr2 = 80 #frequency 2
- freq = np.absolute(fftfreq(N))*WINDOW_SIZE
- ######################################################################################################
- t = np.linspace(0,1,SAMPLE_RATE)[:WINDOW_SIZE]
- sine_wave = np.sin(fr1*2*np.pi*t) + 0.5*np.sin(fr2*2*np.pi*t)
- sine_wave_hamming = sine_wave*np.hamming(WINDOW_SIZE)
- sine_wave_hanning = sine_wave*np.hanning(WINDOW_SIZE)
- ######################################################################################################
- sine_wavefft = np.absolute(fft(sine_wave,N))/WINDOW_SIZE*2
- sine_wave_hammingfft = np.absolute(fft(sine_wave_hamming,N))/WINDOW_SIZE*2
- sine_wave_hanningfft = np.absolute(fft(sine_wave_hanning,N))/WINDOW_SIZE*2
- ######################################################################################################
- pl.subplot(3,1,1)
- pl.xlabel("Freq")
- pl.ylabel("Amplitude")
- pl.grid()
- pl.plot(freq, sine_wavefft)
- pl.subplot(3,1,2)
- pl.xlabel("Freq")
- pl.ylabel("Amplitude")
- pl.grid()
- pl.plot(freq, sine_wave_hammingfft)
- pl.subplot(3,1,3)
- pl.xlabel("Freq")
- pl.ylabel("Amplitude")
- pl.grid()
- pl.plot(freq, sine_wave_hanningfft)
- ######################################################################################################
- pl.tight_layout()
- pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement