Initial import.
[Faustine.git] / dsp_files / fft.lib.1.tmp.dsp
1 /******************************************************************
2 * FFT
3 * Implementation contributed by Remy Muller
4 *****************************************************************/
5
6 // bus(n) : n parallel cables
7 bus(2) = _,_; // avoids a lot of "bus(1)" labels in block diagrams
8 bus(n) = par(i, n, _);
9
10 // twiddle_mult(n) : n parallel cables
11
12 W(k, n) = 1, (0, ( k, ((2 * PI) / n) : *) : -) : polar_cplx;
13
14 twiddle_mult(k, n) = _, W(k, n) : pcplx_mul;
15
16 // selector(i,n) : select ith cable among n
17 selector(i,n) = par(j, n, S(i, j)) with { S(i,i) = _; S(i,j) = !; };
18
19 // interleave(m,n) : interleave m*n cables : x(0), x(m), x(2m), ..., x(1),x(1+m), x(1+2m)...
20 //interleave(m,n) = bus(m*n) <: par(i, m, par(j, n, selector(i+j*m,m*n)));
21
22 // interleave(row,col) : interleave row*col cables from column order to row order.
23 // input : x(0), x(1), x(2) ..., x(row*col-1)
24 // output: x(0+0*row), x(0+1*row), x(0+2*row), ..., x(1+0*row), x(1+1*row), x(1+2*row), ...
25 interleave(row,col) = bus(row*col) <: par(r, row, par(c, col, selector(r+c*row,row*col)));
26
27 // butterfly(n) : addition then substraction of interleaved signals :
28 xbutterfly(n) = (bus(n/2), par(k, n/2, twiddle_mult(k, n))) <: interleave(n/2,2), interleave(n/2,2) : par(i, n/2, pcplx_add), par(i, n/2, pcplx_sub);
29
30 //btf_downside(n) = bus(n) : interleave(n/2,2);
31
32 // fft(n) : fft matrix function of size n = 2^k
33 //fft(2) = butterfly(2);
34 //fft(n) = butterfly(n) : (fft(n/2) , fft(n/2));
35
36 xbutterflies(2) = xbutterfly(2);
37 xbutterflies(n) = (xbutterflies(n/2) , xbutterflies(n/2)) : xbutterfly(n);