why a component of fft to a nonzero vector is a zero(0+i0).

1 次查看(过去 30 天)
a1=[0.0249643366619116 0.0271041369472183 0.0271041369472183 0.0242510699001427 0.0235378031383738 0.0256776034236805 0.0271041369472183 0.0285306704707561 0.0285306704707561 0.0292439372325250 0.0313837375178317 0.0328102710413695 0.0335235378031384 0.0328102710413695 0.0328102710413695 0.0335235378031384 0.0349500713266762 0.0356633380884451 0.0378031383737518 0.0399429386590585 0.0413694721825963 0.0420827389443652 0.0442225392296719 0.0470756062767475 0.0499286733238231 0.0513552068473609 0.0520684736091298 0.0556348074179743 0.0592011412268188 0.0620542082738944 0.0634807417974322 0.0649072753209700 0.0691868758915835 0.0706134094151213 0.0720399429386591 0.0727532097004280 0.0741797432239658 0.0756062767475036 0.0741797432239658 0.0734664764621969 0.0734664764621969 0.0741797432239658 0.0741797432239658 0.0727532097004280 0.0727532097004280 0.0713266761768902 0.0699001426533524 0.0670470756062768 0.0649072753209700 0.0634807417974322 0.0634807417974322 0.0627674750356633 0.0606276747503566 0.0577746077032810 0.0549215406562054 0.0527817403708987 0.0513552068473609 0.0513552068473609 0.0520684736091298 0.0520684736091298 0.0513552068473609 0.0506419400855920 0.0506419400855920 0.0513552068473609 0.0506419400855920 0.0492154065620542 0.0477888730385164 0.0463623395149786 0.0456490727532097 0.0449358059914408 0.0449358059914408 0.0442225392296719 0.0420827389443652 0.0399429386590585 0.0378031383737520 0.0370898716119829 0.0363766048502140 0.0370898716119829 0.0385164051355207 0.0399429386590585 0.0427960057061341 0.0456490727532097 0.0470756062767475 0.0463623395149786 0.0456490727532097 0.0449358059914408 0.0427960057061341 0.0406562054208274 0.0363766048502140 0.0328102710413695 0.0292439372325250 0.0256776034236805 0.0221112696148360 0.0192582025677603 0.0192582025677603 0.0185449358059914 0.0178316690442225 0.0164051355206847 0.0164051355206847 0.0164051355206847 0.0164051355206847 0.0164051355206847 0.0156918687589158 0.0199714693295292 0.0228245363766049 0.0249643366619116 0.0199714693295292 0.0164051355206847 0.0135520684736091 0.0135520684736091 0.0135520684736091 0.0149786019971469 0.0149786019971469 0.0164051355206847 0.0171184022824536 0.0178316690442225 0.0192582025677603 0.0192582025677603 0.0192582025677603 0.0171184022824536 0.0178316690442225 0.0185449358059914 0.0206847360912981 0.0178316690442225 0.0156918687589158 0.0128388017118402 0.0142653352353780 0.0149786019971469 0.0156918687589158 0.0149786019971469 0.0149786019971469 0.0149786019971469 0.0171184022824536 0.0164051355206847 0.0156918687589158 0.0149786019971469 0.0164051355206847 0.0171184022824536 0.0185449358059914 0.0178316690442225 0.0178316690442225 0.0192582025677603 0.0185449358059914 0.0206847360912981 0.0192582025677603 0.0213980028530670 0.0221112696148360 0.0249643366619116];
a2=[0.0213980028530670 0.0313837375178317 0.0235378031383738 0.0213980028530670 0.0299572039942939 0.0256776034236805 0.0263908701854494 0.0271041369472183 0.0271041369472183 0.0271041369472183 0.0320970042796006 0.0328102710413695 0.0335235378031384 0.0306704707560628 0.0306704707560628 0.0349500713266762 0.0378031383737518 0.0378031383737518 0.0449358059914408 0.0385164051355207 0.0342368045649073 0.0456490727532097 0.0413694721825963 0.0470756062767475 0.0584878744650499 0.0556348074179743 0.0534950071326676 0.0527817403708987 0.0634807417974322 0.0556348074179743 0.0599144079885877 0.0613409415121255 0.0670470756062768 0.0727532097004280 0.0677603423680457 0.0663338088445079 0.0706134094151213 0.0691868758915835 0.0734664764621969 0.0756062767475036 0.0699001426533524 0.0777460770328103 0.0720399429386591 0.0756062767475036 0.0706134094151213 0.0649072753209700 0.0649072753209700 0.0670470756062768 0.0599144079885877 0.0592011412268188 0.0620542082738944 0.0592011412268188 0.0534950071326676 0.0520684736091298 0.0492154065620542 0.0470756062767475 0.0427960057061341 0.0435092724679030 0.0470756062767475 0.0456490727532097 0.0378031383737518 0.0420827389443652 0.0463623395149786 0.0463623395149786 0.0499286733238231 0.0406562054208274 0.0435092724679030 0.0463623395149786 0.0463623395149786 0.0392296718972896 0.0385164051355207 0.0363766048502140 0.0385164051355207 0.0413694721825963 0.0356633380884451 0.0349500713266762 0.0285306704707561 0.0306704707560628 0.0385164051355207 0.0392296718972896 0.0427960057061341 0.0485021398002853 0.0477888730385164 0.0420827389443652 0.0413694721825963 0.0349500713266762 0.0406562054208274 0.0378031383737518 0.0235378031383738 0.0271041369472183 0.0299572039942939 0.0342368045649073 0.0249643366619116 0.0171184022824536 0.0149786019971469 0.0213980028530670 0.0171184022824536 0.0128388017118402 0.0135520684736091 0.0199714693295292 0.0135520684736091 0.0185449358059914 0.0192582025677603 0.0199714693295292 0.0106990014265335 0.0263908701854494 0.0221112696148360 0.0178316690442225 0.0121255349500713 0.0171184022824536 0.0192582025677603 0.0192582025677603 0.0192582025677603 0.0106990014265335 0.0135520684736091 0.0242510699001427 0.00998573466476462 0.0114122681883024 0.0156918687589158 0.0192582025677603 0.0192582025677603 0.0121255349500713 0.0206847360912981 0.0328102710413695 0.0128388017118402 0.0128388017118402 0.00427960057061341 0.00784593437945792 0.0164051355206847 0.00927246790299572 0.00713266761768902 0.00855920114122682 0.00213980028530670 0.00784593437945792 0.00570613409415121 0.00927246790299572 0.0142653352353780 0.0221112696148360 0.0106990014265335 0.00998573466476462 0.0178316690442225 0.00927246790299572 0.0349500713266762 0.0263908701854494 0.00855920114122682 0.0142653352353780 0.0442225392296719 0.0192582025677603];
These are two vectors (of length 148) I am using. I'm trying to find Phase correlation between vectors a1 and a2.
The code for phase correlation is:
x=(fft(a1).*conj(fft(a2)));
x1=real(ifft(x./abs(x)));
phase_correlation=x1(1);
I'm getting NaN output.
In fft(a1), 75 th component have zero in real part as well as in imaginary part. That is creating problem. Is there any solution for this?
I'm using Matlab(R2016a).
Thanks, in advance.
  5 个评论
Temu Gautama
Temu Gautama 2020-2-13
Solution-wise, you can just add eps:
x1 = real( ifft( x ./ ( abs(x) + eps )));
I am assuming you mean phase-transform cross-correlation (phat), right? This basically tries to weight every frequency bin equally. So, if this bin is zero, it is probably safe not to take it into account (which is done by dividing zero by eps).
Temu
palla
palla 2020-2-14
I thank you all, for trying to help me.
Yes Walter Roberson, what you have said is correct, definitely there is a round off error. Actually when i copy those variables a1 and a2 from matlab and reuse in command window to compute phase correlation i'm also not getting any problem. but when load dataset contain large samples including these two samples (a1 and a2), i'm facing problem. I thought it may be some preciscion error. Interesting i observed that these two variables are not equal to the respective samples of the data i'm using. it's really confusing me.
And, thanks Temu Gautam. Your suggestion is working well but there is a slight difference in correlation value (if i add eps - 0.1392) as that of original (if i get without addind eps - 0.1325). As you have mentioned, phase correlation and PHAT are similar and i think PHAT identifies location where maximum peaks occurs whereas phase correlation assumes first location will have maximum peak if both signals are alike.
Thanks Bhaskar R, your suggestion helped to findout if any nan exist in computing phase correlation between other samples of the data i'm using.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by