Why does this program return complex numbers?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Babak
2012-8-13
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!