Package PamguardMVC
Class RawDataTransforms
java.lang.Object
PamguardMVC.RawDataTransforms
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 Summary
ConstructorDescriptionRawDataTransforms
(PamDataUnit rawDataHolder) Create raw data transforms using the rawDatAholder for synchronisation.RawDataTransforms
(PamDataUnit rawDataHolder, Object synchObject) Create a RawDataTransforms with a specified synchronisation object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Free eup some memory by deleting the filtered wave data, power spectra and analytic waveform.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.double[][]
getCepstrum
(int ceplen) Get the cepstrum for all channels.double[]
getCepstrum
(int channel, int cepLength) Calculate the cepstrum for a clip channel.getComplexSpectrum
(int channel, int fftLength) Returns the complex spectrum for a given channel using a set FFT lengthstatic ComplexArray
getComplexSpectrumHann
(double[] waveData, int fftLength) Get the complex spectrum of a waveform.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 firstGet the current complex spectrum.double[][]
Get the current power spectra.int
Get the spectrum lengthgetFFTFilter
(FFTFilterParams fftFilterParams) Get an FFT filter, mainly used to generate filtered waveforms within click detections.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.double[][]
getPowerSpectrum
(int fftLength) Get the power spectrum.double[]
getPowerSpectrum
(int channel, int fftLength) Returns the power spectrum for a given channel (square of magnitude of complex spectrum)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.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.float
Get the sample rate to use for transforms.int
Get the shortest FFT length for the number of samples.short[]
getShortWaveData
(int channel) Get the wave data for the given channel in int16 format.getSpectrogram
(int fftSize, int fftHop) Get a spectrogram image of the wave clip.getSpectrogram
(int fftSize, int fftHop, int windowType) Get a spectrogram image of the wave clip.double[]
getTotalPowerSpectrum
(int fftLength) Returns the sum of the power spectra for all channelsdouble[]
getWaveData
(int channel) Get the wave data for the given channel.void
setComplexSpectrum
(ComplexArray[] complexSpectrum) Set the current complex spectrum.
-
Constructor Details
-
RawDataTransforms
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
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 numberminBin
- - the minimum binmaxBin
- - 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 numberfftLength
-- 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
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 calculatefftLength
- - the FFT length to use.- Returns:
- the complex spectrum - the comnplex spectrum of the wave data from the specified channel.
-
getComplexSpectrumHann
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
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 samplesfftHop
- - the FFT hop in samples- Returns:
- a spectrogram clip (dB/Hz ).
-
getSpectrogram
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 samplesfftHop
- - the FFT hop in sampleswindowType
- - 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
- 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)
-
getComplexSpectrum
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
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 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
Get the analytic waveform for all channels if filter params = null, then return normal analytic waveform- Parameters:
fftFilterParams
-- Returns:
- analystic waveforms
-
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
-
getFFTFilter
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
Get the current complex spectrum. Can be null if it has not been calculated in other functions.- Returns:
- the current complex spectrum.
-
setComplexSpectrum
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.
-