Skip to content

Commit d7b13bc

Browse files
committed
initial code commit
1 parent 64756e9 commit d7b13bc

File tree

3 files changed

+891
-0
lines changed

3 files changed

+891
-0
lines changed

FFT.java

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* FFT Export
3+
* James Halliday
4+
* 2001
5+
* FFT.java - handle FFT Stuff Here
6+
*/
7+
8+
//Version 1.0
9+
10+
//////////////////////////IMPORTS//////////////////////////
11+
import java.io.*;
12+
import javax.swing.*;
13+
import java.awt.*;
14+
import java.awt.event.*;
15+
import javax.swing.event.*;
16+
import java.lang.Math;
17+
18+
/////////////////////////JMFaccess CLASS//////////////////////
19+
public class FFT
20+
{
21+
int numbits;
22+
//constructor
23+
public FFT()
24+
{}
25+
26+
////////////////////////METHODS/////////////////////////////
27+
public double[] doFFT(double[] innie, int pow2)
28+
{
29+
//find numbits
30+
numbits = 0;
31+
//find numbits, used for internal FFT processing, based on power2
32+
for (;;)
33+
{
34+
if ((pow2 & (1 << numbits)) != 0)
35+
break;
36+
numbits = numbits + 1;
37+
}
38+
//temporary arrays for FFT creation
39+
double outarray[] = new double[pow2];
40+
double ioutarray[] = new double[pow2];
41+
//counters, counters, counters!
42+
int count = 0;
43+
int count2 = 0;
44+
int mark = 0;
45+
//vars for internal FFT processing
46+
int blockend = 0;
47+
int blocksize = 0;
48+
double deltaangle = 0;
49+
double alpha = 0;
50+
double beta = 0;
51+
double ar, ai;
52+
int k;
53+
double tr, ti;
54+
double deltaar;
55+
//next - reverse bits in array
56+
count = 0;
57+
mark = 0;
58+
while (count < pow2)
59+
{
60+
mark = reversebits(count);
61+
outarray[mark] = innie[count];
62+
//also set ioarray to zero here
63+
ioutarray[count] = 0;
64+
count++;
65+
}
66+
//next = actual FFT calculations
67+
blockend = 1;
68+
blocksize = 2;
69+
//big loop
70+
while (blocksize <= pow2)
71+
{
72+
deltaangle = (2.0d * 3.14159265358979323846d) / (double)blocksize;
73+
alpha = Math.sin(0.5d * deltaangle);
74+
alpha = 2.0d * alpha * alpha;
75+
beta = Math.sin(deltaangle);
76+
count = 0;
77+
//medium loop
78+
while (count < pow2)
79+
{
80+
ar = 1.0d;
81+
ai = 0.0d;
82+
mark = count;
83+
count2 = 0;
84+
//little loop
85+
while (count2 < blockend)
86+
{
87+
k = mark + blockend;
88+
tr = (ar*outarray[k]) - (ai*ioutarray[k]);
89+
ti = (ai*outarray[k]) + (ar*ioutarray[k]);
90+
outarray[k] = outarray[mark] - tr;
91+
ioutarray[k] = ioutarray[mark] - ti;
92+
outarray[mark] += tr;
93+
ioutarray[mark] += ti;
94+
deltaar = (alpha*ar) + (beta*ai);
95+
ai -= ((alpha*ai) - (beta*ar));
96+
ar -= deltaar;
97+
//little loop incrementers
98+
mark = mark + 1;
99+
count2 = count2 + 1;
100+
}
101+
//medium loop incrementer
102+
count += blocksize;
103+
}
104+
//big loop incrementers
105+
blockend = blocksize;
106+
blocksize <<= 1;
107+
}
108+
//FFT DONE
109+
return outarray;
110+
}
111+
//reversebits - an internal process of FFT, from an algorithm of Don Cross
112+
public int reversebits(int index)
113+
{
114+
int i, rev;
115+
for (i=rev=0; i < numbits; i++)
116+
{
117+
rev = (rev << 1) | (index & 1);
118+
index >>= 1;
119+
}
120+
return rev;
121+
}
122+
}

0 commit comments

Comments
 (0)