使用Accelerate框架进行FFT时如何设置缓冲区?

5 iphone cocoa fft accelerate-framework

我正在使用Accelerate框架来执行快速傅立叶变换(FFT),并且我正在尝试找到一种方法来创建一个缓冲区,以便使用长度为1024的缓冲区.我可以访问平均峰值和峰值.我想做FFT的信号.

有人可以帮我或给我一些提示吗?

Bra*_*son 11

Apple提供了一些如何在vDSP编程指南中设置FFT的示例.您还应该查看vDSP示例示例应用程序.对于Mac,此代码也应直接转换为iOS.

我最近需要对64整数输入波形进行简单的FFT,为此我使用了以下代码:

static FFTSetupD fft_weights;
static DSPDoubleSplitComplex input;
static double *magnitudes;

+ (void)initialize
{
    /* Setup weights (twiddle factors) */
    fft_weights = vDSP_create_fftsetupD(6, kFFTRadix2);

    /* Allocate memory to store split-complex input and output data */
    input.realp = (double *)malloc(64 * sizeof(double));
    input.imagp = (double *)malloc(64 * sizeof(double));
    magnitudes = (double *)malloc(64 * sizeof(double));
}

- (CGFloat)performAcceleratedFastFourierTransformAndReturnMaximumAmplitudeForArray:(NSUInteger *)waveformArray;
{   
    for (NSUInteger currentInputSampleIndex = 0; currentInputSampleIndex < 64; currentInputSampleIndex++)
    {
        input.realp[currentInputSampleIndex] = (double)waveformArray[currentInputSampleIndex];
        input.imagp[currentInputSampleIndex] = 0.0f;
    }

    /* 1D in-place complex FFT */
    vDSP_fft_zipD(fft_weights, &input, 1, 6, FFT_FORWARD);  

    input.realp[0] = 0.0;
    input.imagp[0] = 0.0;

    // Get magnitudes
    vDSP_zvmagsD(&input, 1, magnitudes, 1, 64);

    // Extract the maximum value and its index
    double fftMax = 0.0;
    vDSP_maxmgvD(magnitudes, 1, &fftMax, 64);

    return sqrt(fftMax);
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我只使用此FFT中的实数值来设置输入缓冲区,执行FFT,然后读出幅度.