Is it possible to obtain the imaginary parts along with real part in the evaluation of fast fourier transform?

2 次查看(过去 30 天)
I have a program , a part of which is shown below:
X=x(:,1); %assigning X, all the values of x of length n.
Y = fft(X,n); % calculating the fast fourier transform of X.
T=fft(t,n); %calculating the fast fourier transform of time.
plot(log10(T),log10(Y.^2),'R')
After the execution of the program, I get the spectral plot, but a warning too: Warning: Imaginary parts of complex X and/or Y arguments ignored.
This means imaginary parts has been excluded. I am keen interested in, if I am be able to get the plot which will involve both real and imaginary parts. I will be much thankful, if anyone take interst to clear my problem.

采纳的回答

Wayne King
Wayne King 2012-10-13
编辑:Wayne King 2012-10-13
That is because you want to plot only the magnitude of the DFT coefficients, or the magnitudes squared
plot(log10(abs(T)),log10(abs(Y).^2),'r')
I have no idea why you are taking the Fourier transform of your time vector, that is not the frequency vector.
You need to create a meaningful frequency vector by knowing the number of points and the sampling frequency (interval)
t = 0:0.001:1-0.001; %sampling interval is 0.001
Fs = 1000;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
freq = 0:Fs/length(x):Fs/2;
xdft = xdft(1:length(x)/2+1);
plot(freq,20*log10(abs(xdft)))
Of course in the DFT coefficients, you certainly have the imaginary parts.
  5 个评论
Rizwana Junaid
Rizwana Junaid 2012-10-13
Thank you so much for your responsive act.
I still dont understand. suppose If the original data is squared first X=x^2,
then fft of X is performed which have all the imaginary and real parts. then why does it not give the imaginary parts? and gives the warning.
please reply
Wayne King
Wayne King 2012-10-13
编辑:Wayne King 2012-10-13
The warning is because you are trying to use plot(), which is for 1-D data with a complex-valued function. You can plot the real and imaginary parts separately:
t = 0:0.001:1-0.001; %sampling interval is 0.001
Fs = 1000;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
freq = 0:Fs/length(x):Fs/2;
xdft = xdft(1:length(x)/2+1);
plot(freq,real(xdft),'b');
hold on;
plot(freq,imag(xdft),'r'); legend('Real','Imaginary')

请先登录,再进行评论。

更多回答(0 个)

类别

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