1

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

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

回答

3

使用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]是DC偏移而a.imagp[0]是奈奎斯特频率处的实际值。