1
$\begingroup$

I was making a plot to show side lobes for different spectral windows and I noticed if I take a simple fft of a rectangle window, I don't see any side lobes. I think I'm just making a simple mistake.

Here is the Python code I ran:

from matplotlib import pyplot as plt
import numpy as np
fAxis = np.linspace(-1/2,1/2,100)
rect = np.ones( 100 )
specWindow = abs(np.fft.fftshift(np.fft.fft(rect)))
plt.plot(specWindow)
plt.show()

enter image description here

Could anyone explain how to change my code slightly to see the side lobes I'd expect. I expect a discrete FT of a rectangle function to give me the Dirichlet kernel.

$\endgroup$
  • $\begingroup$ I think the problem is that I'm after a spectral window, and that is distinct from a simple discrete Fourier transform of the time domain sequence. $\endgroup$ – ncRubert Dec 6 '13 at 23:46
3
$\begingroup$

You have to imagine your signal as being periodically extended forever in both directions. Since you square window is constant over the whole interval when it is periodically extended it becomes flat everywhere. In other words, you don't have a square window. You just have a flat line. That's why only the zero frequency band on the fft has any amplitude. Try doing it again with some zeros on either side of your square window.

$\endgroup$
  • $\begingroup$ Indeed. Usually the signal is zero-padded to the right. Use somthing like rect_m = np.zeros(1024) rect_m[0:100] = rect. This also will give the FFT 1024 bins instead of only 100. $\endgroup$ – Martin Scharrer Jan 30 '18 at 8:33
2
$\begingroup$

Zero pad your input and use a larger FFT. This has the effect of interpolating your frequency domain points. Then use 10*log10(magnitude_squared_of_fft_outputs). This approach worked fine for me in duplicating the results shown in the classic 1978 windows paper by Harris [ http://web.mit.edu/xiphmont/Public/windows.pdf ].

$\endgroup$
1
$\begingroup$

Zero-pad your rectangle (keep the rectangle the same length) and use a much longer (say 10X or 16X longer) FFT to increase the FFT frequency bin resolution enough to see the side lobes of the Sinc function. Make sure to plot the complex components, not just the magnitude.

Increase the zero-padding even more for more resolution on the transform of your window.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.