MATLAB: Do I get a high frequency oscillation when I take the FFT of a rectangular pulse

fftfftshiftprocessingringingsignalSignal Processing Toolboxtoolbox

Why do I get a high frequency oscillation when I take the FFT of a rectangular pulse?
I am taking the FFT of a Rectangular Pulse and I expect a nice smooth Sinc wave. But what I get is a Sinc wave with a high frequency oscillation. Why is this?

Best Answer

The results you are getting from the FFT are correct and expected. The reason for the oscillations is because the Rectangular Pulse is not centered about zero, which results in a phase shift of the FFT output. The phase shift is essentially negating every other element (odd samples) of the output of the FFT which causes the high frequency oscillation you're observing. This is explained by the time-shifted Fourier Transform Theorem.
One way to avoid the oscillations is to use FFTSHIFT on the Rectangular Pulse before taking the FFT. For example if "rect" is the Rectangular Pulse:
fftrect=fftshift(fft(fftshift(rect)));