use of org.apache.commons.math3.complex.Complex in project opennars by opennars.
the class SpectrumChart method update.
protected void update() {
TreeMLData chart = data.get(0);
float length = chart.getEnd() - chart.getStart();
;
int numWindows = (int) Math.ceil(length / windowSize);
// TODO dont remove existing windows
windows.clear();
int t = 0;
for (int w = 0; w < numWindows; w++) {
final int vl = windowSize;
double[] input = new double[vl];
for (int i = 0; i < vl; i++) {
input[i] = (float) chart.getData(t++);
}
Complex[] c = fft.transform(input, TransformType.FORWARD);
// phase = atan2( imaginary , real )
// magnitude = sqrt( real<sup>2</sup> + imaginary<sup>2</sup> )
windows.add(new Window(c));
}
}
Aggregations