     }
 
     func buildSpectrum() -> [Double] {
-        var sample = buildSample()
-        var spectrum = [Double]() //fft(sample)
-
-        var powerSpectrum = [Double](count: spectrum.count, repeatedValue: 0)
-
-        var powerMax: Double = 1.0
-
-        var i = 0
-        for s in spectrum {
-            powerSpectrum[i] = abs(s) * abs(s)
-
-            if powerMax < powerSpectrum[i] {
-                powerMax = powerSpectrum[i]
-            }
-
-            i = i + 1
-        }
-
-        i = 0
-        for s in powerSpectrum {
-            powerSpectrum[i] = s / powerMax
-        }
+        var realPart = [Float](samples)
+        var imagPart = [Float](count: samples.count, repeatedValue: 0)
+
+        var signal = DSPSplitComplex(
+            realp: UnsafeMutablePointer<Float>(realPart),
+            imagp: UnsafeMutablePointer<Float>(imagPart))
+
+        fft_zrip(
+            samplesFftSetup,
+            signal,
+            vDSP_Stride(1),
+            samples.count,
+            FFTDirection(kFFTDirection_Forward))
+
+        var powerSpectrum = [Double](count: samples.count, repeatedValue: 0)
+
+        zaspec(
+            signal,
+            UnsafeMutablePointer(powerSpectrum),
+            samples.count
+        )
 
         return powerSpectrum
     }

    var samples: [Double] = [Double]()

    var doubleWave: [Double] = [Double]()
    
    var doubleWaveFftSetup: FFTSetup?

    init(){
        samples = [Double](count: Int(4 * discreteFrequency / minFrequency), repeatedValue: 0)

            var k1 = (Double(index1) * df - f) / df
            var s = s0 * sin(M_1_PI * k0) / k0 + s1 * sin(M_1_PI * k1) / k1

            return s / 5.0
        }

