use of org.yamcs.studio.data.vtype.ListNumber in project yamcs-studio by yamcs.
the class DftFormulaFunction method calculate.
@Override
public Object calculate(List<Object> args) {
var array = (VNumberArray) args.get(0);
if (array == null) {
return null;
}
if (array.getSizes().size() != 1) {
throw new IllegalArgumentException("Only 1D array supported for DFT");
}
// TODO: no need to allocate empty array
var fft = ListMath.dft(array.getData(), new ArrayDouble(new double[array.getData().size()]));
var real = fft.get(0);
var imaginary = fft.get(1);
ListNumber modulus = new ListDouble() {
@Override
public double getDouble(int index) {
var x = real.getDouble(index);
var y = imaginary.getDouble(index);
if (x != 0 || y != 0) {
return Math.sqrt(x * x + y * y);
} else {
return 0.0;
}
}
@Override
public int size() {
return real.size();
}
};
ListNumber phase = new ListDouble() {
@Override
public double getDouble(int index) {
var x = real.getDouble(index);
var y = imaginary.getDouble(index);
return Math.atan2(y, x);
}
@Override
public int size() {
return real.size();
}
};
return ValueFactory.newVTable(Arrays.<Class<?>>asList(double.class, double.class, double.class, double.class), Arrays.asList("x", "y", "mod", "phase"), Arrays.<Object>asList(real, imaginary, modulus, phase));
}
Aggregations