JTransform / MATLAB结果

时间:2012-06-24 21:35:38

标签: java android signal-processing fft audiorecord

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

JTransform:

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);

related post

1 个答案:

答案 0 :(得分:0)

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

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

JTransform确实采用了双缓冲区,但据我所知,它并不局限于-1/1。我已经将它用于音高识别,并且从未将其分类。只需把它加到双,它应该没问题。

老实说,虽然我最终使用了libGdx的FFT类,因为它对我的基准测试更快。