Real and imaginary part of fourier transform using fft.
26 views (last 30 days)
Show older comments
Venkata Rajeshwar Majety
on 31 Jan 2018
Commented: David Goodmanson
on 1 Feb 2018
Hello.
Why am I getting a very different value from what is expected when we compute a fourier transform?
For example, let's consider a Gaussian distribution A*exp(-b^2*(y-y0).^2). Here, A is the amplitude, b is the parameter for controlling the width of the distribution and y0 is the point at which the distribution is centered.
I determined the fourier transform of this distribution analytically and obtained the transform as (A*sqrt(pi)/b)*exp(-(xaxis/(2*b)).^2).*exp(-1i*(xaxis*y0)).
I performed a simple test. I took y0 = 0. This would essentially give me the transform with only real part and no imaginary part. However, Matlab 'fft' gives a very different answer.
I am including the graphs obtained and the code so that I can paint a clear picture.
dy = 0.5;
y = dy*(-N/2+1:(N/2)).';
A = 52; % Amplitude
b = 0.25; % Increase for decreasing the width of the distribution
y0 = 0; % Peak center
S = A*exp(-b^2*(y-y0).^2); % (Gaussian)
FT = fft(S)*dy; % Fourier transform
FT = ([FT(N/2+2:end,1);FT(1:floor(N/2+1),1)]);
df = (2*pi/(N*dy));
xaxis = df*(-N/2+1:(N/2)).';
FT_analytical = (A*sqrt(pi)/b)*exp(-(xaxis/(2*b)).^2).*exp(-1i*(xaxis*y0));



Can someone explain this to me, please?
Thanks.
0 Comments
Accepted Answer
David Goodmanson
on 1 Feb 2018
Hi Venkata,
This is close, but you have to make a couple of adjustments. These are
y = dy*(-N/2:(N/2-1)).';
.
.
FT = fft(ifftshift(S))*dy; % Fourier transform
The first change puts y = 0 as the first point in the second half of the y array (assuming N is even). The second change swaps halves and moves the point corresponding to y = 0 down to the first point in the new y array. This is done because the fft always assumes that y=0 is the first point in the input array.
With those changes you get what you expect. Without the ifftshift, the fft is transforming an array that is shifted in the y coordinate, which produces an oscillatory phase factor in the result.
Also, if y corresponds to time and f is frequency, then the scaling is df = 1/(N*dy)
2 Comments
David Goodmanson
on 1 Feb 2018
I didn't check this in any detail, but yes, to do an fft the point corresponding to y = 0 should be the first point in input the array, and to do an ifft the point corresponding to f = 0 should be the first point in that input array. You just have to keep track of where things are. For example, if you do b = fft(a), b = fftshift(b) (say for plotting purposes), you need to do b = ifftshift(b) before using the ifft to go back. Either that or make a copy of b and fftshift that, leaving the original b alone to use in the ifft.
More Answers (0)
See Also
Categories
Find more on Transforms 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!