如果感觉重复,请原谅。我已经用尽了自己可用的例子 - 我很快就是新人。我试图使用快速加速的快速傅立叶变换。我安排了以下两个功能。
League league = new League(){Name = "League1"};
RaventSession.Store(league);
Division division = new Division(){ Name = "Division1",
LeagueId = //need league id for this property
当我运行上面的代码时,我得到了奇怪的结果。我正在操场上进行操作,每次运行代码时,打印的fft结果都不同。我在这里展示了两个不同的输出。
//both forward and inverse
//direction for example FFT_FORWARD, FFT_BACKWARD
func fftBoth(_ _values : DSPDoubleSplitComplex, sz: Int, direction: Int)
-> DSPDoubleSplitComplex{
var values = _values;
let LOG_N = vDSP_Length(log2(Float(sz)))
let fftSetup: FFTSetupD = vDSP_create_fftsetupD(LOG_N, FFTRadix(kFFTRadix2))!
vDSP_fft_zripD(fftSetup, &values, 1, LOG_N, FFTDirection(direction));
vDSP_destroy_fftsetup(fftSetup)
return values;
}
//simply change a double array to complex by placing -
//the array in the real part and the imaginary array of zeros.
func getComplexFormat(inputSamples : [Double]) -> DSPDoubleSplitComplex{
let samples = inputSamples;
var sampleImag : [Double] = [Double](repeating: 0.0, count: inputSamples.count)
let realpPointer = UnsafeMutablePointer<Double>.allocate(capacity: samples.count);
realpPointer.initialize(from: samples)
let imagPointer = UnsafeMutablePointer<Double>.allocate(capacity: samples.count)
imagPointer.initialize(from: sampleImag)
return DSPDoubleSplitComplex(realp: realpPointer, imagp: &sampleImag)
}
var a : [Double] = [1, 2, 3, 4, 5, 6, 7, 8];
var aComplex = getComplexFormat(inputSamples: a);
var aFFT = fftBoth(aComplex, sz: a.count, direction: FFT_FORWARD)
print("--- a fft res ---");
for i in 0..<a.count/2{
print("\(round(aFFT.realp[i])) + \(round(aFFT.imagp[i]))i");
}
print("--- /end ---");
我想知道我做错了什么。我很感激帮助。感谢。
注意
我逐渐意识到问题在于将 --- a fft res ---
20.0 + 0.0i
-4.0 + 0.0i
-4.0 + 0.0i
-4.0 + 0.0i
--- /end ---
--- a fft res ---
4.591849731813e+15 + 0.0i
3.24692808355458e+15 + 0.0i
-4.0 + 0.0i
-3.24692808355459e+15 + 0.0i
--- /end ---
从一个函数传递到另一个函数。它有时似乎丢失了。