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]是奈奎斯特頻率處的實際值。