Why does this program return complex numbers?
3 views (last 30 days)
Show older comments
I am using this code
to calculate the Itakura-Saito distance between two waveforms. When I used to it on several thousand different FFTs of the data it worked fine, however using it on the raw data produced results like "NaN -1.4918e+000i".
Looking at the code it seemed the NaNs were coming from any zeros in the input data as it divides by it. So I coded it to replace any zeros with 0.00001. This still leaves the complex numbers.
It's more down to application of theory then any coding errors but if someone could explain the reasoning behind it I'd be grateful.
0 Comments
Answers (1)
Babak
on 13 Aug 2012
I think the complex numbers come from the function log used in your code at line 0064.
Note that the input of log function should be positive real number or it will give out a complex output! Check to see if the argument of log positive or not. In other words, if
r=pf1(1:nx,:)./pf2(1:nx,:);
is always positive.
0 Comments
See Also
Categories
Find more on Logical 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!