Package PamguardMVC

Class RawDataTransforms

java.lang.Object
PamguardMVC.RawDataTransforms

public class RawDataTransforms extends Object
Holds transforms for raw wave data such as spectrum, spectrogram, cepstrum etc. Can be used for any data unit that implements RawDataHolder.

This provides similar functionality to the many functions in ClickDetection without the need for repeating code.

Author:
Jamie Macaulay
  • Constructor Details

    • RawDataTransforms

      public RawDataTransforms(PamDataUnit rawDataHolder, Object synchObject)
      Create a RawDataTransforms with a specified synchronisation object. This is mostly the data unit, but in some circumstances may need to be a different object to avoid thread lock.
      Parameters:
      rawDataHolder -
      synchObject -
    • RawDataTransforms

      public RawDataTransforms(PamDataUnit rawDataHolder)
      Create raw data transforms using the rawDatAholder for synchronisation.
      Parameters:
      rawDataHolder -
  • Method Details

    • getPowerSpectrum

      public double[][] getPowerSpectrum(int fftLength)
      Get the power spectrum.
      Returns:
      the power spectrum.
    • getShortestFFTLength

      public int getShortestFFTLength()
      Get the shortest FFT length for the number of samples. The is the
      Returns:
      the shortest FFT length.
    • getPowerSpectrum

      public double[] getPowerSpectrum(int channel, int minBin, int maxBin, int fftLength)
      Returns the power spectrum for a given channel (square of magnitude of complex spectrum) between a minimum and maximum sample bin. Note that this is not saved and so is recalculated every time this function is called.
      Parameters:
      channel - channel number
      minBin - - the minimum bin
      maxBin - - the maximum bin.
      fftLength -
      Returns:
      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
    • getTotalPowerSpectrum

      public double[] getTotalPowerSpectrum(int fftLength)
      Returns the sum of the power spectra for all channels
      Parameters:
      fftLength -
      Returns:
      Sum of power spectra
    • 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 - - the channel to calculate
      fftLength - - the FFT length to use.
      Returns:
      the complex spectrum - the comnplex spectrum of the wave data from the specified channel.
    • getComplexSpectrumHann

      public static ComplexArray getComplexSpectrumHann(double[] waveData, int fftLength)
      Get the complex spectrum of a waveform.
      Parameters:
      waveData - - the wave data.
      fftLength -
      Returns:
    • getCurrentSpectrumLength

      public int getCurrentSpectrumLength()
      Get the spectrum length
      Returns:
      the spectrogram length.
    • getSpectrogram

      public ClipSpectrogram getSpectrogram(int fftSize, int fftHop)
      Get a spectrogram image of the wave clip. 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 ).
    • getSpectrogram

      public ClipSpectrogram getSpectrogram(int fftSize, int fftHop, int windowType)
      Get a spectrogram image of the wave clip. 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 windowType @see WindowFunction.getWindowFunc(fftParams.windowFunction, fftParams.fftHop);
      Returns:
      a spectrogram clip (dB/Hz ).
    • getCepstrum

      public double[][] getCepstrum(int ceplen)
      Get the cepstrum for all channels.
      Parameters:
      ceplen - - the cepstrum length.
      Returns:
      the cepstrum for all channels.
    • getCepstrum

      public double[] getCepstrum(int channel, int cepLength)
      Calculate the cepstrum for a clip 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)
    • 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
    • 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 freqeucny 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
    • 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
    • getFFTFilter

      public FFTFilter getFFTFilter(FFTFilterParams fftFilterParams)
      Get an FFT filter, mainly used to generate filtered waveforms within click detections.
      Parameters:
      fftFilterParams -
      Returns:
      FFT filter object.
    • getSampleRate

      public float getSampleRate()
      Get the sample rate to use for transforms.
      Returns:
      the sample rate.
    • 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
    • getWaveData

      public double[] getWaveData(int channel)
      Get the wave data for the given channel.
      Parameters:
      channel - channel index
      Returns:
      wave data
    • getShortWaveData

      public short[] getShortWaveData(int channel)
      Get the wave data for the given channel in int16 format.
      Parameters:
      channel - channel index
      Returns:
      int16 data array.
    • getCurrentPowerSpectra

      public double[][] getCurrentPowerSpectra()
      Get the current power spectra. Can be null if it has not been calculated using getPowerSpectrum(....).
      Returns:
      the current power spectra
    • getCurrentComplexSpectra

      public ComplexArray[] getCurrentComplexSpectra()
      Get the current complex spectrum. Can be null if it has not been calculated in other functions.
      Returns:
      the current complex spectrum.
    • setComplexSpectrum

      public void setComplexSpectrum(ComplexArray[] complexSpectrum)
      Set the current complex spectrum. Can be null to free up memory
    • freeMemory

      public void freeMemory()
      Free eup some memory by deleting the filtered wave data, power spectra and analytic waveform.