     }
 
     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
     }

    }

    func getValueAtFrequency(f: Double, spectrum: [Double]) -> Double {
        var df: Double = Double(1.0) / (Double(spectrum.count) * discreteTime)
        var position: Double = f / df

        var index0 = Int(ceil(position))

            result[i] = a * t * t + b * t + c
            i = i + 1
        }

        return result
    }

    func log2length(time: Double) -> (Int, Int) {
        var lengthExp: Int = Int(floor(log2(time))) + 1
        var length: Int = Int(pow(2, Double(lengthExp)))

        return (lengthExp, length)
    }
}
