我怎样才能利用PCM频率数据FFT [英] How can I get frequency data from PCM using FFT

查看:975
本文介绍了我怎样才能利用PCM频率数据FFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有音频数据的数组,我传递给读者:

I have an array of audio data I am passing to a reader:

 recorder.read(audioData,0,bufferSize); 

的实例如下:

The instantiation is as follows:

AudioRecord recorder;
short[] audioData;
int bufferSize;
int samplerate = 8000;

//get the buffer size to use with this audio record
bufferSize = AudioRecord.getMinBufferSize(samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)*3;

//instantiate the AudioRecorder
recorder = new AudioRecord(AudioSource.MIC,samplerate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,bufferSize); 

recording = true; //variable to use start or stop recording
audioData = new short [bufferSize]; //short array that pcm data is put into.

我有一个FFT级的我已经在网上发现一个复杂的类去用它。 我已经尝试了两天网上到处找,但不能工作如何遍历存储在 audioData 的值,并把它传递给FFT。

I have a FFT class I have found online and a complex class to go with it. I have tried for two days looking online everywhere but cant work out how to loop through the values stored in audioData and pass it to the FFT.

这是我使用的FFT类: HTTP://www.cs .princeton.edu / introcs / 97data / FFT.java 这是复杂的类去用它:的http:// introcs。 cs.princeton.edu/java/97data/Complex.java.html

This is the FFT class I am using: http://www.cs.princeton.edu/introcs/97data/FFT.java and this is the complex class to go with it: http://introcs.cs.princeton.edu/java/97data/Complex.java.html

推荐答案

假设 audioData 数组包含原始音频数据,您需要创建一个 audioData 数组这样复杂的[] 目标:

Assuming the audioData array contains the raw audio data, you need to create a Complex[] object from the audioData array as such:

Complex[] complexData = new Complex[audioData.length];
for (int i = 0; i < complexData.length; i++) {
    complextData[i] = new Complex(audioData[i], 0);
}

现在你可以把你的 complexData 对象作为参数传递给您的FFT功能:

Now you can pass your complexData object as a parameter to your FFT function:

Complex[] fftResult = FFT.fft(complexData);

这篇关于我怎样才能利用PCM频率数据FFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆