Matlab - Fourier transform doesn't look as expected

Thread Starter

lll

Joined Mar 7, 2012
21
x=-5:.001:5;
y = ( (-0.5 <= x) .* (x < 0.5 ) ); %the rect function
plot(x,fft(y)) %looks nothing like sinc function


Why doesn't the graph look like the sinc function?
 

MrChips

Joined Oct 2, 2009
30,821
You have a number of problems.

Firstly, the result of the fft is complex. You need to find the magnitude of each complex pair or you can use the abs( ) function but this doesn't give you the sign.

Secondly, the fft will produce positive frequencies followed by negative frequencies.
In order to rearrange the array to look the way you see it in the text books you use the fftshift( ) function.

Thirdly, you have way too many points so the sinc function will be very narrow.
Try using

x = -5:.1:5;

for 101 points
 
Last edited:
Top