如何从麦克风输入读取实时频率?

How to read real-time frequencies from a microphone input?

我想实时获取从麦克风获取的语音输入的频率。我对此进行了搜索,了解了 FFT 和另外 2、3 种算法,但实现这些算法似乎非常复杂。

我正在寻找一个 C# 库,它使我能够简单地将频率放入数组中而无需实现它。

的确,正如您所猜测的那样,信号处理是您不想自己实现的那种算法,因为它们非常复杂。

显然,对于 C#,您可以在那里找到一些库,但这里有一个性能良好的库 DFT/FFT,目前处于活动状态:DSPLib

DSPLib has several main parts, but it's basic goal is to allow a real Fourier Transform to be preformed on a time series input array, resulting in a usable classic spectrum output without any further tweaking required by the user.

如果我理解正确的话,第二个例子就是你想要完成的任务(它缺少麦克风的录音)。

只有一条建议,小心窗口,因为它会影响信号的频谱。

简单说明一个可能让你疑惑的概念,零填充只是为了使用FFT算法而使样本数等于2的幂的一种技巧。因此,结果频谱以某种方式 'artificially' 以更好的分辨率生成。

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
}

绘图后,结果如下:

放大光谱的峰值: