0

I am trying to implement the Accelerate DFT in Swift in the hope that this will deal with arbitrary sample sizes and not 2^n sample sizes only.

I am struggling to pass values to this function: vDSP_DFT_ExecuteD(...). My code is pasted below and I get an error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).

import Accelerate

var x = [Double]() // Input Real Part
var y = [Double]() // Input Imag Part

var xo = [Double]() // Output Real Part
var yo = [Double]() // Output Imag Part

x = [1,2,3,4,5]
y = [0,0,0,0,0]

var splitComplex = DSPDoubleSplitComplex(realp: &x, imagp: &y)

let length = vDSP_Length(x.count)

let weights = vDSP_DFT_zop_CreateSetupD(nil, length, vDSP_DFT_Direction.FORWARD)

vDSP_DFT_ExecuteD(weights!, x, y, &xo, &yo)

print(xo) // Print Real Output
print(yo) // Print Imag Output
Saif
  • 163
  • 2
  • 11
  • According to https://developer.apple.com/documentation/accelerate/1450061-vdsp_dft_zop_createsetup, vDSP_DFT_zop_CreateSetupD *cannot* be called with length=5. – Martin R Nov 05 '17 at 09:19
  • Thans Martin ! I just saw it and you are right. Was just hoping that Apple might have taken care of it. – Saif Nov 05 '17 at 09:52
  • I've implemented this in the past by using interpolation to a time domain that is a power of two. Naturally, that introduces some high frequency artefacts, but if you can live with that it's pretty straightforward. – Grimxn Nov 05 '17 at 15:02
  • 1
    Thanks Grimnx ! I am trying to implement this on iOS, so interpolation will add more complexity to computation, I guess? Ideally, I was looking for the results similar to the Matlab FFT function. – Saif Nov 05 '17 at 16:44

0 Answers0