List of usage examples for org.apache.commons.math3.transform TransformType FORWARD
TransformType FORWARD
To view the source code for org.apache.commons.math3.transform TransformType FORWARD.
Click Source Link
From source file:ro.hasna.ts.math.representation.DiscreteChebyshevTransformTest.java
@Test public void testTransform() throws Exception { double[] v = { 1, 2, 3 }; discreteChebyshevTransform.transform(v); Mockito.verify(fastFourierTransformer).transform(new double[] { 1, 2, 3, 2 }, TransformType.FORWARD); }
From source file:ro.hasna.ts.math.representation.DiscreteChebyshevTransformTest.java
@Test public void testTransform2() throws Exception { double[] v = { 1, 2, 3, 4 }; discreteChebyshevTransform.transform(v); Mockito.verify(fastFourierTransformer).transform(new double[] { 1, 2, 3, 4, 3, 2, 0, 0 }, TransformType.FORWARD); }
From source file:ro.hasna.ts.math.representation.DiscreteCosineTransform.java
/** * Transform a given sequence of values into Fourier coefficients using {@link FastCosineTransformer}. * The sequence is padded with zeros if it hasn't the right length. * * @param values the sequence of values/*from w w w. j a v a 2 s .c o m*/ * @return the result of the transformation */ public double[] transform(double[] values) { // pad the input array with zeros so as to have a length == 2^k + 1 int initialLength = values.length; int powerOfTwo = Integer.highestOneBit(initialLength); int requiredLength = powerOfTwo + 1; if (initialLength != requiredLength && initialLength != powerOfTwo) { requiredLength = (powerOfTwo << 1) + 1; } double[] copy = new double[requiredLength]; System.arraycopy(values, 0, copy, 0, initialLength); // run FCT (=> DCT-I) double[] transform = cosineTransformer.transform(copy, TransformType.FORWARD); // keep only the most important coefficients int outputLength = (powerOfTwo >> 1) + 1; double[] result = new double[outputLength]; for (int i = 0; i < outputLength && i < transform.length; i++) { result[i] = transform[i]; } return result; }
From source file:ro.hasna.ts.math.representation.DiscreteCosineTransformTest.java
@Test public void testTransform() throws Exception { double[] v = { 1, 2, 3, 4, 5, 6 }; discreteCosineTransform.transform(v); Mockito.verify(fastCosineTransformer).transform(new double[] { 1, 2, 3, 4, 5, 6, 0, 0, 0 }, TransformType.FORWARD); }
From source file:ro.hasna.ts.math.representation.DiscreteCosineTransformTest.java
@Test public void testTransformPowerOfTwoPlusOne() throws Exception { double[] v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; discreteCosineTransform.transform(v); Mockito.verify(fastCosineTransformer).transform(v, TransformType.FORWARD); }
From source file:ro.hasna.ts.math.representation.DiscreteFourierTransform.java
/** * Transform a given sequence of values into Fourier coefficients using {@link FastFourierTransformer}. * The sequence is padded with zeros if it hasn't the right length. * * @param values the sequence of values// w w w. ja v a 2s. com * @return the result of the transformation */ public double[] transform(double[] values) { // pad the input array with zeros so as to have a length == 2^k int initialLength = values.length; int powerOfTwo = Integer.highestOneBit(initialLength); if (initialLength != powerOfTwo) { powerOfTwo = powerOfTwo << 1; } double[] copy = new double[powerOfTwo]; System.arraycopy(values, 0, copy, 0, initialLength); // run FFT Complex[] complexes = fourierTransformer.transform(copy, TransformType.FORWARD); // keep only the most important coefficients int outputLength = (powerOfTwo >> 1) + 1; double[] result = new double[outputLength]; double k = 2.0 / initialLength; result[0] = complexes[0].divide(initialLength).abs(); for (int i = 1; i < outputLength && i < complexes.length; i++) { // multiply the values with 2/N result[i] = complexes[i].multiply(k).abs(); } return result; }
From source file:ro.hasna.ts.math.representation.DiscreteFourierTransformTest.java
@Test public void testTransform() throws Exception { double[] v = { 1, 2, 3 }; discreteFourierTransform.transform(v); Mockito.verify(fastFourierTransformer).transform(new double[] { 1, 2, 3, 0 }, TransformType.FORWARD); }
From source file:ro.hasna.ts.math.representation.DiscreteFourierTransformTest.java
@Test public void testTransformPowerOfTwo() throws Exception { double[] v = { 1, 2, 3, 4 }; discreteFourierTransform.transform(v); Mockito.verify(fastFourierTransformer).transform(v, TransformType.FORWARD); }
From source file:ru.spbspu.model.MathOperations.java
@Override public double[] transformFourier(double[] SFT) { FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] transformed = fft.transform(SFT, TransformType.FORWARD); for (int i = 0; i < SFT.length; i++) { // SFT[i]=transformed[i].abs(); SFT[i] = (Math.pow(Math.pow(transformed[i].getReal(), 2) + Math.pow(transformed[i].getImaginary(), 2), 0.5)) / SFT.length * 2;/*from www.j av a2 s .co m*/ // System.out.println("SFT length is "+SFT.length // +'\n'+"Transformed length is "+transformed.length); } return Arrays.copyOfRange(SFT, 2, SFT.length / 2); }
From source file:tw.edu.sju.ee.eea.module.iepe.file.IepeSpectrumElement.java
private JFreeChart createChart() { XYSeries series = new XYSeries("Ch_0"); try {/* w w w. j av a2 s .c o m*/ ValueInputStream vi = new ValueInputStream(info.getInputStream()); vi.skip(info.getCursor().getIndex() / 8); double[] value = new double[1024 * 16]; for (int i = 0; i < value.length; i++) { value[i] = vi.readValue(); } FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] data = ComplexUtils.convertToComplex(value); Complex[] transform = fft.transform(data, TransformType.FORWARD); int max = transform.length / 2 + 1; for (int i = 1; i < max; i++) { double f = (double) i * info.getSamplerate() / transform.length; series.add(f, transform[i].abs() / value.length * 2); } } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { } XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series); BodePlot bodePlot = new BodePlot("Spectrum"); bodePlot.addData(0, "Magnitude(dB)", collection); bodePlot.getXYPlot().getRangeAxis().setRange(0, 500); bodePlot.getXYPlot().getDomainAxis().setRange(0.5, 10000); return bodePlot; }