0

我为 Android 编写了一个测试程序,我从麦克风录制音频并使用 JTransform lib 来计算 fft。我与 matlab 进行比较,但我没有得到相同的结果。例如 :

J变换:

real: 0.035003662109375 imag: 0.036529541015625
real: 0.036712646484375 imag: 0.0355224609375
real: 0.033966064453125 imag: 0.033111572265625
real: 0.034149169921875 imag: 0.035858154296875
real: 0.036712646484375 imag: 0.0360107421875

MATLAB:

4.1469          
1.6639 + 0.6458i
5.1224 +17.1221i
-4.3110 - 1.8984i
9.3352 + 4.8483i

录音机:

DoubleFFT_1D fft1d = new DoubleFFT_1D(bufferSize / 2);
short[] sourceBuffer = new short[bufferSize];
double[] fftBuffer = new double[bufferSize];
FFT fft = new FFT();
recorder.startRecording();
isRecording.set(true);
while(isRecording.get())
{
  int read = recorder.read(sourceBuffer, 0, bufferSize);
  //Log.e(LOG_TAG, "read: " + read + " bufferSize: " + bufferSize);
  if(read != AudioRecord.ERROR_INVALID_OPERATION)
  {
    for(int i = 0; i < bufferSize && i < read; ++i)
    {
      // signed int16 to double (2^15 = 32768)
      fftBuffer[i] = (double) (sourceBuffer[i] / 32768.0);
      try
      {
        // for matlab
        soundFile.write(fftBuffer[i] + "\n");
      }
      catch (IOException e)
      {
        Log.e(LOG_TAG, e.getMessage());
      }
    }
  }
}
fft1d.realForward(fftBuffer);

相关帖子

4

1 回答 1

0

我几乎可以肯定这是你的问题:

// signed int16 to double (2^15 = 32768)
fftBuffer[i] = (double) (sourceBuffer[i] / 32768.0);

JTransform 确实需要一个双缓冲区,但据我所知,它并不局限于 -1/1。我用它来识别音高,从来没有像那样划分它。只需将其转换为双倍就可以了。

不过,老实说,我最终还是使用了 libGdx 的 FFT 类,因为它对我的基准测试速度更快。

于 2012-06-26T20:04:30.573 回答