Skip to content

Commit

Permalink
Fix production of Octave scale spectrogram
Browse files Browse the repository at this point in the history
Issue #332
  • Loading branch information
towsey committed Aug 11, 2020
1 parent 7ed5281 commit f3eb3ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,10 @@ public double GetFrameOffset(int sampleRate)
int step = DSP_Frames.FrameStep(this.WindowSize, this.WindowOverlap);
return step / (double)sampleRate;
}

public static double CalculateFrameOverlap(int frameWidth, int frameStep)
{
return 1 - (frameStep / (double)frameWidth);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,18 @@ namespace AudioAnalysisTools.StandardSpectrograms

public class SpectrogramOctaveScale : BaseSonogram
{
public SpectrogramOctaveScale(string configFile, WavReader wav)
: this(SonogramConfig.Load(configFile), wav)
public SpectrogramOctaveScale(SonogramConfig config, FrequencyScale scale, WavReader wav)
: base(config, scale, wav)
{
}

public SpectrogramOctaveScale(SonogramConfig config, WavReader wav)
: base(config, wav)
{
}

public SpectrogramOctaveScale(AmplitudeSonogram sg)
: base(sg.Configuration)
{
this.Configuration = sg.Configuration;
this.DecibelsPerFrame = sg.DecibelsPerFrame;
this.DecibelsNormalised = sg.DecibelsNormalised;
this.Duration = sg.Duration;
this.FrameCount = sg.FrameCount;
this.DecibelReference = sg.DecibelReference;
this.MaxAmplitude = sg.MaxAmplitude;
this.SampleRate = sg.SampleRate;
this.SigState = sg.SigState;
this.SnrData = sg.SnrData;
this.Make(sg.Data);
}

/// <summary>
/// Converts amplitude matrix to octave frequency scale spectrogram.
/// ########################################################################TODO TODO need to init as AmplitudeSpectrogram and then use constructor at Line 25.
/// </summary>
/// <param name="amplitudeM">Matrix of amplitude values.</param>
public override void Make(double[,] amplitudeM)
{
//var freqScale = new FrequencyScale(FreqScaleType.LinearOctaveStandard);
//var freqScale = new FrequencyScale(FreqScaleType.OctaveDataReduction);
var freqScale = new FrequencyScale(FreqScaleType.Linear125OctaveTones32Nyquist11025);
//var freqScale = new FrequencyScale(FreqScaleType.Linear62OctaveTones31Nyquist11025);

double[,] m = OctaveFreqScale.ConvertAmplitudeSpectrogramToDecibelOctaveScale(amplitudeM, freqScale);
double[,] m = OctaveFreqScale.ConvertAmplitudeSpectrogramToDecibelOctaveScale(amplitudeM, this.FreqScale);

// Do noise reduction
var tuple = SNR.NoiseReduce(m, this.Configuration.NoiseReductionType, this.Configuration.NoiseReductionParameter);
Expand Down

0 comments on commit f3eb3ed

Please sign in to comment.