Class Correlations
- Author:
- Doug Gillespie
Various functions to do with cross correlating two or more signals
As with the FastFFT class, these functions are no longer static so that Allocation of FFT internal storage is done separately for each detector. This avoids it having to be continually reallocated if fft's of different lenghts are taken.
Also calculates a delay correction factor based on a parabolic interpolation around the maximum value. For compatibility with previous versions, the returned results is still the integer solution. If you require greater accuracy, you should get the interpolated correction and add this to the main integer result for double precision accuracy.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
defaultTimingError
(float sampleRate) Generate a default timing error which is 1/sqrt(12) times the sample intervaldouble[]
getCorrelation
(double[] wave1, double[] wave2, boolean normalise) Get the correlation function of waves 1 and 2 and normalise if requested.double
Get the value of the last correlation calculated by any of the functions in the class.getDelay
(double[] s1, double[] s2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength) Measure the time delay between pulses on two channels.getDelay
(double[] s1, double[] s2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength, double maxDelaySamples) Measure the time delay between pulses on two channels.getDelay
(ComplexArray f1, ComplexArray f2, int fftLength, double maxDelay, int[] binRange) Measure the time delay between pulses on two channels.getDelay
(ComplexArray f1, ComplexArray f2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength) Measure the time delay between pulses on two channels.getDelay
(ComplexArray complexArray, ComplexArray complexArray2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength, double maxDelaySamples) Measure the time delay between pulses on two channels.double[][]
getInterpolatedMaxima
(double[] corrFunction) Get interpolated maxima around every peak in the correlation function.double[]
getInterpolatedPeak
(double[] corrFunction) Find the peak of a correlation function, interpolating about each peak using a wee parabola.double[]
getInterpolatedPeak
(double[] invFFTData, double scale, double maxDelay) double[]
getInterpolatedPeak
(Complex[] complexData, double scale, double maxDelay) Get the peak position and the peak height from a complex array returned by the ifft function.double[]
getInterpolatedPeak
(ComplexArray complexData, double scale, double maxDelay) Get the peak position and the peak height from a complex array returned by the ifft function.double[]
double[]
double[]
getMaxDelays
(float sampleRate, int groupHydrophones, long currentMillis) Get the maximum permissible delays in samples for the set of hydrophones.double
parabolicCorrection
(double y1, double y2, double y3) Calculate a parabolic fit correction based on three bin heights
The answer should always be between -0.5 and +0.5double
parabolicHeight
(double time, double[] correlationFunction) double
parabolicHeight
(double y1, double y2, double y3) Calculate a parabolic maximum height based on three bin heightsvoid
setLastCorrelationData
(double[] lastCorrelationData) void
setLastPeak
(double[] lastPeak)
-
Constructor Details
-
Correlations
public Correlations()
-
-
Method Details
-
getDelay
public TimeDelayData getDelay(double[] s1, double[] s2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength) Measure the time delay between pulses on two channels.- Parameters:
delayMeasurementParams
- Measurement parameters.fftLength
- FFT length to use (data will be packed or truncated as necessary)f1
- waveform on channel 1f2
- waveform on channel 2- Returns:
- time delay in samples.
-
getDelay
public TimeDelayData getDelay(double[] s1, double[] s2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength, double maxDelaySamples) Measure the time delay between pulses on two channels.- Parameters:
delayMeasurementParams
- Measurement parameters.fftLength
- FFT length to use (data will be packed or truncated as necessary)maxDelaySamples
- Maximum possible delay in samplesf1
- waveform on channel 1f2
- waveform on channel 2- Returns:
- time delay in samples.
-
getDelay
public TimeDelayData getDelay(ComplexArray f1, ComplexArray f2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength) Measure the time delay between pulses on two channels. Inputs in this case are the spectrum data (most of the cross correlation is done in the frequency domain)- Parameters:
f1
- complex spectrum on channel 1f2
- complex spectrum on channel 2delayMeasurementParams
- Measurement parameters.fftLength
- FFT length to use (data will be packed or truncated as necessary)- Returns:
- time delay in samples.
-
getDelay
public TimeDelayData getDelay(ComplexArray complexArray, ComplexArray complexArray2, DelayMeasurementParams delayMeasurementParams, double sampleRate, int fftLength, double maxDelaySamples) Measure the time delay between pulses on two channels. Inputs in this case are the spectrum data (most of the cross correlation is done in the frequency domain)- Parameters:
complexArray
- complex spectrum on channel 1complexArray2
- complex spectrum on channel 2delayMeasurementParams
- Measurement parameters.fftLength
- FFT length to use (data will be packed or truncated as necessary)maxDelaySamples
- Maximum feasible delay between channels.- Returns:
- time delay in samples.
-
getDelay
public TimeDelayData getDelay(ComplexArray f1, ComplexArray f2, int fftLength, double maxDelay, int[] binRange) Measure the time delay between pulses on two channels. Inputs in this case are the spectrum data (most of the cross correlation is done in the frequency domain)This was the public function called from the click detector, but now that we've added DelayMEasurementParams to the main call, this is to be called privately only once the filtering and envelope manipulations specified in the params have all been dealt with.
- Parameters:
f1
- complex spectrum on channel 1f2
- complex spectrum on channel 2fftLength
- FFT length to use (data will be packed or truncated as necessary)maxDelay
- Maximum feasible delay between channels.binRnage
- - the bin range to use.- Returns:
- time delay in samples.
-
getCorrelationValue
public double getCorrelationValue()Get the value of the last correlation calculated by any of the functions in the class.- Returns:
- the correlationValue
-
defaultTimingError
public static double defaultTimingError(float sampleRate) Generate a default timing error which is 1/sqrt(12) times the sample interval- Parameters:
sampleRate
- sample rate- Returns:
- typical timing error
-
parabolicCorrection
public double parabolicCorrection(double y1, double y2, double y3) Calculate a parabolic fit correction based on three bin heights
The answer should always be between -0.5 and +0.5- Parameters:
y1
- first biny2
- second biny3
- third bin- Returns:
- correction = 0.5*(y3-y1)/(2*y2-y1-y3);
-
parabolicHeight
public double parabolicHeight(double y1, double y2, double y3) Calculate a parabolic maximum height based on three bin heights- Parameters:
y1
- first biny2
- second biny3
- third bin- Returns:
- height of parabola through those points.
-
parabolicHeight
public double parabolicHeight(double time, double[] correlationFunction) - Parameters:
correlationFunction
- correlation function.t
- time to measure height at.- Returns:
- height of parabola through those points.
-
getCorrelation
public double[] getCorrelation(double[] wave1, double[] wave2, boolean normalise) Get the correlation function of waves 1 and 2 and normalise if requested.- Parameters:
wave1
- - the first wave.wave2
- - the second wave.normalise
- - true to normalise.- Returns:
- the correlation function.
-
getInterpolatedPeak
Get the peak position and the peak height from a complex array returned by the ifft function.- Parameters:
complexData
- Complex data from the ifft during cross correlation calculationscale
- Scaling factor (sqrt(sum^2 of each channel))maxDelay
- max searchable delay- Returns:
- two element array giving the peak pos and it's height.
-
getInterpolatedPeak
public double[] getInterpolatedPeak(double[] invFFTData, double scale, double maxDelay) -
getInterpolatedPeak
Get the peak position and the peak height from a complex array returned by the ifft function.- Parameters:
complexData
- Complex data from the ifft during cross correlation calculationscale
- Scaling factor (sqrt(sum^2 of each channel))maxDelay
- max searchable delay- Returns:
- two element array giving the peak pos and it's height.
-
getInterpolatedPeak
public double[] getInterpolatedPeak(double[] corrFunction) Find the peak of a correlation function, interpolating about each peak using a wee parabola.Note that first and last bins are not used in the search.
- Parameters:
corrFunction
- correlation function- Returns:
- peak position and peak height.
-
getInterpolatedMaxima
public double[][] getInterpolatedMaxima(double[] corrFunction) Get interpolated maxima around every peak in the correlation function.- Parameters:
corrFunction
- correlation function.- Returns:
- 2d array of times and interpolated values.
-
getMaxDelays
public double[] getMaxDelays(float sampleRate, int groupHydrophones, long currentMillis) Get the maximum permissible delays in samples for the set of hydrophones. These numbers can be used to limit the range of correlation searches to valid values.- Parameters:
sampleRate
- sample rate of the datagroupHydrophones
- bitmap of used hydrophones.- Returns:
- array of maximum time delays in samples.
-
getFastFFT
- Returns:
- the fastFFT
-
getLastCorrelationData
public double[] getLastCorrelationData()- Returns:
- the lastCorrelationData
-
setLastCorrelationData
public void setLastCorrelationData(double[] lastCorrelationData) - Parameters:
lastCorrelationData
- the lastCorrelationData to set
-
getLastPeak
public double[] getLastPeak()- Returns:
- the lastPeak
-
setLastPeak
public void setLastPeak(double[] lastPeak) - Parameters:
lastPeak
- the lastPeak to set
-