【问题标题】:Implementing an FFT using vDSP使用 vDSP 实现 FFT
【发布时间】:2017-09-03 11:54:19
【问题描述】:

我有关于当前非常嘈杂的用户手指发红的数据,所以我想通过 FFT 运行它以减少噪音。 this image左边的数据和我目前的数据差不多。我已经熟悉了有关 vDSP 的 Apple 文档,但似乎没有关于如何使用 Apple 的 vDSP 和 Accelerate 框架实现快速傅里叶变换的清晰或简明指南。我怎样才能做到这一点?

我已经提到了this question,它是一个类似的主题,但已经过时并且不涉及 vDSP。

【问题讨论】:

    标签: objective-c signal-processing fft accelerate-framework vdsp


    【解决方案1】:

    使用 vDSP 进行 FFT 计算非常简单。我假设您对输入有真正的价值。唯一需要记住的是,您需要将实值数组转换为 vDSP 的 FFT 算法在内部使用的压缩复数数组。

    您可以在文档中看到很好的概述:

    https://developer.apple.com/library/content/documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html

    这是计算实值 FFT 的最小示例:

    const int n = 1024;
    const int log2n = 10; // 2^10 = 1024
    
    DSPSplitComplex a;
    a.realp = new float[n/2];
    a.imagp = new float[n/2];
    
    // prepare the fft algo (you want to reuse the setup across fft calculations)
    FFTSetup setup = vDSP_create_fftsetup(log2n, kFFTRadix2);
    
    // copy the input to the packed complex array that the fft algo uses
    vDSP_ctoz((DSPComplex *) input, 2, &a, 1, n/2);
    
    // calculate the fft
    vDSP_fft_zrip(setup, &a, 1, log2n, FFT_FORWARD);
    
    // do something with the complex spectrum
    for (size_t i = 0; i < n/2; ++i) {
        a.realp[i];
        a.imagp[i];
    }
    

    一个技巧是a.realp[0] 是直流偏移,a.imagp[0] 是奈奎斯特频率下的实数值幅度。

    【讨论】:

    • 快速提问——这个例子假设input是n/2长度还是n长度?我对 vDSP_ctoz 步骤中数组的大小感到困惑?如果是 n/2 元素,为什么它是 1024 大小的 FFT?
    • @joerick 代码正在计算真正的 FFT 分析,所以input 是一个包含n 实数的数组。 vDSP 要求您取n 实数并假装它们是n/2 复数。
    • 所以这是一个数据打包技巧!谢谢。 (那些 vDSP 文档真的可以引起注意!)
    猜你喜欢
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    • 2019-10-17
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    相关资源
    最近更新 更多