我正在使用 Goertzel 算法来获取特定频率的幅度。 我现在正在尝试从中获取相位,但我不知道如何。
有人可以解释并告诉我如何从这段代码中获得某个特定-f 的阶段吗?
此外,我将它用于 16khz,采样率为 44.1。我可以运行它的最小样本长度是多少?
double AlgorithmGoertzel( int16_t *sample,int sampleRate, double Freq, int len )
{
double realW = 2.0 * cos(2.0 * M_PI * Freq / sampleRate);
double imagW = 2.0 * sin(2.0 * M_PI * Freq / sampleRate);
double d1 = 0;
double d2 = 0;
double y;
for (int i = 0; i < len; i++) {
y=(double)(signed short)sample[i] +realW * d1 - d2;
d2 = d1;
d1 = y;
}
double rR = 0.5 * realW *d1-d2;
double rI = 0.5 * imagW *d1-d2;
return (sqrt(pow(rR, 2)+pow(rI,2)))/len;
}
最佳答案
进行直角坐标到极坐标的转换。这将为您提供相位和幅度。
幅度 = sqrt((Vreal * Vreal)+(Vimag * Vimag))
phase = atan2 (Vimag, Vreal)
关于algorithm - Goertzel算法获取相位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489519/