我需要用C#中的yin算法計算基本頻率。使用C#中的yin方法計算基本頻率
我有一個數組(數據[44100]),其中包含一個1秒長的250Hz正弦波的幅度。這裏是我的代碼:
int t = 0; //starting point of the window
int w = data.Length/25; //the end of the window so the size of the window is 40msec
int rmax = 0; //the maximum of the correlation function
int period = 0; //the period of the sinus
for (int tau = 0; tau < w; tau++)
{
int r = 0;
for (int j = t + 1; j < (t + w); j++)
{
r = r + (data[j] * data[j + tau]);
}
if (r > rmax)
{
rmax = r;
period = tau;
}
}
float time = (float)period/44100;
float freq = 1.0f/time;
System.Console.WriteLine(freq);
我應該得到250的頻率,但出了點問題。數組中的值是好的,我在excel中檢查過,並且期限是應該的。任何人都可以幫忙嗎?
我做到了,但它仍然是錯誤的。現在我計算了其他部分的時期,至少它們與第一時期相同。但結果取決於窗口的大小。這是正常的嗎? – user1707045
矩形窗口包含任何不嚴格定期在該窗口寬度週期的信號將產生「頻譜泄漏」僞像。那是你所看到的嗎? – hotpaw2