Math.Net、特にFFT部分を試してみようとしています。私は純粋な正弦波から周波数領域の情報を抽出しようとしています。あなたが見ることができるように、私は20kHzの時にサンプリングし、10Kのサンプルを生成し、500Hzでの周波数の正弦波を生成しています純粋な正弦波のウィンドウデータセットに対してFFTを正しく実行する方法
private void Form1_Load(object sender, EventArgs e)
{
//Set up the wave and derive some useful info
Double WaveFreq = 500;
Double WavePeriod = 1/WaveFreq;
Double SampleFreq = 20000;
Double SampleTime = (1/SampleFreq);
//Generate the wave using the above parameters
var points = Generate.Sinusoidal(100000, SampleFreq, WaveFreq, 1);
//Array to hold our complex numbers
var data = new Complex[points.Length];
//Set up the series to display our raw wave
Series WaveSeries = new Series("Waveform");
WaveSeries.ChartType = SeriesChartType.Line;
//Creat the series for displaying the FFT
Series FFTSeries = new Series("FFT Test");
FFTSeries.ChartType = SeriesChartType.Column;
//Populate both the wave series and the data array
for (int i = 0; i < points.Length; i++)
{
Double x = SampleTime * i;
WaveSeries.Points.AddXY(x, points[i]);
data[i] = new Complex(x, points[i]);
}
//Create the window to evaluate (using a window 5 times wider than the wavelength of the lowest ferequency being measured)
int WindowWidth = (int)Math.Round((1/WaveFreq)/(1/SampleFreq) * 5 + 0.5f);
var HannWindow = Window.HannPeriodic(WindowWidth);
var window = new Complex[WindowWidth];
for(int i = 0; i < WindowWidth; i++)
{
var y = data[i].Imaginary * HannWindow[i];
window[i] = new Complex(data[i].Real, y);
}
//Perform the FFT
Fourier.Forward(window);
//Add the calculated FFT to our FFTSeries
foreach(Complex sample in window)
{
FFTSeries.Points.AddXY(sample.Phase, sample.Magnitude);
}
chart2.Series.Add(WaveSeries);
chart2.ChartAreas[0].AxisX.Minimum = 0;
chart2.ChartAreas[0].AxisX.Maximum = .01;
chart2.ChartAreas[0].AxisY.Minimum = -2;
chart2.ChartAreas[0].AxisY.Maximum = 2;
chart1.Series.Add(FFTSeries);
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 1000;
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 5;
}
:ここではコードです。
FFTは(0Hzから1.8程度のピークからasides)絶対に何も表示しません!私はそれがおそらくウィンドウ処理のエラーだと思うが、私の人生にとっては、それが何かを見ることができない。
ご協力いただきありがとうございます。
これを複製しようとすると、私はWindow.HannPeriodic関数を見つけることができません。これはMathNetのドキュメントにありますが、Window.Hannだけに切り替えるとコンパイルできます。何か不足していますか? –
@KelsonBall 3.14.0-beta3バージョンです。 –