Search code examples
matlabfftrect

FFT in MATLAB producing amplitude confusion FFT of rect not making sinc


I am doing a FFT in MATLAB. As I am trying to do the FFT of a rect it does not end up being a sinc function. enter image description here instead when I try to correct the error I get enter image description here This correction of using abs I have seen all over the internet but it does not create the sinc function. Here is all the code that I am using.

x = linspace(-15,15,257);
x = x(1:256);
y = rectangularPulse(x)
plot(x,y)
Y = fft(y);
plot(x, fftshift(abs(Y)))

Any help would be greatly appreciated.

Thanks,

T


Solution

  • FFT doesn't care x-axis of your input signal.

    Just, change your code like below.

    x = linspace(0,30,257);
    y = rectangularPulse(x)
    figure(1)
    plot(y)
    Y = fft(y);
    figure(2)
    plot(fftshift(real(Y)))
    

    With this code, you can see sinc function after fft.

    In your original code, FFT just considers your input signal as below.

    enter image description here

    Since the rect shape is little far from 0 index, your FFT is oscillated in the sinc shaped envelop with some mathematical reasons.