Java Code Examples for org.apache.commons.math.complex.Complex#subtract()
The following examples show how to use
org.apache.commons.math.complex.Complex#subtract() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 2
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 3
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 4
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 5
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 6
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 7
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 8
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 9
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 10
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 11
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 12
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param f the real data array to be transformed * @param isInverse the indicator of forward or inverse transform * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(double f[], boolean isInverse) throws IllegalArgumentException { verifyDataSet(f); Complex F[] = new Complex[f.length]; if (f.length == 1) { F[0] = new Complex(f[0], 0.0); return F; } // Rather than the naive real to complex conversion, pack 2N // real numbers into N complex numbers for better performance. int N = f.length >> 1; Complex c[] = new Complex[N]; for (int i = 0; i < N; i++) { c[i] = new Complex(f[2*i], f[2*i+1]); } roots.computeOmega(isInverse ? -N : N); Complex z[] = fft(c); // reconstruct the FFT result for the original array roots.computeOmega(isInverse ? -2*N : 2*N); F[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); F[N] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < N; i++) { Complex A = z[N-i].conjugate(); Complex B = z[i].add(A); Complex C = z[i].subtract(A); //Complex D = roots.getOmega(i).multiply(Complex.I); Complex D = new Complex(-roots.getOmegaImaginary(i), roots.getOmegaReal(i)); F[i] = B.subtract(C.multiply(D)); F[2*N-i] = F[i].conjugate(); } return scaleArray(F, 0.5); }
Example 13
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 14
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 15
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 16
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 17
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 18
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 19
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }
Example 20
Source File: FastFourierTransformer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Perform the base-4 Cooley-Tukey FFT algorithm (including inverse). * * @param data the complex data array to be transformed * @return the complex transformed array * @throws IllegalArgumentException if any parameters are invalid */ protected Complex[] fft(Complex data[]) throws IllegalArgumentException { final int n = data.length; final Complex f[] = new Complex[n]; // initial simple cases verifyDataSet(data); if (n == 1) { f[0] = data[0]; return f; } if (n == 2) { f[0] = data[0].add(data[1]); f[1] = data[0].subtract(data[1]); return f; } // permute original data array in bit-reversal order int ii = 0; for (int i = 0; i < n; i++) { f[i] = data[ii]; int k = n >> 1; while (ii >= k && k > 0) { ii -= k; k >>= 1; } ii += k; } // the bottom base-4 round for (int i = 0; i < n; i += 4) { final Complex a = f[i].add(f[i+1]); final Complex b = f[i+2].add(f[i+3]); final Complex c = f[i].subtract(f[i+1]); final Complex d = f[i+2].subtract(f[i+3]); final Complex e1 = c.add(d.multiply(Complex.I)); final Complex e2 = c.subtract(d.multiply(Complex.I)); f[i] = a.add(b); f[i+2] = a.subtract(b); // omegaCount indicates forward or inverse transform f[i+1] = roots.isForward() ? e2 : e1; f[i+3] = roots.isForward() ? e1 : e2; } // iterations from bottom to top take O(N*logN) time for (int i = 4; i < n; i <<= 1) { final int m = n / (i<<1); for (int j = 0; j < n; j += i<<1) { for (int k = 0; k < i; k++) { //z = f[i+j+k].multiply(roots.getOmega(k*m)); final int k_times_m = k*m; final double omega_k_times_m_real = roots.getOmegaReal(k_times_m); final double omega_k_times_m_imaginary = roots.getOmegaImaginary(k_times_m); //z = f[i+j+k].multiply(omega[k*m]); final Complex z = new Complex( f[i+j+k].getReal() * omega_k_times_m_real - f[i+j+k].getImaginary() * omega_k_times_m_imaginary, f[i+j+k].getReal() * omega_k_times_m_imaginary + f[i+j+k].getImaginary() * omega_k_times_m_real); f[i+j+k] = f[j+k].subtract(z); f[j+k] = f[j+k].add(z); } } } return f; }