Why does this program return complex numbers?

3 Ansichten (letzte 30 Tage)
John Doe
John Doe am 13 Aug. 2012
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.

Antworten (1)

Babak
Babak am 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.

Community Treasure Hunt

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

Start Hunting!

Translated by