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. instead when I try to correct the error I get
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
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.
Since the rect shape is little far from 0 index, your FFT is oscillated in the sinc shaped envelop with some mathematical reasons.