我对信号处理很新,所以请耐心等待。我正在尝试将带通滤波器应用于从iPad获得的录音。使用ExtFile函数和AudioBufferList将记录转换为Float32指针。采样率为44100Hz。录制时间约为9秒(约为396900个样本),包含2-6kHz的啁啾声和一些环境噪声。我需要在2-6kHz的频率范围内对录音进行带通滤波,以便找到啁啾发生的时间点。我已经参考了以下资源来创建带通滤波器:
https://github.com/bartolsthoorn/NVDSP/blob/master/NVDSP.mm
https://github.com/bartolsthoorn/NVDSP/blob/master/Filters/NVBandpassFilter.m
我的问题是,我可以简单地将录音的浮点值数组传递给上面的带通滤波器吗?我试过这个,但我不确定它是否有效,因为它似乎只是减少了数组中每个值的值。通过录音后我应该看到什么
但是,我看到一些资源说我首先需要使用FFT将值从时域转换为频域。我已尝试使用以下代码使用某些vDSP函数执行此操作:
- (Float32 *)calculateFFT
{
// Acquired from http://batmobile.blogs.ilrt.org/fourier-transforms-on-an-iphone/
int numSamples = _recordingLength; //~9 seconds * 44100Hz ~= 396900 samples
// Setup the length
vDSP_Length log2n = log2f(numSamples);
// Calculate the weights array. This is a one-off operation.
FFTSetup fftSetup = vDSP_create_fftsetup(log2n, FFT_RADIX2);
// For an FFT, numSamples must be a power of 2, i.e. is always even
int nOver2 = numSamples/2;
// Populate *window with the values for a hamming window function
float *window = (float *)malloc(sizeof(float) * numSamples);
vDSP_hamm_window(window, numSamples, 0);
// Window the samples
vDSP_vmul(_recordingSamples, 1, window, 1, _recordingSamples, 1, numSamples);
// Define complex buffer
COMPLEX_SPLIT A;
A.realp = (float *) malloc(nOver2*sizeof(float));
A.imagp = (float *) malloc(nOver2*sizeof(float));
// Pack samples:
// C(re) -> A[n], C(im) -> A[n+1]
vDSP_ctoz((COMPLEX*)_recordingSamples, 2, &A, 1, numSamples/2);
//Perform a forward FFT using fftSetup and A
//Results are returned in A
vDSP_fft_zrip(fftSetup, &A, 1, log2n, FFT_FORWARD);
//Convert COMPLEX_SPLIT A result to magnitudes
Float32 *amp = new Float32[numSamples];
amp[0] = A.realp[0]/(numSamples*2);
for(int i=1; i<numSamples; i++) {
amp[i]=A.realp[i]*A.realp[i]+A.imagp[i]*A.imagp[i];
//printf("%f ",amp[i]);
}
return amp;
}
但是我不明白这个函数返回了什么。如果我确实需要在将记录传递给过滤器之前应用FFT,需要从calculateFFT函数返回什么然后传递给过滤器?
提前致谢。