Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * complexData is overlapped 50%.
- * @param complexData
- * @return
- */
- private Double[] autoCorrelation(final Complex[] complexData) {
- Complex[] toFFT = doubleAndPad(complexData);
- Double[] autoCorrelationAbsolute = new Double[toFFT.length];
- FFT.fftForward(toFFT);
- for(int j = 0; j < toFFT.length; j++) {
- //Same as Complex.mult(toFFT[j], toFFT[j].conjugate()) but simpler
- double square = toFFT[j].absoluteSquare();
- toFFT[j] = new Complex(square);
- }
- //Effective inverse FFT
- //forward FFT == inverse FFT for real numbers.
- FFT.fftForward(toFFT);
- for(int i = 0; i < toFFT.length; i++) {
- autoCorrelationAbsolute[i] = toFFT[i].absolute();
- }
- return autoCorrelationAbsolute;
- }
- /**
- * Returns a copy of data with the size doubled and the
- * second half set to zero.
- * @param data
- * @return
- */
- private Complex[] doubleAndPad(Complex[] data) {
- Complex[] doubledData = Arrays.copyOf(data, data.length * 2);
- //Set the second half to zero
- for(int i = data.length; i < doubledData.length; i++) {
- doubledData[i] = new Complex(0);
- }
- return doubledData;
- }
- /**
- * Computes the frequency based off of the padded FFT in autoCorrelation
- * @param bin
- * @param data
- * @return
- */
- public static double computeFrequency(int bin, AudioData data) {
- return bin * data.getFormat().getSampleRate() / data.getFftLength();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement