Initial import.
[Faustine.git] / dsp_files / complex.5.tmp.dsp
1 import ( "math.lib" );
2 square = _ <: *;
3
4 // Complex in cartesian coordinates
5 carte_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
6
7 // Cartesian complex : basic operations
8 ccplx_real = _, 0 : [];
9 ccplx_imag = _, 1 : [];
10 ccplx_conj = _ <: ccplx_real, ccplx_imag : _, (0, _ : -) : carte_cplx;
11 ccplx_modul2 = _ <: ccplx_real, ccplx_imag : square, square : +;
12 ccplx_modul = ccplx_modul2 : sqrt;
13 ccplx_angle = _ <: (ccplx_imag, ccplx_real : / : atan), (ccplx_real, 0 : < : _, PI : *) : +;
14 ccplx_div_real = _, _ <: ccplx_real, _, ccplx_imag, _ : /, / : carte_cplx;
15
16 // cartesian complex : add, sub, mul and div
17 ccplx_add = +;
18 ccplx_sub = -;
19
20 ccplx_mul = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag,ccplx_real, ccplx_imag, ccplx_imag, ccplx_real : *, *, *, * : -, + : carte_cplx;
21
22 ccplx_div = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag, ccplx_imag, ccplx_real, ccplx_real, ccplx_imag, !, ccplx_real, !, ccplx_imag : *, *, *, *, square, square : +, -, + : carte_cplx, _ : ccplx_div_real;
23 //ccplx_div = _, _ <: _, ccplx_conj, !, _ : ccplx_mul, ccplx_modul2 : ccplx_div_real;
24
25 // Complex in polar coordinates
26 polar_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #;
27 pcplx_modul = _, 0 : [];
28 pcplx_angle = _, 1 : [];
29 pcplx_real = _ <: pcplx_modul, (pcplx_angle : cos) : *;
30 pcplx_imag = _ <: pcplx_modul, (pcplx_angle : sin) : *;
31
32 // conversion between cartesian complex and polar complex
33 sca_abs = _ <: _, (>(0) : *(2) : -(1)) : *;
34 sca2pcplx = _ <: sca_abs, (<(0) : *(PI)) : polar_cplx;
35 polar2carte = _ <: pcplx_real, pcplx_imag : carte_cplx;
36 carte2polar = _ <: ccplx_modul, ccplx_angle : polar_cplx;
37
38 // Polar complex : add, sub, mul and div
39 pcplx_add = _, _ : polar2carte, polar2carte : ccplx_add : carte2polar;
40 pcplx_sub = _, _ : polar2carte, polar2carte : ccplx_sub : carte2polar;
41 pcplx_mul = _, _ <: (pcplx_modul, pcplx_modul : *), (pcplx_angle, pcplx_angle : +) : polar_cplx;
42
43 pcplx_div = _, _ <: (pcplx_modul, pcplx_modul : /), (pcplx_angle, pcplx_angle : -) : polar_cplx;
44
45 //functions used in FFT
46 real_pcplx_mul = _, ( _ <: pcplx_modul, pcplx_angle) : *, _ : polar_cplx;
47 pcplx_moduls(n) = par(i, n, pcplx_modul);
48
49