Swift 包,提供带有包装器的 PFFFT(非常快速的快速傅里叶变换)库。
此代码基于 marton78 的 PFFFT 分支,该分支是从 Julien Pommier 最初的 PFFFT 实现派生而来。此分支除了浮点数之外还提供对双精度数的支持,并提供额外的 SIMD 实现。
此包中 C 实现的来源是 https://github.com/marton78/pffft。
PFFFT 相比 KissFFT 提供了显著的性能提升。 与 FFTW 相比,PFFFT 在拥有合理性能的同时,使用起来更加简单,并且采用宽松的 3 条款 BSD 许可证。
// construct an interface for FFT, IFFT and convolutions. The interface is parameterized on the
// type of element in the signal (time) domain. The spectrum (frequency) domain type will always be
// complex. For a real valued signal the spectrum size will be `n / 2`, with the packing convention
//
let fft = try FFT<Complex<Float>>(n: 16)
let signal = fft.makeSignalBuffer()
signal.enumerateInPlace { (i, v) in
v = Complex(Float(i) + 1.0, Float(i) - 2.0)
}
let spectrum = fft.makeSpectrumBuffer()
fft.forward(signal: signal, spectrum: spectrum)
fft.inverse(spectrum: spectrum, signal: signal)