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

5
我正在使用Accelerate框架执行快速傅里叶变换(FFT),并尝试找到一种方法来创建一个长度为1024的缓冲区以供使用。我可以访问要进行FFT处理的信号的平均峰值和峰值。请问有人能帮助我或给我一些提示吗?

2
在WWDC2010的一个关于Accelerate.Framework的会议上,他们谈到了这个。我可能错了,但可能有一个关于这个的示例。无论如何,你应该查看Accelerate.Framework参考,那里有非常有用的函数来完成你想要的操作;) - nacho4d
你可能想要查看这个StackOverflow问题的答案。提供了许多使用苹果的Accelerate框架生成音频FFT的好例子。 - rcw3
1个回答

11

苹果公司在其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);
}

正如您所看到的,在这个FFT中,我仅使用了实际值来设置输入缓冲区,执行FFT,然后读取幅度。


1
谢谢 - 这个例子比我看到的其他例子要简单得多(它们大多数在执行反FFT之后)。非常有帮助,因为我可以看到我需要的最小位数是多少! - Oliver Mason
1
你只将波幅索引放到实际值中了。imagp应该为零吗?我不太清楚。为什么不使用CTOZ函数呢?谢谢。 - Sergey Kopanev
@SergeyKopanev 使用复数FFT(而不是实数FFT)。在这种情况下,您无需排列实际数据,因为所有实际数据都将存储在“DSPDoubleSplitComplex”的realp数组中。虚数数组将为空,因为没有虚数值。 - DEADBEEF

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接