简体   繁体   English

使用vDSP实现FFT

[英]Implementing an FFT using vDSP

I have data regarding the redness of the user's finger that is currently quite noisy, so I'd like to run it through an FFT to reduce the noise. 我有关于当前非常嘈杂的用户手指发红的数据,所以我想通过FFT运行它以减少噪音。 The data on the left side of this image is similar to my data currently. 此图像左侧的数据与我目前的数据类似。 I've familiarized myself with the Apple documentation regarding vDSP, but there doesn't seem to be a clear or concise guide on how to implement a Fast Fourier Transform using Apple's vDSP and the Accelerate framework. 我已经熟悉了有关vDSP的Apple文档,但似乎没有关于如何使用Apple的vDSP和Accelerate框架实现快速傅立叶变换的明确或简明的指南。 How can I do this? 我怎样才能做到这一点?

I have already referred to this question , which is on a similar topic, but is significantly outdated and doesn't involve vDSP. 我已经提到了这个问题 ,这是一个类似的主题,但是已经过时了,并且不涉及vDSP。

Using vDSP for FFT calculations is pretty easy. 使用vDSP进行FFT计算非常简单。 I'm assuming you have real values on input. 我假设你有输入的真实价值。 The only thing you need to keep in mind you need to convert your real valued array to a packed complex array that FFT algo from vDSP uses internally. 您唯一需要记住的是,您需要将实值数组转换为vDSP内部使用FFT算法的压缩复数数组。

You can see a good overview in the documentation: 您可以在文档中看到一个很好的概述:

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

Here is the smallest example of calculating real valued FFT: 这是计算实值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];
}

One trick is that a.realp[0] is the DC offset and a.imagp[0] is the real valued magnitude at the Nyquist frequency. 一个技巧是a.realp[0]是DC偏移, a.imagp[0]是奈奎斯特频率的实值幅度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM