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 Details

  • Constructor Details

  • 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

      public ComplexArray getComplexSpectrum(int channel)
      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

      public ComplexArray getComplexSpectrum(int channel, int fftLength)
      Returns the complex spectrum for a given channel using a set FFT length
      Parameters:
      channel -
      fftLength -
      Returns:
      the complex spectrum
    • getComplexSpectrumHann

      public ComplexArray getComplexSpectrumHann(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 first
      Parameters:
      channel -
      fftLength -
      Returns:
      the complex spectrum
    • getFFTDataUnits

      public List<FFTDataUnit> getFFTDataUnits(Integer fftLength)
      Description copied from interface: FFTDataHolder
      Return a list of FFT data units from the data unit.
      Specified by:
      getFFTDataUnits in interface FFTDataHolder
      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 number
      noRecalc - - 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 - cannel
      cepLength - 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 number
      fftLength -
      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

      public double[] getAnalyticWaveform(int iChan, boolean filtered, FFTFilterParams fftFilterParams)
      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 number
      filtered - true if you want data to be filtered
      fftFilterParams - fft filter parameters.
      Returns:
      analystic waveform.
    • getFilteredAnalyticWaveform

      public double[] getFilteredAnalyticWaveform(FFTFilterParams fftFilterParams, int iChan)
      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

      public double[][] getFilteredAnalyticWaveform(FFTFilterParams fftFilterParams)
      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 Hz
      dBDrop - The drop in magnitude (in dB) to either side of the peak frequency
      channel - The channel to run the calculations on
      hann - 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

      public double[] getFilteredWaveData(FFTFilterParams filterParams, int channelIndex)
      Get filtered waveform data for a single channel.

      Data are filtered in the frequency domain using an FFT / Inverse FFT.

      Parameters:
      filterParams - filter parameters
      channelIndex - channel index
      Returns:
      filtered waveform data
    • getFilteredWaveData

      public double[][] getFilteredWaveData(FFTFilterParams filterParams)
      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

      public double[][] getWaveData(boolean filtered, FFTFilterParams fftFilterParams)
      convenience method to get filtered or unfiltered data for a single channel.
      Parameters:
      filtered - flag saying you want it filtered
      fftFilterParams - filter parameters.
      Returns:
      data filtered or otherwise.
    • getWaveData

      public double[] getWaveData(int channelIndex, boolean filtered, FFTFilterParams fftFilterParams)
      convenience method to get filtered or unfiltered data for a single channel.
      Parameters:
      channelIndex - channel index
      filtered - flag saying you want it filtered
      fftFilterParams - 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: RawDataHolder
      Get arrays of raw audio data, one per channel. Assume that the array matches getChannelMap() !
      Specified by:
      getWaveData in interface RawDataHolder
      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: PamDataUnit
      Free 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:
      freeData in class PamDataUnit<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 number
      amplitude - 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

      public ClickLocalisation getClickLocalisation()
    • setClickLocalisation

      public void setClickLocalisation(ClickLocalisation clickLocalisation)
    • getNChan

      public int getNChan()
    • setChannelBitmap

      public void setChannelBitmap(int channelBitmap)
      Description copied from class: PamDataUnit
      Set the channel bitmap (software channels)
      Overrides:
      setChannelBitmap in class PamDataUnit<PamDataUnit,PamDataUnit>
    • 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

      public void setClickDetector(ClickDetector clickDetector)
      Parameters:
      clickDetector - the clickDetector to set
    • getClickDetector

      public ClickDetector getClickDetector()
      Returns:
      the clickDetector
    • getICI

      public double getICI()
      Returns:
      the iCI
    • setICI

      public void setICI(double iCI)
      Parameters:
      iCI - the iCI to set
    • getChannelGroupDetector

      public ClickDetector.ChannelGroupDetector 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

      public ZeroCrossingStats[] getZeroCrossingStats()
      Returns:
      the ZeroCrossingStats array (array size=number of channels)
    • setZeroCrossingStats

      public void setZeroCrossingStats(ZeroCrossingStats[] zcs)
      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: PamDataUnit
      Get the calculated amplitude, in dB. If it hasn't been calculated yet, do that first and then return the value
      Overrides:
      getAmplitudeDB in class PamDataUnit<PamDataUnit,PamDataUnit>
      Returns:
      the amplitude in dB with reference unit dictated by the hydrophone/microphone sensitivity value units.
    • getClickSpectrogram

      public ClickSpectrogram getClickSpectrogram(int fftSize, int fftHop, int windowType)
      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 samples
      fftHop - - the FFT hop in samples
      windowType - - the window type @see WindowFunction.getWindowFunc(windowFunction, fftLength);
      Returns:
      a spectrogram clip (dB/Hz ).
    • getClickSpectrogram

      public ClickSpectrogram getClickSpectrogram(int fftSize, int fftHop)
      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 samples
      fftHop - - the FFT hop in samples
      Returns:
      a spectrogram clip (dB/Hz ).
    • getClickSpectrogram

      public ClickSpectrogram 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

      public SnapshotGeometry calcSnapshotGeometry()
      Overrides:
      calcSnapshotGeometry in class PamDataUnit<PamDataUnit,PamDataUnit>
    • getDataTransforms

      public RawDataTransforms getDataTransforms()
      Description copied from interface: RawDataHolder
      Get 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:
      getDataTransforms in interface RawDataHolder
      Returns:
      the data transforms object.