FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Maths/FFTBluestein.java at master · primary-code-test/Java · GitHub
primary-code-test
Java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Maths
/
FFTBluestein.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (53 loc) · 2.17 KB
Breadcrumbs
Java
/
Maths
/
FFTBluestein.java
Copy path
File metadata and controls
61 lines (53 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
maths
;
import
java
.
util
.
ArrayList
;
/**
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal using the Bluestein's
* algorithm.
*
* @author Ioannis Karavitsis
* @version 1.0
*/
public
class
FFTBluestein
{
/**
* Bluestein's FFT Algorithm.
*
* <p>More info: https://en.wikipedia.org/wiki/Chirp_Z-transform#Bluestein.27s_algorithm
* http://tka4.org/materials/lib/Articles-Books/Numerical%20Algorithms/Hartley_Trasform/Bluestein%27s%20FFT%20algorithm%20-%20Wikipedia,%20the%20free%20encyclopedia.htm
*
* @param x The discrete signal which is then converted to the FFT or the IFFT of signal x.
* @param inverse True if you want to find the inverse FFT.
*/
public
static
void
fftBluestein
(
ArrayList
<
FFT
.
Complex
>
x
,
boolean
inverse
) {
int
N
=
x
.
size
();
int
bnSize
=
2
*
N
-
1
;
int
direction
=
inverse
? -
1
:
1
;
ArrayList
<
FFT
.
Complex
>
an
=
new
ArrayList
<>();
ArrayList
<
FFT
.
Complex
>
bn
=
new
ArrayList
<>();
/* Initialization of the b(n) sequence (see Wikipedia's article above for the symbols used)*/
for
(
int
i
=
0
;
i
<
bnSize
;
i
++)
bn
.
add
(
new
FFT
.
Complex
());
for
(
int
i
=
0
;
i
<
N
;
i
++) {
double
angle
= (
i
-
N
+
1
) * (
i
-
N
+
1
) *
Math
.
PI
/
N
*
direction
;
bn
.
set
(
i
,
new
FFT
.
Complex
(
Math
.
cos
(
angle
),
Math
.
sin
(
angle
)));
bn
.
set
(
bnSize
-
i
-
1
,
new
FFT
.
Complex
(
Math
.
cos
(
angle
),
Math
.
sin
(
angle
)));
}
/* Initialization of the a(n) sequence */
for
(
int
i
=
0
;
i
<
N
;
i
++) {
double
angle
= -
i
*
i
*
Math
.
PI
/
N
*
direction
;
an
.
add
(
x
.
get
(
i
).
multiply
(
new
FFT
.
Complex
(
Math
.
cos
(
angle
),
Math
.
sin
(
angle
))));
}
ArrayList
<
FFT
.
Complex
>
convolution
=
ConvolutionFFT
.
convolutionFFT
(
an
,
bn
);
/* The final multiplication of the convolution with the b*(k) factor */
for
(
int
i
=
0
;
i
<
N
;
i
++) {
double
angle
= -
1
*
i
*
i
*
Math
.
PI
/
N
*
direction
;
FFT
.
Complex
bk
=
new
FFT
.
Complex
(
Math
.
cos
(
angle
),
Math
.
sin
(
angle
));
x
.
set
(
i
,
bk
.
multiply
(
convolution
.
get
(
i
+
N
-
1
)));
}
/* Divide by N if we want the inverse FFT */
if
(
inverse
) {
for
(
int
i
=
0
;
i
<
N
;
i
++) {
FFT
.
Complex
z
=
x
.
get
(
i
);
x
.
set
(
i
,
z
.
divide
(
N
));
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL