Skip to content

fft

Complex-to-complex Fast Fourier Transform.

Applies a forward Fast Fourier Transform to a complex-valued input 1-dimensional array producing a complex-valued output. The output is another array containing the complex-valued signal, and both arrays are arranged in interleaved real-imaginary format.

In the case of the k-array version, the output array will have the same size as the input, and the transform size will be equivalent to half of the length of the input array (since the real and imag parts are interleaved). The transform is always forward in this version.

This is not the case in the Complex-type array versions, where the transform size always matches the size of the input. There are three of these: complex to complex types (forward or inverse); real to complex (forward) and complex to real (inverse). The last two are not true real-fft transforms: they still produce/consume a full Hermitian-symmetric spectrum, but they only use real time-domain signals (and assume imaginary part is always zero).

Non-power-of-two transforms are limited to even sizes with not too many factors.

Syntax

out:k[] = fft(in:k[])
in:Complex[] = fft(in:Complex[][,inverse:i])
in:Complex[] = fft(in:k[]);
out:k[] = fft(in:Complex[]);
kout[] fft kin[]
in:Complex[] fft in:Complex[]
in:Complex[] fft in:k[] 
kout[] fft in:Complex[];

Initialisation

inverse -- if non-zero, apply an inverse transform. Defaults to 0 (forward).

Performance

out -- output array containing the complex or real-valued output, depending on the opcode version. It will be created if it does not exist.

in -- input array containing the complex or real-valued input, depending on the opcode version.

Examples

This is example of the fft opcode (k-type array). It uses the file fft.csd.

Example of the fft opcode (k array).
<CsoundSynthesizer>
<CsOptions>
-d -o dac
</CsOptions>
<CsInstruments>
ksmps = 64

instr 1
ifftsize = 1024
kcnt init 0
kIn[] init  ifftsize
kOut[] init ifftsize

a1 oscili 0dbfs/2, 440

if kcnt >= ifftsize then
 kCmplx[] r2c kIn
 kSpec[] fft kCmplx
 kCmplx fftinv kSpec
 kOut c2r kCmplx
 kcnt = 0 
endif

kIn[] shiftin a1
a2 shiftout kOut
kcnt += ksmps
   out a2
endin
</CsInstruments>
<CsScore>
i1 0 10
</CsScore>
</CsoundSynthesizer>

Another example of the fft opcode, now using a Complex-type array. It uses the file fft_complex_type.csd.

Example of the fft opcode (Complex array.
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
ksmps = 1024  // sets transform size
nchnls = 1
0dbfs = 1

instr 1
 Params:i[] = array(p4, p5)
 Audio:k[] = array(oscili(Params[0],Params[1]))
 Spec:Complex[] = fft(Audio)
 Wave:k[] = fft(Spec)
 out a(Wave)
endin
schedule(1,0,2,0.5,440)
event_i("e",0,2)

</CsInstruments>
<CsScore>
</CsScore>
</CsoundSynthesizer>

See Also

Vectorial opcodes

array opcodes

Array-based spectral opcodes

Credits

Author: Victor Lazzarini
NUI Maynooth
2014

New in version 6.04
Complex type introduced in version 7.