【发布时间】:2015-06-04 15:06:57
【问题描述】:
我正在使用http://www.lomont.org/Software/Misc/FFT/LomontFFT.html 的 LomontFFT 从信号的采样值中获取基频。为了测试是否正确确定了基频,我使用了一些过去的样本(具有已知的基频)。
下面是我编写的调用 LomontFFT 算法并确定 FFT 的代码:
private void buttonFFT_Click(object sender, EventArgs e)
{
//double fftavg = 0;
double fftmax = 0;
var fftData = new byte[512];
double[] fftValues = Enumerable.Repeat(0.0, 512).ToArray();
Array.Copy(sapmledDoubleValuesADC1, fftValues, sapmledDoubleValuesADC1.Length);
var fftMethod = new Lomont.LomontFFT();
fftMethod.RealFFT(fftValues, true);
for (int i = 0; i < 512; i += 2)
{
double fftmag = Math.Sqrt((fftValues[i] * fftValues[i]) + (fftValues[i + 1] * fftValues[i + 1]));
if (fftmag > fftmax)
fftmax = fftmag;
//fftavg += fftmag;
//fftData[i] = (byte)fftmag;
//fftData[i + 1] = fftData[i];
}
textBoxFundaFreq.Text = "Frey = " + fftmax.ToString();
for (int x = 1; x < 512; x++)
{
this.chart2.Series[0].Points.AddXY(x, fftValues[x]);
}
}
但问题是频率的大小是错误的。 FFT 也不匹配,但这是可能的,因为有多种解决方案,但频率应该相同。该算法已被证明多年,所以它绝对没有错。我在调用代码时做错了吗?
(我在采样数据中只有实数值)
【问题讨论】:
-
请重新格式化代码
-
抱歉,我的手机中的空格和未格式化的代码出错了。但它现在固定了。
标签: c# algorithm signal-processing fft