如何从麦克风输入读取实时频率?
问题描述:
我想实时获取从麦克风获取的语音输入的频率。我搜索了这个,并了解了FFT和另外的2,3种算法,但是实现这些算法似乎非常复杂。如何从麦克风输入读取实时频率?
我正在寻找一个C#库,使我能够将频率简单地插入到数组中而无需实现它。
答
事实上,正如你猜测的那样,信号处理是你不想实现的算法,因为它有相当复杂的。
显然,对于C#中,你可以找到一些图书馆在那里,但这里是一个很好的图书馆执行DFT/FFT和当前的活跃:DSPLib
DSPLIB有几个主要部分,但它的基本目标是:允许在时间序列输入阵列 上执行真实的 傅立叶变换,产生可用的经典谱输出,而不需要用户进一步调整 。
如果我正确理解你想要的,第二个例子是你想要达到的任务(它缺少麦克风的录音)。
只是一个建议,小心窗口,因为它可以影响你的信号的频谱。
只有一个关于概念的注释可能会让你困惑,为了使用FFT算法,零填充仅仅是一个诀窍,让一些采样等于2的幂。因此,所产生的频谱在某种程度上是以更好的分辨率“人为”制作的。
void example2()
{
// Same Input Signal as Example 1 - Except a fractional cycle for frequency.
double amplitude = 1.0; double frequency = 20000.5;
UInt32 length = 1000; UInt32 zeroPadding = 9000; // NOTE: Zero Padding
double samplingRate = 100000;
double[] inputSignal = DSPLib.DSP.Generate.ToneSampling(amplitude, frequency, samplingRate, length);
// Apply window to the Input Data & calculate Scale Factor
double[] wCoefs = DSP.Window.Coefficients(DSP.Window.Type.Hamming, length);
double[] wInputData = DSP.Math.Multiply(inputSignal, wCoefs);
double wScaleFactor = DSP.Window.ScaleFactor.Signal(wCoefs);
// Instantiate & Initialize a new DFT
DSPLib.DFT dft = new DSPLib.DFT();
dft.Initialize(length, zeroPadding); // NOTE: Zero Padding
// Call the DFT and get the scaled spectrum back
Complex[] cSpectrum = dft.Execute(wInputData);
// Convert the complex spectrum to note: Magnitude Format
double[] lmSpectrum = DSPLib.DSP.ConvertComplex.ToMagnitude(cSpectrum);
// Properly scale the spectrum for the added window
lmSpectrum = DSP.Math.Multiply(lmSpectrum, wScaleFactor);
// For plotting on an XY Scatter plot generate the X Axis frequency Span
double[] freqSpan = dft.FrequencySpan(samplingRate);
// At this point a XY Scatter plot can be generated from,
// X axis => freqSpan
// Y axis => lmSpectrum
}
密谋后,这里是结果:
有了放大的光谱峰:
除了FFT什么算法你认为你需要使用? – Paradox