diff --git a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs index 1e06c12c1..38905c0f4 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs @@ -133,6 +133,7 @@ public static SonogramConfig Load(string configFile) /// /// Initializes a new instance of the class. /// Default Constructor - initialises a configuration with the default values. + /// This sets the default values for most spectrogram types, including Mel-scale and MFCC spectrograms. /// public SonogramConfig() { diff --git a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramMelScale.cs b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramMelScale.cs index efbe6c6b0..08a49a980 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramMelScale.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramMelScale.cs @@ -66,7 +66,7 @@ public SpectrogramMelScale(AmplitudeSonogram sg, int minHz, int maxHz) /// Matrix of amplitude values. public override void Make(double[,] amplitudeM) { - var tuple = MakeMelScaleSpectrogram(this.Configuration, amplitudeM, this.DecibelsNormalised, this.SampleRate); + var tuple = MakeMelScaleSpectrogram(this.Configuration, amplitudeM, this.SampleRate); this.Data = tuple.Item1; this.ModalNoiseProfile = tuple.Item2; //store the full bandwidth modal noise profile } @@ -76,21 +76,15 @@ public override void Make(double[,] amplitudeM) /// /// NOTE!!!! The decibel array has been normalised in 0 - 1. /// - protected static Tuple MakeMelScaleSpectrogram(SonogramConfig config, double[,] matrix, double[] decibels, int sampleRate) + protected static Tuple MakeMelScaleSpectrogram(SonogramConfig config, double[,] matrix, int sampleRate) { double[,] m = matrix; int nyquist = sampleRate / 2; double epsilon = config.epsilon; - bool includeDelta = config.mfccConfig.IncludeDelta; - bool includeDoubleDelta = config.mfccConfig.IncludeDoubleDelta; //(i) APPLY FILTER BANK int bandCount = config.mfccConfig.FilterbankCount; - bool doMelScale = config.mfccConfig.DoMelScale; - int ccCount = config.mfccConfig.CcCount; int fftBinCount = config.FreqBinCount; //number of Hz bands = 2^N +1. Subtract DC bin - int minHz = config.MinFreqBand ?? 0; - int maxHz = config.MaxFreqBand ?? nyquist; Log.WriteIfVerbose("ApplyFilterBank(): Dim prior to filter bank =" + matrix.GetLength(1)); @@ -98,12 +92,12 @@ protected static Tuple MakeMelScaleSpectrogram(SonogramConf if (bandCount > fftBinCount) { throw new Exception( - "## FATAL ERROR in BaseSonogram.MakeCepstrogram():- Can't calculate cepstral coefficients. Filterbank Count > number of FFT bins. (" + + "## FATAL ERROR in MakeMelScaleSpectrogram(): Filterbank Count > number of FFT bins. (" + bandCount + " > " + fftBinCount + ")\n\n"); } //this is the filter count for full bandwidth 0-Nyquist. This number is trimmed proportionately to fit the required bandwidth. - m = doMelScale ? MFCCStuff.MelFilterBank(m, bandCount, nyquist, minHz, maxHz) : MFCCStuff.LinearFilterBank(m, bandCount, nyquist, minHz, maxHz); + m = MFCCStuff.MelFilterBank(m, bandCount, nyquist, 0, nyquist); Log.WriteIfVerbose("\tDim after filter bank=" + m.GetLength(1) + " (Max filter bank=" + bandCount + ")"); diff --git a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs index a06bb1bb0..2dbb3fae0 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs @@ -72,7 +72,7 @@ public SpectrogramOctaveScale(AmplitudeSonogram sg, int minHz, int maxHz) /// Matrix of amplitude values. public override void Make(double[,] amplitudeM) { - var tuple = MakeOctaveScaleSpectrogram(this.Configuration, amplitudeM, this.DecibelsNormalised, this.SampleRate); + var tuple = MakeOctaveScaleSpectrogram(this.Configuration, amplitudeM, this.SampleRate); this.Data = tuple.Item1; this.ModalNoiseProfile = tuple.Item2; //store the full bandwidth modal noise profile } @@ -82,21 +82,15 @@ public override void Make(double[,] amplitudeM) /// /// NOTE!!!! The decibel array has been normalised in 0 - 1. /// - protected static Tuple MakeOctaveScaleSpectrogram(SonogramConfig config, double[,] matrix, double[] decibels, int sampleRate) + protected static Tuple MakeOctaveScaleSpectrogram(SonogramConfig config, double[,] matrix, int sampleRate) { double[,] m = matrix; int nyquist = sampleRate / 2; double epsilon = config.epsilon; - bool includeDelta = config.mfccConfig.IncludeDelta; - bool includeDoubleDelta = config.mfccConfig.IncludeDoubleDelta; //(i) APPLY FILTER BANK int bandCount = config.mfccConfig.FilterbankCount; - bool doMelScale = config.mfccConfig.DoMelScale; - int ccCount = config.mfccConfig.CcCount; int fftBinCount = config.FreqBinCount; //number of Hz bands = 2^N +1. Subtract DC bin - int minHz = config.MinFreqBand ?? 0; - int maxHz = config.MaxFreqBand ?? nyquist; Log.WriteIfVerbose("ApplyFilterBank(): Dim prior to filter bank =" + matrix.GetLength(1)); @@ -104,13 +98,13 @@ protected static Tuple MakeOctaveScaleSpectrogram(SonogramC if (bandCount > fftBinCount) { throw new Exception( - "## FATAL ERROR in BaseSonogram.MakeCepstrogram():- Can't calculate cepstral coefficients. Filterbank Count > number of FFT bins. (" + + "## FATAL ERROR in MakeOctaveScaleSpectrogram(): Filterbank Count > number of FFT bins. (" + bandCount + " > " + fftBinCount + ")\n\n"); } //this is the filter count for full bandwidth 0-Nyquist // TODO ADJUST THIS TO OCTAVE SCALE - m = doMelScale ? MFCCStuff.MelFilterBank(m, bandCount, nyquist, minHz, maxHz) : MFCCStuff.LinearFilterBank(m, bandCount, nyquist, minHz, maxHz); + m = MFCCStuff.MelFilterBank(m, bandCount, nyquist, 0, nyquist); Log.WriteIfVerbose("\tDim after filter bank=" + m.GetLength(1) + " (Max filter bank=" + bandCount + ")");