Need help getting started with DFT/FFT using vDSP/Accelerate

Hi, I am having trouble getting started with the vDSP functions.


Can anyone show some sample code to calculate the DFT of a small array of real numbers like [0,0,1,0] ?

Replies

Ended up getting it to work with this:



let x : [Float] =   [1,2,3,4]// Input Real Part
let DFTSize = x.count

let y = [Float](repeatElement(0, count: DFTSize)) // Input Imag Part

var xo = [Float](repeatElement(0, count: DFTSize))
var yo = [Float](repeatElement(0, count: DFTSize))


print(x.count, y.count)

let length = vDSP_Length(x.count)
let setup = vDSP_DFT_zop_CreateSetup(nil, vDSP_Length(DFTSize), vDSP_DFT_Direction.FORWARD)
vDSP_DFT_Execute(setup!, x, y, &xo, &yo)

print(xo) // Print Real Output
print(yo) // Print Imag Output




I still really don’t understand all the data packing stuff in the real-to-complex functions, so I just decided to use the complex-to-complex functions and use an array of zeroes for the complex input vector.