Warning: Imaginary parts of complex X and/or Y arguments ignored

I got this problem while applying FFT,
>> f=1803*(0:(2^(n-1)-1))/2^n;
the corresponding matrix 'f' is coming out to be a row vector instead of column. due to this MATLAB warns me 'Warning: Imaginary parts of complex X and/or Y arguments ignored' when I try to plot(f, Pyy(1:2^(n-1))) Pyy is a column vector.
How can I solve this problem and get the plot?

Answers (3)

That error message warns that you are trying to plot a complex function. Try
whos
to see which complex function you are trying to plot.
Hope this helps.
Greg
f = (1803 * (0:(2^(n-1)-1)) / 2^n) .';
And then f will be a column vector.
You will find, though, that this absolutely will not solve your complex problem.
Hint: you would get exactly the same problem if you were to attempt
plot(1 + 2i)
I'm guessing from your variable, Pyy, that you are trying to plot a spectrum and f is your frequency vector. Then assuming that f and Pyy have the same length.
isequal(length(f),length(Pyy))
should return a 1.
Just do
plot(f,abs(Pyy))
% or usually better if you have a power spectral density estimate
% use dB
plot(f,10*log10(abs(Pyy)))

2 Comments

Yes, you are absolutely right Walter, thank you! I've corrected the typo.

Sign in to comment.

Categories

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

Asked:

on 13 Jan 2013

Community Treasure Hunt

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

Start Hunting!