C# 自然频率长度
据 我能够在声音文件中捕获波形的FFT结果。 我的取样器是由C# 自然频率长度,c#,signal-processing,fft,naudio,C#,Signal Processing,Fft,Naudio,据 我能够在声音文件中捕获波形的FFT结果。 我的取样器是由 using (var reader = new WaveFileReader(soundFile)) using (wc = new WaveChannel32(reader) { PadWithZeroes = false }) using (audioOutput = new DirectSoundOut()) { wc.Volume = 100; sampleRate = reader.WaveFormat.Sa
using (var reader = new WaveFileReader(soundFile))
using (wc = new WaveChannel32(reader) { PadWithZeroes = false })
using (audioOutput = new DirectSoundOut())
{
wc.Volume = 100;
sampleRate = reader.WaveFormat.SampleRate; //<== sampleRate
averageBytePerSecond = waveIn.WaveFormat.AverageBytesPerSecond;
audioOutput.Init(wc);
try
{
audioOutput.Play();
while (audioOutput.PlaybackState != PlaybackState.Stopped)
{
Thread.Sleep(20);
}
audioOutput.Stop();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
使用(变量读取器=新的波形读取器(声音文件))
使用(wc=newwavechannel32(读卡器){PadWithZeroes=false})
使用(audioOutput=new DirectSoundOut())
{
wc.体积=100;
sampleRate=reader.WaveFormat.sampleRate;//maxVal)
{
maxVal=v;
maxIndex=i;
}
}
var频率=最大指数*(采样器/FftLenth);
}
现在我有了我的频率,但是我怎样才能找到这个频率的持续时间呢?(播放频率的时间。)如果您知道主信号的频率和带宽,可以使用带通滤波器和包络跟踪器。您还需要估计包络线开始和衰减的某种振幅阈值
Goertzel滤波器是一种常见的具有振幅输出的组合带通滤波器。滑动Goertzel过滤器可用于定位时域事件。如果要测量持续时间,则需要计算重叠FFT,例如,在每次迭代时将窗口提前10毫秒,以确定开始和偏移时间,然后获得差值。这是一种非常低效的方法来测量音调的持续时间。嗨,谢谢你的想法,问题是音频样本是实时捕获的,那么我如何“将窗口提前10毫秒”呢?你所说的“确定起始和偏移时间,然后得到差异”是什么意思?再次感谢您的帮助:)您需要缓冲音频,以便能够重叠连续的窗口。我不知道这是否是容易做到与NAudio然而。正如我上面所说的,这是一种非常低效的方法来尝试和确定音调或音符的持续时间-你可能应该做一些更合适的算法研究,以解决你试图解决的任何问题。嗨,我开始研究Goertzel过滤器。你认为滤波器必须应用于输入信号还是FFT变换信号?@SimonMardiné:Goertzel滤波器在时域工作-你不需要FFT。(考虑Goertzel滤波器的一个有用方法是,它实际上与仅在一个输出单元上计算的DFT相同。)
void FftCalculated(object sender, FftEventArgs e)
{
float maxVal = 0;
int maxIndex = -1;
for (int i = 0; i < FftLenth / 2; i++)
{
float v = e.Result[i].X * e.Result[i].X + e.Result[i].Y * e.Result[i].Y;
if (v > maxVal)
{
maxVal = v;
maxIndex = i;
}
}
var frequency = maxIndex * (sampleRate / FftLenth);
}