@Test public void dft1() { ListDouble x = new ArrayDouble(0, 1.0, 0, -1.0, 0, 1, 0, -1); ListDouble y = new ArrayDouble(0, 0, 0, 0, 0, 0, 0, 0); List<ListNumber> res = ListMath.dft(x, y); }
public static List<ListNumber> dft(ListNumber x, ListNumber y) { if (x.size() != y.size()) { throw new IllegalArgumentException("Real and imaginary part must be of the same length"); } double cosarg,sinarg; double[] resX = new double[x.size()]; double[] resY = new double[x.size()]; int direction = 1; double size = x.size(); for (int i = 0; i < x.size(); i++) { double arg = - direction * 2.0 * Math.PI * (double) i / size; for (int k = 0; k < x.size(); k++) { cosarg = Math.cos(k * arg); sinarg = Math.sin(k * arg); resX[i] += (x.getDouble(k) * cosarg - y.getDouble(k) * sinarg); resY[i] += (x.getDouble(k) * sinarg + y.getDouble(k) * cosarg); } } if (direction == 1) { for (int i = 0; i < x.size(); i++) { resX[i] = resX[i] / size; resY[i] = resY[i] / size; } return Arrays.<ListNumber>asList(new ArrayDouble(resX), new ArrayDouble(resY)); } else { return Arrays.<ListNumber>asList(new ArrayDouble(resY), new ArrayDouble(resX)); } }
ListMath { public static List<ListNumber> dft(ListNumber x, ListNumber y) { if (x.size() != y.size()) { throw new IllegalArgumentException("Real and imaginary part must be of the same length"); } double cosarg,sinarg; double[] resX = new double[x.size()]; double[] resY = new double[x.size()]; int direction = 1; double size = x.size(); for (int i = 0; i < x.size(); i++) { double arg = - direction * 2.0 * Math.PI * (double) i / size; for (int k = 0; k < x.size(); k++) { cosarg = Math.cos(k * arg); sinarg = Math.sin(k * arg); resX[i] += (x.getDouble(k) * cosarg - y.getDouble(k) * sinarg); resY[i] += (x.getDouble(k) * sinarg + y.getDouble(k) * cosarg); } } if (direction == 1) { for (int i = 0; i < x.size(); i++) { resX[i] = resX[i] / size; resY[i] = resY[i] / size; } return Arrays.<ListNumber>asList(new ArrayDouble(resX), new ArrayDouble(resY)); } else { return Arrays.<ListNumber>asList(new ArrayDouble(resY), new ArrayDouble(resX)); } } }
ListMath { public static List<ListNumber> dft(ListNumber x, ListNumber y) { if (x.size() != y.size()) { throw new IllegalArgumentException("Real and imaginary part must be of the same length"); } double cosarg,sinarg; double[] resX = new double[x.size()]; double[] resY = new double[x.size()]; int direction = 1; double size = x.size(); for (int i = 0; i < x.size(); i++) { double arg = - direction * 2.0 * Math.PI * (double) i / size; for (int k = 0; k < x.size(); k++) { cosarg = Math.cos(k * arg); sinarg = Math.sin(k * arg); resX[i] += (x.getDouble(k) * cosarg - y.getDouble(k) * sinarg); resY[i] += (x.getDouble(k) * sinarg + y.getDouble(k) * cosarg); } } if (direction == 1) { for (int i = 0; i < x.size(); i++) { resX[i] = resX[i] / size; resY[i] = resY[i] / size; } return Arrays.<ListNumber>asList(new ArrayDouble(resX), new ArrayDouble(resY)); } else { return Arrays.<ListNumber>asList(new ArrayDouble(resY), new ArrayDouble(resX)); } } private  ListMath(); }
ListMath { public static List<ListNumber> dft(ListNumber x, ListNumber y) { if (x.size() != y.size()) { throw new IllegalArgumentException("Real and imaginary part must be of the same length"); } double cosarg,sinarg; double[] resX = new double[x.size()]; double[] resY = new double[x.size()]; int direction = 1; double size = x.size(); for (int i = 0; i < x.size(); i++) { double arg = - direction * 2.0 * Math.PI * (double) i / size; for (int k = 0; k < x.size(); k++) { cosarg = Math.cos(k * arg); sinarg = Math.sin(k * arg); resX[i] += (x.getDouble(k) * cosarg - y.getDouble(k) * sinarg); resY[i] += (x.getDouble(k) * sinarg + y.getDouble(k) * cosarg); } } if (direction == 1) { for (int i = 0; i < x.size(); i++) { resX[i] = resX[i] / size; resY[i] = resY[i] / size; } return Arrays.<ListNumber>asList(new ArrayDouble(resX), new ArrayDouble(resY)); } else { return Arrays.<ListNumber>asList(new ArrayDouble(resY), new ArrayDouble(resX)); } } private  ListMath(); static ListDouble limit(final ListDouble data, final int start, final int end); static ListNumber limit(final ListNumber data, final int start, final int end); static ListLong limit(final ListLong data, final int start, final int end); static ListDouble rescale(final ListNumber data, final double factor, final double offset); static ListDouble inverseRescale(final ListNumber data, final double numerator, final double offset); static ListDouble pow(final ListNumber data, final double expon); static ListDouble pow(final double base, final ListNumber expons); static ListDouble add(final ListNumber data, final double offset); static ListDouble add(final ListNumber data1, final ListNumber data2); static ListDouble subtract(final ListNumber data1, final ListNumber data2); static ListDouble multiply(final ListNumber data1, final ListNumber data2); static ListDouble divide(final ListNumber data1, final ListNumber data2); static List<ListNumber> dft(ListNumber x, ListNumber y); }
ListMath { public static List<ListNumber> dft(ListNumber x, ListNumber y) { if (x.size() != y.size()) { throw new IllegalArgumentException("Real and imaginary part must be of the same length"); } double cosarg,sinarg; double[] resX = new double[x.size()]; double[] resY = new double[x.size()]; int direction = 1; double size = x.size(); for (int i = 0; i < x.size(); i++) { double arg = - direction * 2.0 * Math.PI * (double) i / size; for (int k = 0; k < x.size(); k++) { cosarg = Math.cos(k * arg); sinarg = Math.sin(k * arg); resX[i] += (x.getDouble(k) * cosarg - y.getDouble(k) * sinarg); resY[i] += (x.getDouble(k) * sinarg + y.getDouble(k) * cosarg); } } if (direction == 1) { for (int i = 0; i < x.size(); i++) { resX[i] = resX[i] / size; resY[i] = resY[i] / size; } return Arrays.<ListNumber>asList(new ArrayDouble(resX), new ArrayDouble(resY)); } else { return Arrays.<ListNumber>asList(new ArrayDouble(resY), new ArrayDouble(resX)); } } private  ListMath(); static ListDouble limit(final ListDouble data, final int start, final int end); static ListNumber limit(final ListNumber data, final int start, final int end); static ListLong limit(final ListLong data, final int start, final int end); static ListDouble rescale(final ListNumber data, final double factor, final double offset); static ListDouble inverseRescale(final ListNumber data, final double numerator, final double offset); static ListDouble pow(final ListNumber data, final double expon); static ListDouble pow(final double base, final ListNumber expons); static ListDouble add(final ListNumber data, final double offset); static ListDouble add(final ListNumber data1, final ListNumber data2); static ListDouble subtract(final ListNumber data1, final ListNumber data2); static ListDouble multiply(final ListNumber data1, final ListNumber data2); static ListDouble divide(final ListNumber data1, final ListNumber data2); static List<ListNumber> dft(ListNumber x, ListNumber y);  }