我正在为孩子们建立一个小的安卓应用程序,它只是简单地播放旋律,然后孩子试图唱回。我录下来,并与歌曲比较,因为我说你唱得正确等等。
到目前为止,我用TarsosDSP.I从麦克风上成功地记录和计算了实时数据。我还将其投影到图表中。但是我不能得到旋律的FFT值。我真的是音频处理领域的新手。
谁能给我一个例子,如何计算简单的mp3文件的快速傅立叶变换?谢谢。
发布于 2016-08-05 20:04:54
基于Java的频谱分析、采样频率、折叠频率和快速傅立叶变换算法http://www.developer.com/java/other/article.php/3380031
发布于 2019-11-21 12:42:29
将歌曲转换成字节后,就可以使用下面的代码了。
我使用了JTranforms库,它工作得很好,你可以将它与Matlab使用的函数进行比较。
这是我的代码,带有注释,引用matlab如何转换任何信号并获得频率振幅(https://la.mathworks.com/help/matlab/ref/fft.html)
首先,在build.gradle (应用程序)中添加以下内容
implementation 'com.github.wendykierp:JTransforms:3.1'这是转换一个简单的正弦波的代码,效果很好。
double Fs = 8000;
double T = 1/Fs;
int L = 1600;
double freq = 338;
double sinValue_re_im[] = new double[L*2]; // because FFT takes an array where its positions alternate between real and imaginary
for( int i = 0; i < L; i++)
{
sinValue_re_im[2*i] = Math.sin( 2*Math.PI*freq*(i * T) ); // real part
sinValue_re_im[2*i+1] = 0; //imaginary part
}
// matlab
// tf = fft(y1);
DoubleFFT_1D fft = new DoubleFFT_1D(L);
fft.complexForward(sinValue_re_im);
double[] tf = sinValue_re_im.clone();
// matlab
// P2 = abs(tf/L);
double[] P2 = new double[L];
for(int i=0; i<L; i++){
double re = tf[2*i]/L;
double im = tf[2*i+1]/L;
P2[i] = sqrt(re*re+im*im);
}
// P1 = P2(1:L/2+1);
double[] P1 = new double[L/2]; // single-sided: the second half of P2 has the same values as the first half
System.arraycopy(P2, 0, P1, 0, L/2);
// P1(2:end-1) = 2*P1(2:end-1);
System.arraycopy(P1, 1, P1, 1, L/2-2);
for(int i=1; i<P1.length-1; i++){
P1[i] = 2*P1[i];
}
// f = Fs*(0:(L/2))/L;
double[] f = new double[L/2 + 1];
for(int i=0; i<L/2+1;i++){
f[i] = Fs*((double) i)/L;
}https://stackoverflow.com/questions/38788745
复制相似问题