public void init() { // this.coeffs = MathBasics.getLPCoefficientsButterworth2Pole(bciSettings.getSamplesPerSecond(), 36d); this.fft = new DoubleFFT_1D(bciSettings.getSamplesPerSecond()); this.fftData.init(bciSettings.getSamplesPerSecond(), bciSettings.getBins(), bciSettings.getNumChannels()); System.out.println("window size: " + this.fftData.windowSize + " / samples per second: " + bciSettings.getSamplesPerSecond()); this.filterWindow = WindowFunction.generate(this.fftData.windowSize, WindowFunction.FunctionType.BLACKMAN); }
public FftGenerator(long size){ this.fft = new DoubleFFT_1D(size); //If this happens we can convert this to use a LargeDoubleArray instead of normal arrays if(size > Integer.MAX_VALUE) throw new ShouldNeverHappenException("Too much data to fft!"); this.values = new double[(int)size]; this.position = 0; this.averageSamplePeriodMs = 0; this.lastTimestamp = 0; }
public double calculateFFT(double[] signal) { final int mNumberOfFFTPoints =1024; double[] magnitude = new double[mNumberOfFFTPoints/2]; DoubleFFT_1D fft = new DoubleFFT_1D(mNumberOfFFTPoints); double[] fftData = new double[mNumberOfFFTPoints*2]; double max_index=-1; double max_magnitude=-1; final float sampleRate=44100; double frequency; for (int i=0;i<mNumberOfFFTPoints;i++){ //fftData[2 * i] = buffer[i+firstSample]; fftData[2 * i] = signal[i]; //da controllare fftData[2 * i + 1] = 0; fft.complexForward(fftData); } for(int i = 0; i < mNumberOfFFTPoints/2; i++){ magnitude[i]=Math.sqrt((fftData[2*i] * fftData[2*i]) + (fftData[2*i + 1] * fftData[2*i + 1])); if (max_magnitude<magnitude[i]){ max_magnitude=magnitude[i]; max_index=i; } } return frequency=sampleRate*(double)max_index/(double)mNumberOfFFTPoints; }
/** * Creates new instance of DoubleDHT_1D. * * @param n size of data */ public DoubleDHT_1D(long n) { this.n = (int) n; this.nl = n; this.useLargeArrays = (CommonUtils.isUseLargeArrays() || n > LargeArray.getMaxSizeOf32bitArray()); fft = new DoubleFFT_1D(n); }
/** * Creates new instance of DoubleDHT_1D. * * @param n size of data */ public DoubleDHT_1D(long n) { this.n = (int) n; this.nl = n; this.useLargeArrays = (CommonUtils.isUseLargeArrays() || n > LargeArray.getMaxSizeOf32bitArray()); fft = new DoubleFFT_1D(n); }
System.out.println("Complex forward FFT 1D of size " + sizes1D[i]); if (doWarmup) { // call the transform twice to warm up DoubleFFT_1D fft = new DoubleFFT_1D(sizes1D[i]); x = new double[(int) (2 * sizes1D[i])]; IOUtils.fillMatrix_1D(2 * sizes1D[i], x); DoubleFFT_1D fft = new DoubleFFT_1D(sizes1D[i]); times_with_constructor[i] = (System.nanoTime() - elapsedTime) / 1000000.0; x = new double[(int) (2 * sizes1D[i])];
fftRows = new DoubleFFT_1D(rows); if (rows == columns) { fftColumns = fftRows; } else { fftColumns = new DoubleFFT_1D(columns);
fftRows = new DoubleFFT_1D(rows); if (rows == columns) { fftColumns = fftRows; } else { fftColumns = new DoubleFFT_1D(columns);
public static double[][] computeFreqMagPhase(double[] time, double[] data) { int n = time.length; if (data.length != n) throw new RuntimeException("input.length != n"); DoubleFFT_1D fft = new DoubleFFT_1D(n); double T = time[n - 1] - time[0]; double fftInput[] = copyDoubleArray(data); fft.realForward(fftInput); double[] magnitude = extractMagnitude(fftInput); double[] phase = extractPhaseRadians(fftInput); double[] frequency = new double[n / 2]; for (int i = 0; i < n / 2; i++) { frequency[i] = (i) / T; } return new double[][] { frequency, magnitude, phase }; }
public static double[][] computeFreqMagPhase(double[] time, double[] data) { int n = time.length; if (data.length != n) throw new RuntimeException("input.length != n"); DoubleFFT_1D fft = new DoubleFFT_1D(n); double T = time[n - 1] - time[0]; double fftInput[] = copyDoubleArray(data); fft.realForward(fftInput); double[] magnitude = extractMagnitude(fftInput); double[] phase = extractPhaseRadians(fftInput); double[] frequency = new double[n / 2]; for (int i = 0; i < n / 2; i++) { frequency[i] = (i) / T; } return new double[][] { frequency, magnitude, phase }; }
public static double[][] computeFreqMagPhase(double[] time, double[] data) { int n = time.length; if (data.length != n) throw new RuntimeException("input.length != n"); DoubleFFT_1D fft = new DoubleFFT_1D(n); double T = time[n - 1] - time[0]; double fftInput[] = copyDoubleArray(data); fft.realForward(fftInput); double[] magnitude = extractMagnitude(fftInput); double[] phase = extractPhaseRadians(fftInput); double[] frequency = new double[n / 2]; for (int i = 0; i < n / 2; i++) { frequency[i] = (i) / T; } return new double[][] { frequency, magnitude, phase }; }
/** * Returns new complex matrix which is the discrete Fourier transform (DFT) * of this matrix. * * @return the discrete Fourier transform (DFT) of this matrix. */ public DenseDComplexMatrix1D getFft() { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); final double[] elems; if (isNoView == true) { elems = elements; } else { elems = (double[]) this.copy().elements(); } DenseDComplexMatrix1D c = new DenseDComplexMatrix1D(size); final double[] elementsC = (c).elements(); System.arraycopy(elems, 0, elementsC, 0, size); if (fft == null) { fft = new DoubleFFT_1D(size); } fft.realForwardFull(elementsC); ConcurrencyUtils.setNumberOfThreads(oldNthreads); return c; }
/** * Returns new complex matrix which is the inverse of the discrete Fourier * (IDFT) transform of this matrix. * * @return the inverse of the discrete Fourier transform (IDFT) of this * matrix. */ public DenseDComplexMatrix1D getIfft(boolean scale) { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); final double[] elems; if (isNoView == true) { elems = elements; } else { elems = (double[]) this.copy().elements(); } DenseDComplexMatrix1D c = new DenseDComplexMatrix1D(size); final double[] elementsC = (c).elements(); System.arraycopy(elems, 0, elementsC, 0, size); if (fft == null) { fft = new DoubleFFT_1D(size); } fft.realInverseFull(elementsC, scale); ConcurrencyUtils.setNumberOfThreads(oldNthreads); return c; }
fftRows = new DoubleFFT_1D(columns);
fftRows = new DoubleFFT_1D(columns);
/** * Computes the discrete Fourier transform (DFT) of this matrix. Throws * IllegalArgumentException if the size of this matrix is not a power of 2 * number. */ public void fft() { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); if (fft == null) { fft = new DoubleFFT_1D(size); } if (isNoView) { fft.complexForward(elements); } else { DComplexMatrix1D copy = this.copy(); fft.complexForward((double[]) copy.elements()); this.assign((double[]) copy.elements()); } ConcurrencyUtils.setNumberOfThreads(oldNthreads); }
/** * Computes the inverse of the discrete Fourier transform (IDFT) of this * matrix. Throws IllegalArgumentException if the size of this matrix is not * a power of 2 number. * * @param scale * if true, then scaling is performed. */ public void ifft(boolean scale) { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); if (fft == null) { fft = new DoubleFFT_1D(size); } if (isNoView) { fft.complexInverse(elements, scale); } else { DComplexMatrix1D copy = this.copy(); fft.complexInverse((double[]) copy.elements(), scale); this.assign((double[]) copy.elements()); } ConcurrencyUtils.setNumberOfThreads(oldNthreads); }
ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); if (fft == null) { fft = new DoubleFFT_1D(size);
/** * Computes the inverse of the discrete Fourier transform (DFT) of this * matrix. The physical layout of the input data has to be as follows: * * <pre> * this[2*k] = Re[k], 0<=k<size/2 * this[2*k+1] = Im[k], 0<k<size/2 * this[1] = Re[size/2] * </pre> * * This method computes only half of the elements of the real transform. The * other half satisfies the symmetry condition. If you want the full real * inverse transform, use <code>getIfft</code>. * */ public void ifft(boolean scale) { int oldNthreads = ConcurrencyUtils.getNumberOfThreads(); ConcurrencyUtils.setNumberOfThreads(ConcurrencyUtils.nextPow2(oldNthreads)); if (fft == null) { fft = new DoubleFFT_1D(size); } if (isNoView) { fft.realInverse(elements, scale); } else { DoubleMatrix1D copy = this.copy(); fft.realInverse((double[]) copy.elements(), scale); this.assign((double[]) copy.elements()); } ConcurrencyUtils.setNumberOfThreads(oldNthreads); }
public Online1DSignalFourierAnalysis(String namePrefix, double estimationWindow, double dt, YoVariableRegistry parentRegistry) { this.dt = dt; registry = new YoVariableRegistry(namePrefix + "FrequencyAnalysis"); parentRegistry.addChild(registry); enabled = new BooleanYoVariable(registry.getName() + "_enabled", registry); int windowSize = 10; principalOscillationIndex = new GlitchFilteredIntegerYoVariable(namePrefix + "PrincipalOscillationIndex", windowSize, registry); secondaryOscillationIndex = new GlitchFilteredIntegerYoVariable(namePrefix + "SecondaryOscillationIndex", windowSize, registry); principalFrequency = new DoubleYoVariable(namePrefix + "PrincipalFrequency", registry); secondaryFrequency = new DoubleYoVariable(namePrefix + "SecondaryFrequency", registry); principalMagnitude = new DoubleYoVariable(namePrefix + "PrincipalMagnitude", registry); secondaryMagnitude = new DoubleYoVariable(namePrefix + "SecondaryMagnitude", registry); minFrequencyIndex = new IntegerYoVariable(namePrefix + "MinFrequencyIndex", registry); minFrequencyIndex.set(2); minimumMagnitude = new DoubleYoVariable(namePrefix + "MinimumMagnitude", registry); this.numberOfObservations = (int) (estimationWindow / dt); observationDuration = (numberOfObservations - 1) * dt; fft = new DoubleFFT_1D(numberOfObservations); signalBuffer = new double[numberOfObservations]; fftOuput = new double[numberOfObservations]; frequencies = new double[numberOfObservations / 2]; magnitudes = new double[numberOfObservations / 2]; filteredMagnitudes = new double[numberOfObservations / 2]; magnitudeAlpha = new DoubleYoVariable(namePrefix + "MagnitudeAlpha", registry); for (int i = 0; i < numberOfObservations / 2; i++) frequencies[i] = i / observationDuration; }