I have a signal that I have acquired from an experimental instrument, that I wish to examine in the frequency domain. I don't care about phase for this exercise, I only care about magnitude. I deliberately planned my experiment so that the dominant frequency would fall completely within a single fft bin. when I use the scipy fft function on an unfiltered window, the fft shows a clean spike as expected. However, when I first apply a numpy.hanning window, the spikes become smeared. Note the mean of the signal (the zero bin) also shows the same smearing effect. My code is as follows:
eta=[instrument data series of length 2048]
etaHann=np.hanning(nfft)*eta
EtaSpectrum=abs(sp.fft(eta))
EtaSpectrum=EtaSpectrum*2/nfft # convert to amplitude
EtaSpectrumHann=abs(sp.fft(etaHann))
EtaSpectrumHann=EtaSpectrumHann*2*2/nfft # also correct for Hann filter
frequencies=np.linspace(0,samplingFrequency,nfft)
plt.plot(frequencies[0:200],EtaSpectrumHann[0:200],'b.-',label='Hann filtered')
plt.plot(frequencies[0:200],EtaSpectrum[0:200],'c.-',label='rectangular')
plt.xlim(-0.01,2)
plt.xlabel('frequency')
plt.ylabel('amplitude')
plt.grid()
plt.legend(loc=0)
plt.show()
Is this meant to happen? Does anyone else get this problem? For my data, it seems a rectangular window is fine, but to me it seems that the Hanning window must be wrong here, as the integral of the entire spectrum should be the same (after I multiplied by 2 to correct amplitude), but in this case it seems to be different.