FFT的音频文件读取



第一次问我是否已经访问了一段时间。

问题是:

我目前正试图用以下属性隔离WAVE数据文件中包含的信号的基频:

  • PCM音频格式,即线性量化
  • 8000 Hz采样率
  • 每个样本16位
  • 16000字节速率

只有一个通道,没有交错。

获取字节值:

System.IO.FileStream WaveFile = System.IO.File.OpenRead(@"c:tetfft.wav");
byte[] data = new byte[WaveFile.Length];
WaveFile.Read(data,0,Convert.ToInt32(WaveFile.Length));

将其转换为双打数组:

for (int i = 0; i < 32768; i++)//this is only for a relatively small chunk of the file 
{
InReal[i] =BitConverter.ToDouble(data, (i + 1) * 8 + 44);
}

并最终将其传递给变换函数。

FFT FftObject = new FFT();
FftObject.Transform(InReal, InImg, 0, 32768, out outReal, out outImg, false);

现在第一个问题,正如我所理解的,wav文件的PCM值应该在-1和1,但当转换为Double时,我会得到以下值:

2.65855908666825E-235
2.84104982662944E-285
-1.58613492930337E+235
-1.25617351166869E+264
1.58370933499389E-242
6.19284549187335E-245
-2.92969500042228E+254
-5.90042665390976E+226
3.11954507295188E-273
3.06831908609091E-217
NaN
2.77113146323761E-302
6.76597919848376E-306
-1.55843653898344E+291

这些是数组中在这些极限中的最初几个,也是数组的其余部分。

我的结论是,我有某种代码故障,但我似乎能够找到它。如有任何帮助,我们将不胜感激。

第二个问题,因为我只在响应向量中向FFT算法提供真实数据,我应该也只期望真实部分的数据吗??

非常感谢。

我终于找到了问题所在,似乎我没有考虑到数据表示中信号的脉冲编码调制,因为我在准备傅立叶变换的波形文件中发现了许多未回答的问题,这是准备波形文件的函数中的代码。

public static Double[] prepare(String wavePath, out int SampleRate)
{
Double[] data;
byte[] wave;
byte[] sR= new byte[4];
System.IO.FileStream WaveFile = System.IO.File.OpenRead(wavePath);
wave = new byte[WaveFile.Length];
data = new Double[(wave.Length - 44) / 4];//shifting the headers out of the PCM data;
WaveFile.Read(wave,0,Convert.ToInt32(WaveFile.Length));//read the wave file into the wave variable
/***********Converting and PCM accounting***************/
for (int i = 0; i < data.Length - i * 4; i++)
{
data[i] = (BitConverter.ToInt32(wave, (1 + i) * 4)) / 65536.0;
//65536.0.0=2^n,       n=bits per sample;
}
/**************assigning sample rate**********************/
for (int i = 24; i < 28; i++)
{
sR[i-24]= wave[i];
}
SampleRate = BitConverter.ToInt32(sR,0);
return data;
}

您现在所需要做的就是将采样率和返回的结果发送到FFT算法。代码没有被处理,所以根据需要进行自己的处理。我已经接受了电话录音、忙碌、铃声和语音的测试,它功能正常。

最新更新