【问题标题】:How do I set up a buffer when doing an FFT using the Accelerate framework?使用 Accelerate 框架进行 FFT 时如何设置缓冲区?
【发布时间】:2011-06-15 19:16:55
【问题描述】:

我正在使用 Accelerate 框架来执行快速傅立叶变换 (FFT),并试图找到一种方法来创建一个长度为 1024 的缓冲区供它使用。我可以访问平均峰值和我要对其进行 FFT 的信号的峰值。

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

【问题讨论】:

  • 在一次关于 Accelerate.Framework 的 WWDC2010 会议中,他们谈到了这一点。我可能错了,但可能有一个关于此的示例。无论哪种方式,您都应该查看 Accelerate.Framework 参考,有非常有用的功能可以做您想做的事;)
  • 您可能想查看this StackOverflow question 的答案。提供了许多使用 Apple 的 Accelerate 框架生成音频 FFT 的好示例。

标签: iphone cocoa fft accelerate-framework


【解决方案1】:

Apple 在其vDSP Programming Guide 中有一些如何设置 FFT 的示例。您还应该查看vDSP Examples 示例应用程序。而对于 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,然后读出幅度。

【讨论】:

  • 谢谢 - 这是一个比我见过的其他例子简单得多的例子(他们大多在之后立即执行逆 FFT)。非常有帮助,因为我可以看到解决我的问题所需的最少位!
  • 您只需将波幅指数设为实际值。 imagp 应该为零吗?我不清楚。为什么不使用 CTOZ 功能?谢谢
  • @SergeyKopanev 他使用复数到复数 fft(而不是实数到复数 fft)。在这种情况下,您不需要排列真实数据,因为它们都将存储在DSPDoubleSplitComplex 的 realp 数组中。虚数数组将为空,因为没有虚数。
猜你喜欢
  • 2011-03-24
  • 2011-09-15
  • 2011-05-29
  • 2013-09-26
  • 1970-01-01
  • 2016-02-08
  • 1970-01-01
  • 1970-01-01
  • 2011-07-24
相关资源
最近更新 更多