-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.js
45 lines (39 loc) · 1.08 KB
/
object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class vector
{
constructor(x,y){
this.x=x;
this.y=y;
}
}
class dftCoefficient
{
constructor(real,imaginary)
{
this.real=real;
this.imaginary=imaginary;
this.magnitude=Math.sqrt(this.real**2 + this.imaginary**2);
this.angle=Math.atan2(imaginary,real);
}
}
function discretFourierTransform(listePoint)
{
N=listePoint.length;
exponetialFunctions=[];
for(let i=0;i<N;i++)
{
let somme=math.complex(0,0);
for(let j=0;j<N;j++)
{
try {
let x_n=math.complex(listePoint[j].x,listePoint[j].y);
let exponential=math.complex(Math.cos((2*Math.PI*i*j)/N),-Math.sin((2*Math.PI*i*j)/N));
somme=math.add(somme,math.multiply(x_n,exponential));
} catch (error) {
console.log(error);
}
}
let func=new dftCoefficient(math.re(somme)/N,math.im(somme)/N);
exponetialFunctions[i]=func;
}
return exponetialFunctions;
}