/
acsharpe.java
65 lines (47 loc) · 1.42 KB
/
acsharpe.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public class acsharpe {
/**
* @param args
*/
public static void main(String[] args) {
new acsharpe ();
}
public acsharpe ()
{
int bin =10;
double[] sample = new double[] {0.00, 1.00/1100.00, 2.00/1100.00, 3.00/1100.00, 4.00/1100.00, 5.00/1100.00, 6.00/1100.00, 7.00/1100.00, 8.00/1100.00, 9.00/1100.00};
double [][]bins = new double[2][sample.length];
for (int i=0; i<sample.length; i++){
System.out.println(sample[i]);
}
double sum=0;
//cosine function
for (int i =0; i<bin; i++){
for (int j=0; j<sample.length; j++){//j = index of sample array
sum+=sample[j]*Math.cos(-2*(Math.PI)*i*j/(sample.length));
}
bins[0][i]=sum;
System.out.println ("X bin "+i+" = "+bins[0][i]+" (R)");
sum=0;
}
sum=0;
System.out.println("\n\nImaginary Components");
//calculating imaginary component (sine function)
for (int i =0; i<bin; i++){
for (int j=0; j<sample.length; j++){//j = index of sample array
sum+=sample[j]*Math.sin(-2*(Math.PI)*i*j/(sample.length));
}
bins[1][i]=sum;
System.out.println ("X bin "+i+" = "+sum+"i");
sum=0;
}
double mag=0;
//calculating magnitude
for (int i=0;i<sample.length; i++){
mag=Math.pow(bins[0][i],2);
mag+=Math.pow(bins[1][i],2);
mag=Math.sqrt(mag);
System.out.println("Bin #: "+i+" Mag. ="+mag);
mag=0;
}
}
}