Why do i have to take the abs when using fft and ifft?

조회 수: 61 (최근 30일)
Brenden
Brenden 2011년 5월 31일
I have a simple code to test how matlab processes the fft and ifft command:
clear all
close all
N=1e4;
dx=0.01;
Axis=(-ceil(N/2):ceil(N/2));
x=dx*Axis;
y=exp(-(x.^2)/(2*(1^2)));
Fy=fftshift(abs(fft(y)));
IFy=ifftshift(abs(ifft(Fy)));
y1=exp(-((x-3).^2)/(2*(1^2)))+ exp(-((x+3).^2)/(2*1^2)));
Fy1=fftshift((fft(y1)));
IFy1=abs(ifft(Fy1));
figure(1)
subplot(311);
plot(x,y)
subplot(312)
plot(x,Fy)
subplot(313)
plot(x,IFy)
figure(2)
subplot(311);
plot(x,y1)
subplot(312)
plot(x,Fy1)
subplot(313)
plot(x,IFy1)
Firstly, why in the first case, figure 1, do i have to take the abs in the fft and ifft. the fourier of a gaussian is a gaussian and the abs should not have to be taken.
Second, in the second case why can i not use the same code. ie why does the abs have to be left out in the fft and there is still a warning once run:
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In Untitled at 38

채택된 답변

Ivan van der Kroon
Ivan van der Kroon 2011년 5월 31일
Walter means that discrete Fourier transforms are not exactly as what one would expect from their continuous counterparts. You check the web why and how this works and how to minimize the undesired artifacts in your transformations.
As for the plot of IFY; first you have to have the Fourier transform as input for the ifft and not the absolute values. Secondly, you make a mistake in the order of the operations:
Fy=fftshift(fft(y));
IFy=ifft(ifftshift(Fy));
plot(abs(Fy)), etc
You see, an ifft undoes an fft and an ifftshift undoes an fftshift, hence
y=ifft(ifftshift(fftshift(fft(y))));
for any y, exept for round-off errors. Maybe the 'symmetric' input for the ifft could be useful to you as well.
  댓글 수: 2
Brenden
Brenden 2011년 5월 31일
Thanks for the in put.
So the graph of the fourier itself is not correct for a continuous equation, only the discrete data points that where taken to approximate it? and to find the proper fourier for the continuous equation you simply take the abs of the fft when you plot?
Walter Roberson
Walter Roberson 2011년 5월 31일
To find the proper fourier of a continuous equation, use the Symbolic Toolbox. Taking abs() is not sufficient (especially if the original equation involves complex numbers.)
But yes, the plot your are seeing is of the discrete fourier of the approximating data points. You very likely have round-off errors in calculating those approximations that are leading to phase shifts.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 5월 31일
The fourier of a gaussian might be a gaussian, but your data is only the approximation of a gaussian.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 5월 31일
One does not get false graphs: one gets correct graphs for the data that was input. fft() cannot (and *should not*) do anything to "correct" the data input to it.
Brenden
Brenden 2011년 5월 31일
Excuse my wording, the program is only as good as the the code it is made up of. How then can i fix my code to get the proper fourier of the equations i am entering?
sorry i am new to matlab
thank you for your time,
BN

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by