0

44100のサンプリングレートでマイクから直接送られるオーディオサンプルを含むdoubleの配列があります。基本周波数を取得したい(サンプルには振幅が含まれています)。自己相関ページのウィキペディアで、ウィーナー・ヒンチンの定理に基づいたソリューションの説明を見つけました。インターネットでさらに調査してアルゴリズムを完成させ、最終的に次のコードを記述しましたが、それが正しいかどうかはわかりません。

private double determineFrequency(double[] signal) {
 //Get a FastFourierTransformer instance (Apache library)
 FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);

 //The size of the array used by the fft must be a power of two, wrapping 
 //the original array in a bigger one padded to zero
 //NOTE: Here I assume that the input array is smaller than 8192
 double[] paddedSignal = new double[8192];
 System.arraycopy(signal, 0, paddedSignal, 0, signal.length);

 //First fft (forward) to switch from amplitude domain to the frequency domain
 Complex[] transformed = fft.transform(paddedSignal, TransformType.FORWARD);

 // Calculate the conjugate of the complex array
 for (int i=0; i<transformed.length; i++)
  transformed[i] = transformed[i].conjugate();

 //Second fft (inverse) to complete the autocorrelation
 transformed = fft.transform(transformed, TransformType.INVERSE);

 //Calculate the array of corresponding real values to switch 
 // from the frequency domain to the amplitude domain
 double[] autocorrelationMatrix = new double[transformed.length];
 for (int i=0; i<transformed.length; i++) {
  if (Double.isNaN(transformed[i].abs()) || Double.isInfinite(transformed[i].abs()))
   autocorrelationMatrix[i] = 0;
  else
   autocorrelationMatrix[i] = transformed[i].abs();
 }

 //Get the index of the max amplitude
 Integer indexOfMax = Utils.indexOfMax(autocorrelationMatrix);

 return transformed[indexOfMax].getReal()*audioFormat.getSampleRate()/transformed.length; 
}
4

1 に答える 1

0

自己相関ドメインで最大値を見つけ、それを使用して周波数ドメインを読み取りました。時間領域のインデックスを使用して周波数領域について何かを学ぶことができる以上に、それは機能しません。

その代わり、

return autocorrelationMatrix[indexOfMax].getReal()*audioFormat.getSampleRate()/autocorrelationMatrix.length;

そうは言っても、余分なIFFTを回避する方が簡単な場合があります。代わりに、周波数領域から最大絶対値を抽出するだけです。これは、サンプルレート/変換長の解像度で機能し、最大FFTビンのフェーズから少し助けを借りて調整できます。

于 2012-06-25T20:50:13.763 に答える