List of usage examples for org.apache.commons.math3.transform FastFourierTransformer transformInPlace
public static void transformInPlace(final double[][] dataRI, final DftNormalization normalization, final TransformType type)
From source file:kip.utils.PowerUtils.java
/** * Performs a FFT over the data/*from w w w. ja va 2 s .c o m*/ * @param samples samples to perform FFT over * @return transformed voltage */ public static double[] voltageTransform(int[] samples) { double[][] data = new double[2][samples.length]; for (int i = 0; i < data[0].length; i++) { data[0][i] = i; data[1][i] = 0; } FastFourierTransformer.transformInPlace(data, DftNormalization.STANDARD, TransformType.FORWARD); //System.out.println(java.util.Arrays.toString(samples) + "\n"); //System.out.println(java.util.Arrays.toString(data[0]) + "\n"); return data[0]; }
From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java
/** * Computes discrete Hilbert transform of the input array (in place) using * FFTs. The transform operation is computed in place. For efficiency, no * error checking is performed on input data range limits or length of input * array. The input array length <b>must</b> be equal to a power of 2, * otherwise a runtime exception may be thrown. * * @param a input array/*from www.j a v a 2 s . com*/ * @param isForward true for forward Hilbert transform, false for inverse * Hilbert transform */ public static final void fastHilbertTransformPowerOf2(double[] a, boolean isForward) { int n = a.length; int nOver2 = n / 2; double c = isForward ? 1.0 : -1.0; // create zero-valued imaginary component double[] aIm = new double[n]; // perform FFT FastFourierTransformer.transformInPlace(new double[][] { a, aIm }, DftNormalization.STANDARD, TransformType.FORWARD); // zero out DC and Nyquist components a[0] = aIm[0] = a[nOver2] = aIm[nOver2] = 0.0; // multiply positive frequency components by -I for (int i = 1; i < nOver2; i++) { double temp = a[i]; a[i] = c * aIm[i]; aIm[i] = -c * temp; } // multiply negative frequency components by I for (int i = nOver2 + 1; i < n; i++) { double temp = a[i]; a[i] = -c * aIm[i]; aIm[i] = c * temp; } FastFourierTransformer.transformInPlace(new double[][] { a, aIm }, DftNormalization.STANDARD, TransformType.INVERSE); }
From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java
/** * Filters input array within specified range by Fourier transforming the * segment of the input array, multiplying the real and imaginary parts of * the transformed segment by {@code filterCoefficients} element-by-element, * and inverse Fourier transforming the result. The output is the filtered * segment; input array is unchanged. The length of the segment to be * filtered <b>must</b> be a power-of-2, otherwise unexpected results or * runtime errors may occur. No error checking is performed on range limits; * if the values are negative or outside the range of the array, a runtime * exception may be thrown.//from ww w . jav a2 s .c o m * * @param a input array (assumed to be real-valued) * @param from initial index of the range of elements to * filter * @param to final index of the range of elements to filter * @param filterCoefficients frequency-domain filter coefficients; if length * of array is not equal to {@code from-to}, * return an unmodified copy of the input array * segment * @return filtered array segment */ public static final double[] freqDomainFilter(double[] a, int from, int to, double[] filterCoefficients) { int n = to - from; double[] re = Arrays.copyOfRange(a, from, to); if (filterCoefficients.length != n) { return re; } double[] im = new double[n]; FastFourierTransformer.transformInPlace(new double[][] { re, im }, DftNormalization.STANDARD, TransformType.FORWARD); for (int i = 0; i < n; i++) { re[i] *= filterCoefficients[i]; im[i] *= filterCoefficients[i]; } FastFourierTransformer.transformInPlace(new double[][] { re, im }, DftNormalization.STANDARD, TransformType.INVERSE); return re; }