音频,FFT 不起作用
本文关键字:不起作用 FFT 音频 | 更新日期: 2023-09-27 18:26:01
class Main
{
WaveFileReader reader;
short[] sample;
Complex[] tmpComplexArray;
public Main()
{
//read in wav, to raw data in byte array then to short array.
reader = new WaveFileReader("C:''Users''minford''Downloads''English_Subtitles_.wav");
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0 , buffer.Length);
sample = new short[reader.Length];
for (int n = 0; n < buffer.Length; n += 2)
{
sample[n] = BitConverter.ToInt16(buffer, n);
}
// short array to complex
Complex[] complexData = new Complex[sample.Length];
for (int i = 0; i < complexData.Length; i++)
{
Complex tmp = new Complex(sample[i],0);
complexData[i] = tmp;
}
//to get first 500 for testing.
tmpComplexArray = new Complex[500];
for (int i = 0; i < 500; i++)
{
Complex a = new Complex(complexData[i]);
tmpComplexArray[i] = a;
}
//run FFT
FourierTransform.DFT(tmpComplexArray ,FourierTransform.Direction.Forward);
//print result
for (int i = 0; i < complexData.Length; i++)
{
Console.Write(complexData[i]);
}
}
}
}
我在使用 AForge 的 FFT 时遇到了这个问题。这是正确的使用方式吗?返回的复数(目前仅返回前 500 个(每次将第二个数字定为 0。
您打印了错误的数据:
//print result vvvvvvvvvvvvvvv
for (int i = 0; i < tmpComplexArray.Length; i++)
{
Console.Write(tmpComplexArray[i]);
}