-
Notifications
You must be signed in to change notification settings - Fork 114
/
Fft2.java
41 lines (32 loc) · 1.07 KB
/
Fft2.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
package com.example.yo7a.healthwatcher.Math;
public class Fft2 {
public static double FFT(Double[] in, int size, double samplingFrequency) {
double temp = 0;
double POMP = 0;
double frequency;
double[] output = new double[2 * size];
Butterworth butterworth = new Butterworth();
butterworth.bandPass(2, samplingFrequency, 0.2, 0.3);
for (int i = 0; i < output.length; i++)
output[i] = 0;
for (int x = 0; x < size; x++) {
output[x] = in[x];
}
DoubleFft1d fft = new DoubleFft1d(size);
fft.realForward(output);
for (int x = 0; x < 2 * size; x++) {
output[x] = butterworth.filter(output[x]);
}
for (int x = 0; x < 2 * size; x++) {
output[x] = Math.abs(output[x]);
}
for (int p = 12; p < size; p++) {
if (temp < output[p]) {
temp = output[p];
POMP = p;
}
}
frequency = POMP * samplingFrequency / (2 * size);
return frequency;
}
}