Ripples in Fourier Transform

3 views (last 30 days)
Aman
Aman on 28 Feb 2017
Edited: David Goodmanson on 6 Mar 2017
I am trying to plot fourier transform of sinc function using following code. In plot, I can see some ripples. Do anybody know the possible reasons of these ripples. As the spectrum should be rectangular without any ripples. Any help will be appreciated. y = sinc(x); plot(y) s=abs(fft(y)); z = fftshift(s); plot(z);

Accepted Answer

David Goodmanson
David Goodmanson on 4 Mar 2017
Hi Aman,
You don't say what your x array was, but I believe the effect occurs because that array has finite width and cuts off the sinc function on both sides. One can use a zillion points to widen the x array, but since sinc falls off very slowly as 1/x, the fft is not well suited to this particular exercise. It's at least as effective to use a sensible width and damp down the sinc function at each end in such a way as to not affect its behavior too much. Rather than use a lowpass filter, here I multiplied sinc by a (physically nonrealizable) gaussian function. The following code gives a fairly good rectangular function, slightly rounded off. For demo purposes the code does not worry about normalization or the scaling of the x axis in the final plot.
n = 2^11;
x = (-n:n-1)*2*pi/10; % 10 array points per cycle
A = max(x)/3; % set an appropriate gaussian width
G = exp(-x.^2./A^2); % gaussian
y = sin(x)./x; y(x==0) = 1; % sinc function
figure(1)
plot(x,y,x,y.*G) % zoom in to compare
z = fftshift(fft(ifftshift(y.*G)));
disp(max(abs(imag(z)))) % show that imag(z) is minuscule
figure(2)
plot(real(z))
  2 Comments
Aman
Aman on 5 Mar 2017
Hi David,Thanks for answer. Could you please elaborate the step z = fftshift(fft(ifftshift(y.*G))) why you take ifftshift of (y.*G) I am new to matlab, so dnt know much about it.
Thanks
David Goodmanson
David Goodmanson on 6 Mar 2017
Edited: David Goodmanson on 6 Mar 2017
Hi Aman, The idea here is that in order to properly create the sinc function, x=0 is in the middle of the x array. But Matlab fft wants a function defined by an x array that has x=0 at the start. ifftshift swaps halves of the array so that y(x=0) is at the start of the y array.
Returning to the idea of x=0 in the middle: if N is the number of points in the array, to get the right answer for N even (N=2n) you need to define x as (-n:n-1) NOT (-n+1:n). For odd N there is no ambiguity about where the point in the middle is to put x=0.
Not doing the ifftshift introduces a phase factor into the result z. You need to use ifftshift to get an exact result, but if you are just going to plot abs(z), using ifftshift does not matter.
For even N, fftshift and ifftshift do the same thing. But they are not quite the same for odd N. The code as written should work for N either odd or even.

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!