FDS計算にvDSPを使用するのはかなり簡単です。私はあなたが入力に本当の価値を持っていると仮定しています。あなたが心に留めておく必要があるのは、実数値アレイを、vDSPからの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];
}
1つのトリックはa.realp[0]
は、DCオフセットであるということである。
ここhttps://developer.apple.com/library/content/documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html
は実数値FFTを計算する最小の一例ですa.imagp[0]
は、ナイキスト周波数での実数値の振幅です。