Class SpectrogramTools
Inherited Members
Namespace: AudioAnalysisTools.StandardSpectrograms
Assembly: AudioAnalysisTools.dll
Syntax
public static class SpectrogramTools
Methods
| Improve this Doc View SourceAverageAnArrayOfDecibelValues(Double[])
Here is some test data for this method: array = new[] { 96.0, 100.0, 90.0, 97.0 }; The return value should = 96.988 dB First need to calculate the original value i.e. exponential or antilog. See also DataTools.AntiLogBase10(double value).
Declaration
public static double AverageAnArrayOfDecibelValues(double[] array)
Parameters
Type | Name | Description |
---|---|---|
Double[] | array | an array of decibel values. |
Returns
Type | Description |
---|---|
Double | a decibel value. |
CalculateAvgDecibelSpectrumFromDecibelSpectrogram(Double[,])
Use this method to average a decibel spectrogram.
Declaration
public static double[] CalculateAvgDecibelSpectrumFromDecibelSpectrogram(double[, ] spectrogram)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | spectrogram |
Returns
Type | Description |
---|---|
Double[] |
CalculateAvgSpectrumAndVarianceSpectrumFromAmplitudeSpectrogram(Double[,])
Returns AVERAGE POWER SPECTRUM (PSD) and VARIANCE OF POWER SPECTRUM. Have been passed the amplitude spectrum but square amplitude values to get power or energy.
This method assumes that the passed amplitude spectrogram has been prepared according to method of P.D. Welch. It is the standard method used now to calculate a PSD. Welch's method splits time series into overlapping segments and windows them. It is the windowing that makes Welche's method different. Normally overlap windows because windows decay at edges and therefore loss of info. Can now do FFT. Does not need to be FFT, but if so then window must be power of 2. Square the FFT coefficients >>>> energy. Then take average in each frquncy bin. Averaging reduces the variance. Welch's method is an improvement on the standard periodogram spectrum estimating method and on Bartlett's method, in that it reduces noise in the estimated power spectra in exchange for reducing the frequency resolution. The end result is an array of power measurements vs. frequency "bin".
As well as calculating the av power spectrum, this method also returns a variance spectrum and a spectrum of the Coeff of Variation = var/mean.
Declaration
public static Tuple<double[], double[], double[]> CalculateAvgSpectrumAndVarianceSpectrumFromAmplitudeSpectrogram(double[, ] amplitudeSpectrogram)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | amplitudeSpectrogram | this is an amplitude spectrum. Must square values to get power. |
Returns
Type | Description |
---|---|
Tuple<Double[], Double[], Double[]> | three spectral indices. |
CalculateAvgSpectrumFromEnergySpectrogram(Double[,])
NOTE: This method should not be used to average a decibel spectrogram. Use only for power spectrograms.
Declaration
public static double[] CalculateAvgSpectrumFromEnergySpectrogram(double[, ] spectrogram)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | spectrogram |
Returns
Type | Description |
---|---|
Double[] |
CalculateNdsi(Double[], Int32, Int32, Int32, Int32)
Calculates Stuart Gage's NDSI acoustic index from the Power Spectrum derived from a spectrogram. This method assumes P.D. Welch's method has been used to calculate the PSD. See method above: CalculateAvgSpectrumAndVarianceSpectrumFromAmplitudeSpectrogram().
Declaration
public static double CalculateNdsi(double[] psd, int samplerate, int lowBound, int midBound, int topBound)
Parameters
Type | Name | Description |
---|---|---|
Double[] | psd | power spectral density. |
Int32 | samplerate | original sample rate of the recording. Only used to get nyquist. |
Int32 | lowBound | low ndsi bound. |
Int32 | midBound | mid ndsi bound. |
Int32 | topBound | top ndsi bound. |
Returns
Type | Description |
---|---|
Double | ndsi. |
CreateFalseColourAmplitudeSpectrogram(Double[,], Double[,], Byte[,])
Another experimental method to colour render spectrograms, this time amplitude spectrograms.
Declaration
public static Image<Rgb24> CreateFalseColourAmplitudeSpectrogram(double[, ] spectrogramData, double[, ] nrSpectrogramData, byte[, ] hits)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | spectrogramData | |
Double[,] | nrSpectrogramData | |
Byte[,] | hits |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> |
CreateFalseColourDecibelSpectrogram(Double[,], Double[,], Byte[,])
TODO: This method needs a unit test. This is experimental method to explore colour rendering of standard spectrograms Used to convert a standard decibel spectrogram into a colour version using a colour rendering for three separate properties.
Declaration
public static Image<Rgb24> CreateFalseColourDecibelSpectrogram(double[, ] dbSpectrogramData, double[, ] nrSpectrogramData, byte[, ] hits)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | dbSpectrogramData | the raw decibel spectrogram data - assigned to red channel. |
Double[,] | nrSpectrogramData | the noise reduced decibel spectrogram data - assigned to green channel. |
Byte[,] | hits | assigned to ridge colours. |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> | coloured-rendered spectrogram as image. |
CreateFalseColourDecibelSpectrogramForZooming(Double[,], Double[,], Byte[,])
Creates a false-coloured spectrogram from spectral frame data. That is, uses normal spectrogram data but draws the raw data in red and then superimposes the noise reduced decibel data Also uses the spectral "hits" data for highlighting the spectrogram.
IMPORTANT WARNING!!!! THIS METHOD ASSUMES THAT BOTH SPECTRAL MATRICES HAVE BEEN NORMALISED IN [0,1].
Declaration
public static Image<Rgb24> CreateFalseColourDecibelSpectrogramForZooming(double[, ] dbSpectrogramNorm, double[, ] nrSpectrogramNorm, byte[, ] hits)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | dbSpectrogramNorm | the raw decibel spectrogram data - assigned to red channel. |
Double[,] | nrSpectrogramNorm | the noise reduced decibel spectrogram data - assigned to green channel. |
Byte[,] | hits | assigned to ridge colours. |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> | coloured-rendered spectrogram as image. |
DrawGridLinesOnImage(Image<Rgb24>, TimeSpan, TimeSpan, TimeSpan, FrequencyScale)
Only calls method to draw frequency lines but may in future want to add the times scale.
Declaration
public static void DrawGridLinesOnImage(Image<Rgb24> bmp, TimeSpan startOffset, TimeSpan fullDuration, TimeSpan xAxisTicInterval, FrequencyScale freqScale)
Parameters
Type | Name | Description |
---|---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> | bmp | the spectrogram image. |
TimeSpan | startOffset | start Offset. |
TimeSpan | fullDuration | full Duration. |
TimeSpan | xAxisTicInterval | xAxis Tic Interval. |
FrequencyScale | freqScale | freq Scale. |
DrawTimeLinesOnImage(Image<Rgb24>, TimeSpan, TimeSpan, TimeSpan)
Declaration
public static void DrawTimeLinesOnImage(Image<Rgb24> bmp, TimeSpan startOffset, TimeSpan fullDuration, TimeSpan xAxisTicInterval)
Parameters
Type | Name | Description |
---|---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> | bmp | |
TimeSpan | startOffset | |
TimeSpan | fullDuration | |
TimeSpan | xAxisTicInterval |
ExtractFreqSubband(Double[,], Int32, Int32, Boolean, Int32, Double)
Declaration
public static double[, ] ExtractFreqSubband(double[, ] m, int minHz, int maxHz, bool doMelscale, int binCount, double binWidth)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | m | |
Int32 | minHz | |
Int32 | maxHz | |
Boolean | doMelscale | |
Int32 | binCount | |
Double | binWidth |
Returns
Type | Description |
---|---|
Double[,] |
ExtractModalNoiseSubband(Double[], Int32, Int32, Boolean, Int32, Double)
Declaration
public static double[] ExtractModalNoiseSubband(double[] modalNoise, int minHz, int maxHz, bool doMelScale, int nyquist, double binWidth)
Parameters
Type | Name | Description |
---|---|---|
Double[] | modalNoise | |
Int32 | minHz | |
Int32 | maxHz | |
Boolean | doMelScale | |
Int32 | nyquist | |
Double | binWidth |
Returns
Type | Description |
---|---|
Double[] |
FilterbankIntegral(Double[], Int32, Int32, Int32)
Implements the integral for a single filter in a filterbank.
Declaration
public static double FilterbankIntegral(double[] spectrum, int lowIndex, int centreIndex, int highIndex)
Parameters
Type | Name | Description |
---|---|---|
Double[] | spectrum | THe input (linear) spectrum. |
Int32 | lowIndex | The lower bound of the filter. |
Int32 | centreIndex | Centre index of the filter. |
Int32 | highIndex | Upper bound of the filter. |
Returns
Type | Description |
---|---|
Double | The integral of the filter. |
GetImage(Double[,], Int32, Boolean)
Declaration
public static Image<Rgb24> GetImage(double[, ] data, int nyquist, bool DoMel)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | data | |
Int32 | nyquist | |
Boolean | DoMel |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> |
GetImageFullyAnnotated(Image<Rgb24>, String, Int32[,], TimeSpan)
Declaration
public static Image<Rgb24> GetImageFullyAnnotated(Image<Rgb24> image, string title, int[, ] gridLineLocations, TimeSpan duration)
Parameters
Type | Name | Description |
---|---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> | image | |
String | title | |
Int32[,] | gridLineLocations | |
TimeSpan | duration |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> |
GetSonogramPlusCharts(BaseSonogram, List<AcousticEvent>, List<Plot>, Double[,], String)
This method draws a spectrogram with other useful information attached.
Declaration
public static Image<Rgb24> GetSonogramPlusCharts(BaseSonogram sonogram, List<AcousticEvent> events, List<Plot> plots, double[, ] hits, string title)
Parameters
Type | Name | Description |
---|---|---|
BaseSonogram | sonogram | of BaseSonogram class. |
List<AcousticEvent> | events | a list of acoustic events. |
List<Plot> | plots | a list of plots relevant to the spectrogram scores. |
Double[,] | hits | not often used - can be null. |
String | title |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> |
GetSonogramPlusCharts(BaseSonogram, List<EventCommon>, List<Plot>, Double[,], String)
This method draws a spectrogram with other useful information attached.
Declaration
public static Image<Rgb24> GetSonogramPlusCharts(BaseSonogram sonogram, List<EventCommon> events, List<Plot> plots, double[, ] hits, string title)
Parameters
Type | Name | Description |
---|---|---|
BaseSonogram | sonogram | of BaseSonogram class. |
List<EventCommon> | events | a list of acoustic events. |
List<Plot> | plots | a list of plots relevant to the spectrogram scores. |
Double[,] | hits | not often used - can be null. |
String | title |
Returns
Type | Description |
---|---|
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgb24> |
HistogramOfSpectralPeaks(Double[,])
Returns a HISTORGRAM OF THE DISTRIBUTION of SPECTRAL maxima.
Declaration
public static Tuple<int[], int[]> HistogramOfSpectralPeaks(double[, ] spectrogram)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | spectrogram |
Returns
Type | Description |
---|---|
Tuple<Int32[], Int32[]> |
NormaliseSpectrogramMatrix(Double[,], Double, Double, Double)
Used to normalise a spectrogram in 0,1.
Declaration
public static double[, ] NormaliseSpectrogramMatrix(double[, ] matrix, double truncateMin, double truncateMax, double backgroundFilterCoeff)
Parameters
Type | Name | Description |
---|---|---|
Double[,] | matrix | the spectrogram data. |
Double | truncateMin | set all values above to 1.0. |
Double | truncateMax | set all values below to zero. |
Double | backgroundFilterCoeff | used to de-emphisize the background. |
Returns
Type | Description |
---|---|
Double[,] | a normalised matrix of spectrogram data. |
RescaleSpectrumUsingFilterbank(Int32[,], Double[])
Converts a single linear frequency scale spectrum to a reduced linear or non-linear frequency scale spectrum. The scale conversion is defined in the transformMatrix variable. The transformMatrix defines a filter bank. Strictly speaking the input spectrum can be any vector of values but typically it should be linear spectrum.
Declaration
public static double[] RescaleSpectrumUsingFilterbank(int[, ] transformMatrix, double[] linearSpectrum)
Parameters
Type | Name | Description |
---|---|---|
Int32[,] | transformMatrix | |
Double[] | linearSpectrum |
Returns
Type | Description |
---|---|
Double[] |