Class SNR
Assembly: AudioAnalysisTools.dll
Constructors
|
Improve this Doc
View Source
Initializes a new instance of the SNR class.
CONSTRUCTOR
This constructor is called once from DSP_Frames.ExtractEnvelopeAndAmplSpectrogram().
Declaration
public SNR(double[] signal, int[, ] frameIDs)
Parameters
Type |
Name |
Description |
Double[] |
signal |
signal.
|
Int32[,] |
frameIDs |
the start and end index of every frame.
|
Fields
|
Improve this Doc
View Source
Declaration
public const double DefaultNhBgThreshold = 2
Field Value
|
Improve this Doc
View Source
Declaration
public const double DefaultStddevCount = 0
Field Value
|
Improve this Doc
View Source
Declaration
public const double FractionalBoundForLowPercentile = 0.2
Field Value
|
Improve this Doc
View Source
Declaration
public const double FractionalBoundForMode = 0.95
Field Value
|
Improve this Doc
View Source
Declaration
public const string KeyDynamicRange = "DYNAMIC_RANGE"
Field Value
|
Improve this Doc
View Source
Declaration
public const string KeyNoiseReductionType = "NOISE_REDUCTION_TYPE"
Field Value
|
Improve this Doc
View Source
Declaration
public const double MaxLogEnergyReference = 0
Field Value
|
Improve this Doc
View Source
Reference dB levels for recording of very silent environment
Used as minimum bound when normalising dB values.
This value was based on actual recording of cold winter morning (Gympie) using an SM2.
However, SM4 has a lower noise level. Consequently this value lowered to -90 on 7th August 2018.
Declaration
public const double MinimumDbBoundForEnvironmentalNoise = -90
Field Value
|
Improve this Doc
View Source
Reference dB levels for a zero signal
Used as minimum bound when normalising dB values.
This value was based on the observation of an actual zero signal on an SM2.
However, SM4 has a lower noise level. Consequently this value lowered to -100 on 7th August 2018.
Declaration
public const double MinimumDbBoundForZeroSignal = -100
Field Value
|
Improve this Doc
View Source
Reference logEnergies for signal segmentation, energy normalisation etc
MinLogEnergyReference was changed from -6.0 to -8.0 on 6th August 2018 to accommodate signals with extended zero values.
Typical noise value using Jason Wimmer original handheld recorders was = -4.5 = -45dB
Typical noise value for quiet recordings with SM4 = -8.0 or -9.0, i.e. -80 to -90 dB.
Declaration
public const double MinLogEnergyReference = -8
Field Value
Properties
|
Improve this Doc
View Source
Declaration
public double FractionOfHighEnergyFrames { get; set; }
Property Value
|
Improve this Doc
View Source
Gets or sets the FrameDecibels array. Calculate as dB[i] = 10 x log-energy of frame[i].
Appears only to be used to determine the fraction of high energy frames.
Declaration
public double[] FrameDecibels { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double MaxDb { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double MaxReferenceDecibelsWrtNoise { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double MinDb { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double[] ModalNoiseProfile { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double NoiseRange { get; set; }
Property Value
|
Improve this Doc
View Source
Declaration
public double NoiseSubtracted { get; set; }
Property Value
|
Improve this Doc
View Source
Gets or sets Snr.
SNR = max_dB - Q
that is, max decibels minus the modal noise
This is notation used by Lamel et al.
Declaration
public double Snr { get; set; }
Property Value
Methods
|
Improve this Doc
View Source
This method written 18-09-2014 to process Xueyan's query recordings.
Calculate the SNR statistics for each recording and then write info back to csv file.
Declaration
public static SNR.SnrStatistics Calculate_SNR_ShortRecording(FileInfo sourceRecording, Dictionary<string, string> configDict, TimeSpan start, TimeSpan duration, int minHz, int maxHz, double threshold)
Parameters
Returns
|
Improve this Doc
View Source
Calculates the mean intensity in a freq band defined by its min and max freq.
THis method averages dB log values incorrectly but it is faster than doing many log conversions.
This method is used to find acoustic events and is accurate enough for the purpose.
Declaration
public static double[] CalculateFreqBandAvIntensity(double[, ] sonogram, int minHz, int maxHz, int nyquist)
Parameters
Returns
|
Improve this Doc
View Source
Calculates the average intensity in a freq band having min and max freq,
AND then subtracts average intensity in the side/buffer bands, below and above.
THis method adds dB log values incorrectly but it is faster than doing many log conversions.
This method is used to find acoustic events and is accurate enough for the purpose.
Declaration
public static double[] CalculateFreqBandAvIntensityMinusBufferIntensity(double[, ] sonogramData, int minHz, int maxHz, int bottomHzBuffer, int topHzBuffer, int nyquist)
Parameters
Returns
|
Improve this Doc
View Source
Returns the log(energy) in each frame of the signal.
The energy of a frame is the log of the summed energy of all the samples in the frame.
Normally, if the passed frames are FFT spectra, then would multiply by 2 because spectra are symmetrical about Nyquist.
BUT this method returns the AVERAGE sample energy, which therefore normalises for frame length / sample number.
Energy normalisation formula taken from Lecture Notes of Prof. Bryan Pellom
Automatic Speech Recognition: From Theory to Practice.
http://www.cis.hut.fi/Opinnot/T-61.184/ September 27th 2004.
Calculate normalised energy of frame as energy[i] = logEnergy - maxLogEnergy;
This is same as log10(logEnergy / maxLogEnergy) ie normalised to a fixed maximum energy value.
Declaration
public static double[] CalculateLogEnergyOfsignalFrames(double[] signal, int[, ] frameIDs)
Parameters
Type |
Name |
Description |
Double[] |
signal |
|
Int32[,] |
frameIDs |
|
Returns
|
Improve this Doc
View Source
NOTE: This method is identical to the above one, except that the actual frames are passed
rather than the starts and ends of the frames.
Declaration
public static double[] CalculateLogEnergyOfsignalFrames(double[, ] frames)
Parameters
Type |
Name |
Description |
Double[,] |
frames |
|
Returns
|
Improve this Doc
View Source
Declaration
public static SNR.BackgroundNoise CalculateModalBackgroundNoiseInSignal(double[] array, double sdCount)
Parameters
Returns
|
Improve this Doc
View Source
Calculates the matrix row/column bounds given the real world bounds.
Axis scales are obtained form the passed sonogram instance.
Declaration
public static SNR.SnrStatistics CalculateSnrInFreqBand(BaseSonogram sonogram, TimeSpan startTime, TimeSpan extractDuration, int minHz, int maxHz, double threshold)
Parameters
Returns
|
Improve this Doc
View Source
The calculation of SNR in this method assumes that background noise has already been removed.
That is, the maximum value is with respect to zero.
SNR should be calculated based on power values in decibel units.
i.e. SNR = 10log(PowerOfSignal / PowerOfNoise);
or SNR = 20log(Signal amplitude) - 20log(Noise amplitude);
If the passed sonogram data is amplitude or energy values (rather than decibel values) then the returned SNR value needs to be appropriately corrected.
Declaration
public static SNR.SnrStatistics CalculateSnrInFreqBand(double[, ] sonogramData, int startframe, int frameSpan, int minBin, int maxBin, double threshold)
Parameters
Returns
|
Improve this Doc
View Source
Calculates the average intensity in a freq band having min and max freq,
AND then subtracts average intensity in the side/buffer bands, below and above.
THis method adds dB log values incorrectly but it is faster than doing many log conversions.
This method is used to find acoustic events and is accurate enough for the purpose.
Declaration
public static double[] CalculateWhistleIntensity(double[, ] sonogramData, int minHz, int maxHz, int bottomHzBuffer, int topHzBuffer, int nyquist)
Parameters
Returns
|
Improve this Doc
View Source
Declaration
public static double[] ConvertLogEnergy2Decibels(double[] logEnergy)
Parameters
Type |
Name |
Description |
Double[] |
logEnergy |
|
Returns
|
Improve this Doc
View Source
Declaration
public static double[] DecibelsInSubband(double[, ] dBMatrix, int minHz, int maxHz, double freqBinWidth)
Parameters
Returns
|
Improve this Doc
View Source
This is the important part of Lamel's algorithm.
It assumes an additive noise model. That is, it assumes that the passed histogram represents the distribution of values
in a waveform consisting of a signal plus added Gaussian noise.
This method estimates the mean and SD of the noise.
Declaration
public static void GetModeAndOneStandardDeviation(double[] histo, out int indexOfMode, out int indexOfOneSd)
Parameters
|
Improve this Doc
View Source
Converts a string interpreted as a key to a NoiseReduction Type.
Declaration
public static NoiseReductionType KeyToNoiseReductionType(string key)
Parameters
Type |
Name |
Description |
String |
key |
The string to convert.
|
Returns
|
Improve this Doc
View Source
Removes noise from a spectrogram. Choice of methods.
Make sure that do MelScale reduction BEFORE applying noise filter.
Declaration
public static Tuple<double[, ], double[]> NoiseReduce(double[, ] m, NoiseReductionType nrt, double parameter)
Parameters
Returns
|
Improve this Doc
View Source
IMPORTANT: Mel scale conversion should be done before noise reduction.
Declaration
public static double[, ] NoiseReduce_FixedRange(double[, ] matrix, double dynamicRange, double sdCount)
Parameters
Returns
|
Improve this Doc
View Source
Declaration
public static double[, ] NoiseReduce_FlattenAndTrim(double[, ] matrix, double stdDevCount)
Parameters
Returns
|
Improve this Doc
View Source
The passed matrix is the decibel spectrogram.
Declaration
public static double[, ] NoiseReduce_Mean(double[, ] matrix, double nhBackgroundThreshold)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Double |
nhBackgroundThreshold |
|
Returns
|
Improve this Doc
View Source
The passed matrix is the decibel spectrogram.
Declaration
public static double[, ] NoiseReduce_Median(double[, ] matrix, double nhBackgroundThreshold)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Double |
nhBackgroundThreshold |
|
Returns
|
Improve this Doc
View Source
expects a spectrogram in dB values
IMPORTANT: Mel scale conversion should be done before noise reduction
Uses default values for severity of noise reduction and neighbourhood threshold.
Declaration
public static double[, ] NoiseReduce_Standard(double[, ] matrix)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Returns
|
Improve this Doc
View Source
expects a spectrogram in dB values.
Declaration
public static double[, ] NoiseReduce_Standard(double[, ] matrix, double[] noiseProfile, double nhBackgroundThreshold)
Parameters
Returns
|
Improve this Doc
View Source
NormaliseMatrixValues the power values using the passed reference decibel level.
NOTE: This method assumes that the energy values are in decibels and that they have been scaled
so that the modal noise value = 0 dB. Simply truncate all values below this to zero dB.
Declaration
public static double[] NormaliseDecibelArray_ZeroOne(double[] dB, double maxDecibels)
Parameters
Returns
|
Improve this Doc
View Source
returns a spectrogram with reduced number of frequency bins.
Declaration
public static double[, ] ReduceFreqBinsInSpectrogram(double[, ] inSpectro, int subbandCount)
Parameters
Type |
Name |
Description |
Double[,] |
inSpectro |
input spectrogram.
|
Int32 |
subbandCount |
numbre of req bands in output spectrogram.
|
Returns
|
Improve this Doc
View Source
This method sets a sonogram pixel value = minimum value in sonogram if average pixel value in its neighbourhood is less than min+threshold.
Typically would expect min value in sonogram = zero.
Declaration
public static double[, ] RemoveNeighbourhoodBackgroundNoise(double[, ] matrix, double nhThreshold)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
the sonogram.
|
Double |
nhThreshold |
user defined threshold. Typically in range 2-4 dB.
|
Returns
|
Improve this Doc
View Source
Root Mean Square (RMS) Normalization
Matrix is assumed to be a spectrogram
Divides the spectrogram values by the RMS in order to adjust for varying levels of signal strength.
Declaration
public static double[, ] RmsNormalization(double[, ] matrix)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Returns
|
Improve this Doc
View Source
Declaration
public static List<int[]> SegmentArrayOfIntensityvalues(double[] values, double threshold, int minLength)
Parameters
Returns
|
Improve this Doc
View Source
sets the dynamic range in dB for a sonogram.
All intensity values are shifted so that the max intensity value = maxDB parameter.
All values which fall below the minDB parameter are then set = to minDB.
Declaration
public static double[, ] SetDynamicRange(double[, ] m, double minDb, double maxDb)
Parameters
Type |
Name |
Description |
Double[,] |
m |
The spectral sonogram passes as matrix of doubles.
|
Double |
minDb |
minimum decibel value.
|
Double |
maxDb |
maximum decibel value.
|
Returns
|
Improve this Doc
View Source
Declaration
public static double[, ] SetLocalBounds(double[, ] m, int minPercentileBound, int maxPercentileBound, int temporalNh, int freqBinNh)
Parameters
Type |
Name |
Description |
Double[,] |
m |
The spectral sonogram passes as matrix of doubles.
|
Int32 |
minPercentileBound |
minimum decibel value.
|
Int32 |
maxPercentileBound |
maximum decibel value.
|
Int32 |
temporalNh |
buffer in temporal dimension.
|
Int32 |
freqBinNh |
buffer in frequency dimension.
|
Returns
|
Improve this Doc
View Source
Declaration
public static double[] Signal2Decibels(double[] signal)
Parameters
Type |
Name |
Description |
Double[] |
signal |
|
Returns
|
Improve this Doc
View Source
Declaration
public static Tuple<double[], double, double> SubbandIntensity_NoiseReduced(double[, ] sonogram, int minHz, int maxHz, int nyquist, double smoothDuration, double framesPerSec)
Parameters
Type |
Name |
Description |
Double[,] |
sonogram |
sonogram of signal - values in dB.
|
Int32 |
minHz |
min of freq band to sample.
|
Int32 |
maxHz |
max of freq band to sample.
|
Int32 |
nyquist |
signal nyquist - used to caluclate hz per bin.
|
Double |
smoothDuration |
window width (in seconds) to smooth sig intenisty.
|
Double |
framesPerSec |
time scale of the sonogram.
|
Returns
|
Improve this Doc
View Source
Declaration
public static double[] SubtractAndTruncate2Zero(double[] inArray, double threshold)
Parameters
Returns
|
Improve this Doc
View Source
Subtracts the supplied noise profile from spectorgram AND sets values less than backgroundThreshold to ZERO.
Declaration
public static double[, ] SubtractAndTruncateNoiseProfile(double[, ] matrix, double[] noiseProfile, double backgroundThreshold)
Parameters
Returns
|
Improve this Doc
View Source
subtract background noise to produce a decibels array in which zero dB = modal noise
DOES NOT TRUNCATE BELOW ZERO VALUES.
Declaration
public void SubtractBackgroundNoise_dB()
|
Improve this Doc
View Source
Calculates and subtracts the background noise value from an array of double.
Used for calculating and removing the background noise and setting baseline = zero.
Implements a MODIFIED version of Lamel et al. They only search in range 10dB above min dB whereas
this method sets upper limit to 66% of range of intensity values.
ASSUMES ADDITIVE MODEL with GAUSSIAN NOISE.
Values below zero set equal to zero.
This method can be called for any array of signal values but is PRESUMED TO BE A WAVEFORM or FREQ BIN OF HISTOGRAM.
Declaration
public static SNR.BackgroundNoise SubtractBackgroundNoiseFromSignal(double[] array, double sdCount)
Parameters
Returns
|
Improve this Doc
View Source
Calls method to implement the "Adaptive Level Equalisatsion" algorithm of (Lamel et al, 1981)
It has the effect of setting background noise level to 0 dB.
Passed signal array MUST be in deciBels.
ASSUMES an ADDITIVE MODEL with GAUSSIAN NOISE.
Calculates the average and standard deviation of the noise and then calculates a noise threshold.
Then subtracts threshold noise from the signal - so now zero dB = threshold noise
Sets default values for min dB value and the noise threshold. 10 dB is a default used by Lamel et al.
RETURNS: 1) noise reduced decibel array; 2) Q - the modal BG level; 3) min value 4) max value; 5) snr; and 6) SD of the noise.
Declaration
public static SNR.BackgroundNoise SubtractBackgroundNoiseFromWaveform_dB(double[] dBarray, double sdCount)
Parameters
Returns
|
Improve this Doc
View Source
Subtracts the supplied modal noise value for each freq bin BUT DOES NOT set negative values to zero.
Declaration
public static double[, ] SubtractBgNoiseFromSpectrogram(double[, ] matrix, double[] noiseProfile)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Double[] |
noiseProfile |
|
Returns
|
Improve this Doc
View Source
Subtracts the supplied noise profile from spectorgram AND sets negative values to ZERO.
Declaration
public static double[, ] TruncateBgNoiseFromSpectrogram(double[, ] matrix, double[] noiseProfile)
Parameters
Type |
Name |
Description |
Double[,] |
matrix |
|
Double[] |
noiseProfile |
|
Returns
|
Improve this Doc
View Source
Declaration
public static double[] TruncateNegativeValues2Zero(double[] inArray)
Parameters
Type |
Name |
Description |
Double[] |
inArray |
|
Returns
Extension Methods