我有关于当前非常嘈杂的用户手指发红的数据,所以我想通过 FFT 运行它以减少噪音。此图左侧的数据与我目前的数据相似。我已经熟悉了有关 vDSP 的 Apple 文档,但似乎没有关于如何使用 Apple 的 vDSP 和 Accelerate 框架实现快速傅里叶变换的清晰或简明指南。我怎样才能做到这一点?
我已经提到过这个问题,这是一个类似的主题,但已经过时并且不涉及 vDSP。
使用 vDSP 进行 FFT 计算非常简单。我假设您对输入有真正的价值。您唯一需要记住的是,您需要将实值数组转换为 vDSP 的 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];
}
一个技巧是a.realp[0]
直流偏移,a.imagp[0]
它是奈奎斯特频率下的实数值幅度。