【发布时间】:2014-03-06 15:30:41
【问题描述】:
我一直在分析代码并试图理解算法的每个部分。 我遇到了使用按位和运算符的部分
if (qpd >= 0) qpd += qpd&1;
else qpd -= qpd&1;
据我了解,该算法希望使用 1 作为变量 qpd 的掩码,但由于数字仅为 1,因此执行几乎不进行任何更改的操作没有多大意义。由于我迷路了,请在这里赐教。
使用按位运算符从数组中获取数据的幅度和频率的for循环如下:
/* this is the analysis step */
for (k = 0; k <= fftFrameSize2; k++) {
/* de-interlace FFT buffer */
real = gFFTworksp[2*k];
imag = gFFTworksp[2*k+1];
/* compute magnitude and phase */
magn = 2.*sqrt(real*real + imag*imag);
phase = atan2(imag,real);
/* compute phase difference */
tmp = phase - gLastPhase[k];
gLastPhase[k] = phase;
/* subtract expected phase difference */
tmp -= (double)k*expct;
/* map delta phase into +/- Pi interval */
qpd = tmp/M_PI;
if (qpd >= 0) qpd += qpd&1;
else qpd -= qpd&1;
tmp -= M_PI*(double)qpd;
/* get deviation from bin frequency from the +/- Pi interval */
tmp = osamp*tmp/(2.*M_PI);
/* compute the k-th partials' true frequency */
tmp = (double)k*freqPerBin + tmp*freqPerBin;
/* store magnitude and true frequency in analysis arrays */
gAnaMagn[k] = magn;
gAnaFreq[k] = tmp;
}
【问题讨论】:
-
“几乎没有做任何改变”是没有意义的。在某些情况下,它确实会做出改变。它没有什么虚拟的。
-
哦,对不起,马特!我的意思是没有做任何改变,当我从对 & 位运算符的理解中阅读它时,它似乎没有做任何改变。终于从下面的答案中理解了。 :)
标签: c++ signal-processing