Package clickDetector
Class ClickDetection
- All Implemented Interfaces:
 Comparable<PamDataUnit>,PamDetection,AcousticDataUnit,FFTDataHolder,RawDataHolder
public class ClickDetection
extends PamDataUnit<PamDataUnit,PamDataUnit>
implements PamDetection, RawDataHolder, FFTDataHolder 
Class for Click Detector clicks.
- Author:
 - Doug Gillespie
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intprotected longprotected static CPUMonitorprotected static CPUMonitorFields inherited from class PamguardMVC.PamDataUnit
absBlockIndex, localisation - 
Constructor Summary
ConstructorsConstructorDescriptionClickDetection(int channelBitmap, long startSample, long duration, ClickDetector clickDetector, ClickDetector.ChannelGroupDetector channelGroupDetector, int triggerList) ClickDetection(ClickDetector clickDetector)  - 
Method Summary
Modifier and TypeMethodDescriptionstatic double[]applyHanningWindow(double[] data) apply a Hanning window to the passed dataset.booleancalculateAmplitude(int channel) Calculate the peak waveform amplitude making the correction of rotating the wave so it's two ends are at zero.doubleclickLength(double percent) Calculates the length of a click in seconds averaged over all channelsdoubleclickLength(int channel, double percent) Calculates the length of a click in seconds for a particular channelvoidFree up as much click memory as possible.voidfreeData()Free as much data as possible.voidFree up the most memory - basically clear everything except for the compressed wave data held in field compressedWaveData.doublegetAmplitude(int channel) doubleGet the calculated amplitude, in dB.double[]getAnalyticWaveform(int iChan) Get the analytic waveform for a given channeldouble[]getAnalyticWaveform(int iChan, boolean filtered, FFTFilterParams fftFilterParams) Get filtered or unfiltered analytic waveform.doublegetAngle()Returns the angle in degrees for compatibilty with older version of click detector This is really bad to use for anything apart from two element arrays and it would be sensible to remove the function entirely.double[]getCepstrum(int channel, int cepLength) Calculate the cepstrum for a click channel.intlongGet a spectrogram image of the click.getClickSpectrogram(int fftSize, int fftHop) Get a spectrogram image of the click.getClickSpectrogram(int fftSize, int fftHop, int windowType) Get a spectrogram image of the click.bytegetComplexSpectrum(int channel) Returns the complex spectrum for a given channel using the shortest possible FFT lengthgetComplexSpectrum(int channel, int fftLength) Returns the complex spectrum for a given channel using a set FFT lengthgetComplexSpectrumHann(int channel, int fftLength) Returns the complex spectrum for a given channel using a set FFT length as getComplexSpectrum, but applies a Hanning window to the raw data firstbyte[][]Get compressed waveform data in int8 format, scaled so that the maximum range >-127 to +127 is utilised.intGet the raw data transforms class.bytedouble[]return a list of delaysInSamples.intGet thd event id for a click.getFFTDataUnits(Integer fftLength) Return a list of FFT data units from the data unit.double[][]getFilteredAnalyticWaveform(FFTFilterParams fftFilterParams) Get the analytic waveform for all channels if filter params = null, then return normal analytic waveformdouble[]getFilteredAnalyticWaveform(FFTFilterParams fftFilterParams, int iChan) Get a filtered version of the analytic waveform.double[][]getFilteredWaveData(FFTFilterParams filterParams) Get filtered waveform data for all channels.double[]getFilteredWaveData(FFTFilterParams filterParams, int channelIndex) Get filtered waveform data for a single channel.doublegetICI()double[]getMagnitude(int channel, int fftLength, boolean hann) Returns the magnitude of the complex spectrum for a given channel.doubledoublegetMeanFrequency(double[] searchRange) intgetNChan()intdouble[]getPowerSpectrum(int channel) Get the power spectrum of the entire click.double[]getPowerSpectrum(int channel, boolean recalc) Get the power spectrum of the entire click.double[]getPowerSpectrum(int channel, int fftLength) Returns the power spectrum for a given channel (square of magnitude of complex spectrum)double[]getRotationCorrection(int channel) Get a correction based on the slope of the waveform which can be used to remove large DC / LF offsets in the waveform.intdoubledouble[]getTotalPowerSpectrum(int fftLength) Returns the sum of the power spectra for all channelsintGet the trigger bitmap, i.e.doubledouble[][]Get arrays of raw audio data, one per channel.double[][]getWaveData(boolean filtered, FFTFilterParams fftFilterParams) convenience method to get filtered or unfiltered data for a single channel.double[]getWaveData(int channelIndex) Get raw waveform data for a given click channel index.double[]getWaveData(int channelIndex, boolean filtered, FFTFilterParams fftFilterParams) convenience method to get filtered or unfiltered data for a single channel.intGet the length of the wave in samples.booleanFind out whether there are complex spectrum data - and if there are, data may get cleaned up.doubleinBandEnergy(double[] freqs) Calculates the total energy within a particular frequency bandbooleanisEcho()booleandoublepeakFrequency(double[] searchRange) doublepeakFrequencyWidth(double peakFrequency, double percent) double[]peakFrequencyWidth(double peakFrequency, int dBDrop) double[]peakFrequencyWidthChan(double peakFrequency, int dBDrop, int channel, boolean hann) Returns the frequency width of a drop in dBDrop decibels to either side of the peak frequency.voidsetAmplitude(int channel, double amplitude) Set the amplitude for a given channelvoidsetChannelBitmap(int channelBitmap) Set the channel bitmap (software channels)protected voidsetChannelGroupDetector(ClickDetector.ChannelGroupDetector channelGroupDetector) voidsetClickDetector(ClickDetector clickDetector) voidsetClickFlags(int clickFlags) voidsetClickLocalisation(ClickLocalisation clickLocalisation) voidsetClickType(byte clickType) voidvoidsetCompressedData(byte[][] compressedWaveData, double waveAmplitude) Set the compressed wave data (used when reading back from file).voidsetDataType(byte dataType) voidsetDelayInSamples(int iDelay, double delay) Set the time of arrival delay in samples.voidsetDelaysInSamples(double[] delays) voidsetEcho(boolean isEcho) voidsetICI(double iCI) voidsetOfflineEventID(int offlineEventID) voidsetTempICI(double tempICI) voidsetTracked(boolean tracked) voidsetWaveData(double[][] waveData) voidMethods inherited from class PamguardMVC.PamDataUnit
addDataAnnotation, addSuperDetection, amplifyMeasuredAmplitudeByDB, amplifyMeasuredAmplitudeByLinear, clearOandAngles, clearUpdateCount, compareTo, findDataAnnotation, findDataAnnotation, getAbsBlockIndex, getAnnotationsSummaryString, getBasicData, getCalculatedAmlitudeDB, getChannelBitmap, getColourIndex, getDataAnnotation, getDatabaseIndex, getDatabaseUpdateOf, getDataUnitFileInformation, getDataUnitPopupMenu, getDurationInMilliseconds, getEndTimeInMilliseconds, getFrequency, getFrequencyOverlap, getGpsPosition, getHydrophoneBitmap, getHydrophoneHeading, getLastChangeTime, getLastSample, getLastUpdateTime, getLocalisation, getMeasuredAmplitude, getMeasuredAmplitudeType, getNoiseBackground, getNumDataAnnotations, getOriginLatLong, getParentDataBlock, getSampleDuration, getSampleDurationAsInt, getSeconds, getSequenceBitmap, getSequenceBitmapObject, getSignalExcess, getSignalSPL, getSnapshotGeometry, getStartSample, getSummaryString, getSuperDetection, getSuperDetection, getSuperDetection, getSuperDetection, getSuperDetection, getSuperDetectionsCount, getSuperDetectionSyncronisation, getSuperId, getTimeDelaysSeconds, getTimeMilliseconds, getTimeNanoseconds, getTimeOverlap, getUID, getUpdateCount, isEmbryonic, isForceAmpRecalc, linAmplitudeToDB, removeDataAnnotation, removeDataAnnotation, removeSuperDetection, setAbsBlockIndex, setCalculatedAmlitudeDB, setDatabaseIndex, setDatabaseUpdateOf, setDataUnitFileInformation, setDurationInMilliseconds, setEmbryonic, setForceAmpRecalc, setFrequency, setInfo, setLastUpdateTime, setLocalisation, setMeasuredAmpAndType, setMeasuredAmplitude, setMeasuredAmplitudeType, setNoiseBackground, setParentDataBlock, setSampleDuration, setSequenceBitmap, setSignalExcess, setSignalSPL, setSnapshotGeometry, setStartSample, setTimeDelaysSeconds, setTimeMilliseconds, setUID, setUniqueSuperDetection, sortOutputMaps, updateDataUnit 
- 
Field Details
- 
CLICK_CLICK
public static final int CLICK_CLICK- See Also:
 
 - 
CLICK_NOISEWAVE
public static final int CLICK_NOISEWAVE- See Also:
 
 - 
CLICK_FLAG_ECHO
public static final int CLICK_FLAG_ECHO- See Also:
 
 - 
filePos
protected long filePos - 
originMon
 - 
headingMon
 
 - 
 - 
Constructor Details
- 
ClickDetection
public ClickDetection(int channelBitmap, long startSample, long duration, ClickDetector clickDetector, ClickDetector.ChannelGroupDetector channelGroupDetector, int triggerList)  - 
ClickDetection
 
 - 
 - 
Method Details
- 
getShortestFFTLength
public int getShortestFFTLength() - 
isTracked
public boolean isTracked() - 
setTracked
public void setTracked(boolean tracked)  - 
getEventId
public int getEventId()Get thd event id for a click. no longer store EventId within the click, but get it from the super detection.- Returns:
 - Event id (same as database index of an event).
 
 - 
isEcho
public boolean isEcho()- Returns:
 - true if the echo flag is set.
 
 - 
setEcho
public void setEcho(boolean isEcho) - Parameters:
 isEcho- set the click echo flag.
 - 
getComplexSpectrum
Returns the complex spectrum for a given channel using the shortest possible FFT length- Parameters:
 channel-- Returns:
 - The complex spectrum
 
 - 
setComplexSpectrum
public void setComplexSpectrum() - 
getComplexSpectrum
Returns the complex spectrum for a given channel using a set FFT length- Parameters:
 channel-fftLength-- Returns:
 - the complex spectrum
 
 - 
getComplexSpectrumHann
Returns the complex spectrum for a given channel using a set FFT length as getComplexSpectrum, but applies a Hanning window to the raw data first- Parameters:
 channel-fftLength-- Returns:
 - the complex spectrum
 
 - 
getFFTDataUnits
Description copied from interface:FFTDataHolderReturn a list of FFT data units from the data unit.- Specified by:
 getFFTDataUnitsin interfaceFFTDataHolder- Parameters:
 fftLength- Length of FFT to use. If this is null, a default from the data source will be used, otherwise the source should recalculate if possible. If it's not possible to recalculate, then return what's available and the calling process must decide whether it can use the data or not.- Returns:
 - list of FFT units, interleaved by channel.
 
 - 
hasComplexSpectrum
public boolean hasComplexSpectrum()Find out whether there are complex spectrum data - and if there are, data may get cleaned up.- Returns:
 - true if complex spec data exist.
 
 - 
getCurrentSpectrumLength
public int getCurrentSpectrumLength() - 
getPowerSpectrum
public double[] getPowerSpectrum(int channel) Get the power spectrum of the entire click.- Parameters:
 channel- channel number- Returns:
 - power spectrum
 
 - 
getPowerSpectrum
public double[] getPowerSpectrum(int channel, boolean recalc) Get the power spectrum of the entire click. Note, if recalc is false then this function can return null.- Parameters:
 channel- - channel numbernoRecalc- - true to calculate power spectrum if it's null or fft length is not the same.- Returns:
 - the click power spectrum.
 
 - 
getCepstrum
public double[] getCepstrum(int channel, int cepLength) Calculate the cepstrum for a click channel.- Parameters:
 channel- cannelcepLength- length of cepstrum. If this is 0, then the Cepstrum will be the next binary int up from the click length.- Returns:
 - cepstrum. (ifft of the log of the power spectrum)
 
 - 
getPowerSpectrum
public double[] getPowerSpectrum(int channel, int fftLength) Returns the power spectrum for a given channel (square of magnitude of complex spectrum)- Parameters:
 channel- channel numberfftLength-- Returns:
 - Power spectrum
 
 - 
getMagnitude
public double[] getMagnitude(int channel, int fftLength, boolean hann) Returns the magnitude of the complex spectrum for a given channel. Has the option to apply a hanning window to the raw data before computing the fft- Parameters:
 channel-fftLength-hann- TRUE=apply hanning window; FALSE=do not apply hanning window- Returns:
 
 - 
getTotalPowerSpectrum
public double[] getTotalPowerSpectrum(int fftLength) Returns the sum of the power spectra for all channels- Parameters:
 fftLength-- Returns:
 - Sum of power spectra
 
 - 
getAnalyticWaveform
public double[] getAnalyticWaveform(int iChan) Get the analytic waveform for a given channel- Parameters:
 iChan- channel index- Returns:
 - analytic waveform
 
 - 
getAnalyticWaveform
Get filtered or unfiltered analytic waveform. Easy access method for click detector modules which can let this function work out what they want rather than having to write their own.- Parameters:
 iChan- channel numberfiltered- true if you want data to be filteredfftFilterParams- fft filter parameters.- Returns:
 - analystic waveform.
 
 - 
getFilteredAnalyticWaveform
Get a filtered version of the analytic waveform. In principle, this could be made more efficient since the calc is done partly in frequency domain - so could save a couple of fft's back and forth.- Parameters:
 fftFilterParams- FFT filter parameters.iChan- channel number- Returns:
 - envelope of the filtered data.
 
 - 
getFilteredAnalyticWaveform
Get the analytic waveform for all channels if filter params = null, then return normal analytic waveform- Parameters:
 fftFilterParams-- Returns:
 - analystic waveforms
 
 - 
inBandEnergy
public double inBandEnergy(double[] freqs) Calculates the total energy within a particular frequency band- Parameters:
 freqs-- Returns:
 - In Band Energy
 - See Also:
 
 - 
clickLength
public double clickLength(double percent) Calculates the length of a click in seconds averaged over all channels- Parameters:
 percent- Fraction of total click energy to use in the calculation- Returns:
 - click length in seconds
 - See Also:
 
 - 
clickLength
public double clickLength(int channel, double percent) Calculates the length of a click in seconds for a particular channel- Parameters:
 channel-percent- Fraction of total click energy to use in the calculation- Returns:
 - Click Length (seconds)
 - See Also:
 
 - 
peakFrequency
public double peakFrequency(double[] searchRange)  - 
peakFrequencyWidth
public double peakFrequencyWidth(double peakFrequency, double percent)  - 
peakFrequencyWidth
public double[] peakFrequencyWidth(double peakFrequency, int dBDrop)  - 
peakFrequencyWidthChan
public double[] peakFrequencyWidthChan(double peakFrequency, int dBDrop, int channel, boolean hann) Returns the frequency width of a drop in dBDrop decibels to either side of the peak frequency. Note that this differs from the method peakFrequencyWidth because it operates only on a single channel, and it uses the magnitude (sqrt(PowerSpectrum)) instead of the PowerSpectrum.- Parameters:
 peakFrequency- The peak frequency in HzdBDrop- The drop in magnitude (in dB) to either side of the peak frequencychannel- The channel to run the calculations onhann- TRUE=apply hanning window, FALSE=do not apply hanning window- Returns:
 - a 3-position array with the frequency bin in the first index, the lower frequency in the second index, and the higher frequency in the third index
 
 - 
getMeanFrequency
public double getMeanFrequency(double[] searchRange)  - 
getFilteredWaveData
Get filtered waveform data for a single channel.Data are filtered in the frequency domain using an FFT / Inverse FFT.
- Parameters:
 filterParams- filter parameterschannelIndex- channel index- Returns:
 - filtered waveform data
 
 - 
getFilteredWaveData
Get filtered waveform data for all channels.Data are filtered in the frequency domain using an FFT / Inverse FFT.
- Parameters:
 filterParams- filter parameters- Returns:
 - array of filtered data
 
 - 
getWaveData
convenience method to get filtered or unfiltered data for a single channel.- Parameters:
 filtered- flag saying you want it filteredfftFilterParams- filter parameters.- Returns:
 - data filtered or otherwise.
 
 - 
getWaveData
convenience method to get filtered or unfiltered data for a single channel.- Parameters:
 channelIndex- channel indexfiltered- flag saying you want it filteredfftFilterParams- filter parameters.- Returns:
 - data filtered or otherwise.
 
 - 
getWaveData
public double[] getWaveData(int channelIndex) Get raw waveform data for a given click channel index.- Parameters:
 channelIndex- channel index- Returns:
 - waveform data
 
 - 
getWaveData
public double[][] getWaveData()Description copied from interface:RawDataHolderGet arrays of raw audio data, one per channel. Assume that the array matches getChannelMap() !- Specified by:
 getWaveDatain interfaceRawDataHolder- Returns:
 - waveform data for all channels. Convert from compressed (int16) data if necessary.
 
 - 
setWaveData
public void setWaveData(double[][] waveData)  - 
getCompressedWaveData
public byte[][] getCompressedWaveData()Get compressed waveform data in int8 format, scaled so that the maximum range >-127 to +127 is utilised.- Returns:
 - arrays of waveform data.
 
 - 
setCompressedData
public void setCompressedData(byte[][] compressedWaveData, double waveAmplitude) Set the compressed wave data (used when reading back from file).- Parameters:
 compressedWaveData-waveAmplitude-
 - 
getWaveAmplitude
public double getWaveAmplitude()- Returns:
 - the waveAmplitude - the double precision amplitude of the orignal wave data.
 
 - 
getWaveLength
public int getWaveLength()Get the length of the wave in samples.- Returns:
 - the length of the wave data in samples.
 
 - 
freeData
public void freeData()Description copied from class:PamDataUnitFree as much data as possible. this gets called when processing offline data and during datagramming to free any data that's not needed in memory such as derived spectral data (e.g. from a click waveform) which can be recalculated if necessary.- Overrides:
 freeDatain classPamDataUnit<PamDataUnit,PamDataUnit> 
 - 
freeMaxMemory
public void freeMaxMemory()Free up the most memory - basically clear everything except for the compressed wave data held in field compressedWaveData. That we need, but everything else can be recalculated if necessary. - 
freeClickMemory
public void freeClickMemory()Free up as much click memory as possible.Ensures that waveform data are retained in a compressed (int8) format so that all other data can be reconstructed if necessary.
 - 
setDelayInSamples
public void setDelayInSamples(int iDelay, double delay) Set the time of arrival delay in samples.- Parameters:
 delay- delay in samples
 - 
setDelaysInSamples
public void setDelaysInSamples(double[] delays)  - 
getDelaysInSamples
public double[] getDelaysInSamples()return a list of delaysInSamples.- Returns:
 
 - 
calculateAmplitude
public boolean calculateAmplitude(int channel) Calculate the peak waveform amplitude making the correction of rotating the wave so it's two ends are at zero.- Parameters:
 channel-- Returns:
 - true if calculation completed OK.
 
 - 
getRotationCorrection
public double[] getRotationCorrection(int channel) Get a correction based on the slope of the waveform which can be used to remove large DC / LF offsets in the waveform.- Parameters:
 channel- - the channel to correct- Returns:
 - the corrected waveform
 
 - 
setAmplitude
public void setAmplitude(int channel, double amplitude) Set the amplitude for a given channel- Parameters:
 channel- channel numberamplitude- amplitude
 - 
getAmplitude
public double getAmplitude(int channel)  - 
getAngle
public double getAngle()Returns the angle in degrees for compatibilty with older version of click detector This is really bad to use for anything apart from two element arrays and it would be sensible to remove the function entirely.- Returns:
 - angle of the click detection in degrees
 
 - 
getMeanAmplitude
public double getMeanAmplitude() - 
getClickLocalisation
 - 
setClickLocalisation
 - 
getNChan
public int getNChan() - 
setChannelBitmap
public void setChannelBitmap(int channelBitmap) Description copied from class:PamDataUnitSet the channel bitmap (software channels)- Overrides:
 setChannelBitmapin classPamDataUnit<PamDataUnit,PamDataUnit> - Parameters:
 channelBitmap-
 - 
setClickType
public void setClickType(byte clickType) - Parameters:
 clickType- the clickType (click species) to set
 - 
getClickType
public byte getClickType()- Returns:
 - the clickType (click species)
 
 - 
getDataType
public byte getDataType()- Returns:
 - the type of data - click, noise, etc.
 
 - 
setDataType
public void setDataType(byte dataType) - Parameters:
 dataType- the type of data - click, noise, etc.
 - 
setClickDetector
- Parameters:
 clickDetector- the clickDetector to set
 - 
getClickDetector
- Returns:
 - the clickDetector
 
 - 
getICI
public double getICI()- Returns:
 - the iCI
 
 - 
setICI
public void setICI(double iCI) - Parameters:
 iCI- the iCI to set
 - 
setChannelGroupDetector
 - 
getChannelGroupDetector
 - 
setClickFlags
public void setClickFlags(int clickFlags) - Parameters:
 clickFlags- the clickFlags to set
 - 
getClickFlags
public int getClickFlags()- Returns:
 - the clickFlags
 
 - 
setTempICI
public void setTempICI(double tempICI) - Parameters:
 tempICI- the tempICI to set
 - 
getTempICI
public double getTempICI()- Returns:
 - the tempICI
 
 - 
getZeroCrossingStats
- Returns:
 - the ZeroCrossingStats array (array size=number of channels)
 
 - 
setZeroCrossingStats
- Parameters:
 zcs- save the ZeroCrossingStats array (array size=number of channels)
 - 
applyHanningWindow
public static double[] applyHanningWindow(double[] data) apply a Hanning window to the passed dataset. Note that the size of the window is the length of te full dataset that is passed.- Parameters:
 data- a double array- Returns:
 - the windowed data array
 
 - 
getOfflineEventID
public int getOfflineEventID()- Returns:
 - the offlineEventID
 
 - 
setOfflineEventID
public void setOfflineEventID(int offlineEventID) - Parameters:
 offlineEventID- the offlineEventID to set
 - 
getClickNumber
public long getClickNumber()- Returns:
 - the clickNumber
 
 - 
getTriggerList
public int getTriggerList()Get the trigger bitmap, i.e. which channels triggers- Returns:
 - the trigger map.
 
 - 
getAmplitudeDB
public double getAmplitudeDB()Description copied from class:PamDataUnitGet the calculated amplitude, in dB. If it hasn't been calculated yet, do that first and then return the value- Overrides:
 getAmplitudeDBin classPamDataUnit<PamDataUnit,PamDataUnit> - Returns:
 - the amplitude in dB with reference unit dictated by the hydrophone/microphone sensitivity value units.
 
 - 
getClickSpectrogram
Get a spectrogram image of the click. The clip is null until called. It is recalculated if the FFT length and/or hop size are different.- Parameters:
 fftSize- - the FFT size in samplesfftHop- - the FFT hop in sampleswindowType- - the window type @see WindowFunction.getWindowFunc(windowFunction, fftLength);- Returns:
 - a spectrogram clip (dB/Hz ).
 
 - 
getClickSpectrogram
Get a spectrogram image of the click. The clip is null until called. It is recalculated if the FFT length and/or hop size are different.- Parameters:
 fftSize- - the FFT size in samplesfftHop- - the FFT hop in samples- Returns:
 - a spectrogram clip (dB/Hz ).
 
 - 
getClickSpectrogram
Get a spectrogram image of the click. The clip is null until called. It is recalculated if the FFT length and/or hop size are different. The the spectrogram is null then it is calculated with a default FFT length of 512 and FFT Hop of 256- Returns:
 - a spectrogram clip (dB/Hz ).
 
 - 
calcSnapshotGeometry
- Overrides:
 calcSnapshotGeometryin classPamDataUnit<PamDataUnit,PamDataUnit> 
 - 
getDataTransforms
Description copied from interface:RawDataHolderGet the raw data transforms class. This handles standard data transforms that are often used in raw data units, e.g. calculating the spectrum, filtering waveforms, getting data as an int16 (short) array, etc.- Specified by:
 getDataTransformsin interfaceRawDataHolder- Returns:
 - the data transforms object.
 
 
 -