Skip to content

Commit

Permalink
Fixed bug that arose when first implementing multiple decibel thresholds
Browse files Browse the repository at this point in the history
Issue #390 A bug appeared when first implementing multiple decibel thresholds. The loop over an array of thresholdholds was implemented only around the profile matching and did not include the post processing. This caused the recognizer to miss many true calls. The corrections implemented here are to encusre that the lopp over all decibel thresholds includes both the profile detection and the post processing in each pass.
  • Loading branch information
towsey authored and atruskie committed Nov 1, 2020
1 parent 8630b97 commit cf30bdf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 92 deletions.
6 changes: 0 additions & 6 deletions src/AudioAnalysisTools/CommonParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,5 @@ public abstract class CommonParameters
/// Gets or sets the maximum allowed duration of the component. Units are seconds.
/// </summary>
public double? MaxDuration { get; set; } = 10.0;

/// <summary>
/// Gets or sets an array of decibel thresholds.
/// Each threshold determines the minimum "loudness" of an event that can be detected. Units are decibels.
/// </summary>
public double?[] DecibelThresholds { get; set; }
}
}
68 changes: 37 additions & 31 deletions src/AudioAnalysisTools/Ocillations/Oscillations2012.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,34 @@ public static class Oscillations2012
public static (List<EventCommon> SpectralEvents, List<Plot> DecibelPlots) GetComponentsWithOscillations(
SpectrogramStandard spectrogram,
OscillationParameters op,
double? decibelThreshold,
TimeSpan segmentStartOffset,
string profileName)
{
// get the array of decibel thresholds
var thresholdArray = op.DecibelThresholds;

var spectralEvents = new List<EventCommon>();
var plots = new List<Plot>();

// loop through the array of decibel thresholds
foreach (var threshold in thresholdArray)
{
Oscillations2012.Execute(
spectrogram,
op.MinHertz.Value,
op.MaxHertz.Value,
op.DctDuration,
op.MinOscillationFrequency,
op.MaxOscillationFrequency,
op.DctThreshold,
op.EventThreshold,
op.MinDuration.Value,
op.MaxDuration.Value,
out var scores,
out var oscillationEvents,
out var hits,
segmentStartOffset);

spectralEvents.AddRange(oscillationEvents);

// prepare plot of resultant Harmonics decibel array.
var plot = Plot.PreparePlot(scores, $"{profileName} (Oscillations:{threshold:F0}db)", threshold.Value);
plots.Add(plot);
}
Oscillations2012.Execute(
spectrogram,
op.MinHertz.Value,
op.MaxHertz.Value,
op.DctDuration,
op.MinOscillationFrequency,
op.MaxOscillationFrequency,
op.DctThreshold,
op.EventThreshold,
op.MinDuration.Value,
op.MaxDuration.Value,
out var scores,
out var oscillationEvents,
out var hits,
segmentStartOffset);

spectralEvents.AddRange(oscillationEvents);

// prepare plot of resultant Harmonics decibel array.
var plot = Plot.PreparePlot(scores, $"{profileName} (Oscillations:{decibelThreshold:F0}db)", decibelThreshold.Value);
plots.Add(plot);

return (spectralEvents, plots);
}
Expand All @@ -82,9 +76,21 @@ public static void Execute(
{
int scoreSmoothingWindow = 11; // sets a default that is good for Cane toad but not necessarily for other recognizers

Execute(sonogram, minHz, maxHz, dctDuration, minOscilFreq, maxOscilFreq, dctThreshold, scoreThreshold,
minDuration, maxDuration, scoreSmoothingWindow,
out scores, out events, out hits,
Execute(
sonogram,
minHz,
maxHz,
dctDuration,
minOscilFreq,
maxOscilFreq,
dctThreshold,
scoreThreshold,
minDuration,
maxDuration,
scoreSmoothingWindow,
out scores,
out events,
out hits,
segmentStartOffset);
}

Expand Down
25 changes: 11 additions & 14 deletions src/AudioAnalysisTools/Tracks/ForwardTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,26 @@ public static class ForwardTrackAlgorithm
public static (List<EventCommon> Events, List<Plot> DecibelPlots) GetForwardTracks(
SpectrogramStandard spectrogram,
ForwardTrackParameters parameters,
double? decibelThreshold,
TimeSpan segmentStartOffset,
string profileName)
{
var decibelThresholds = parameters.DecibelThresholds;
var spectralEvents = new List<EventCommon>();
var plots = new List<Plot>();

foreach (var threshold in decibelThresholds)
{
double[] decibelArray;
List<EventCommon> events;
double[] decibelArray;
List<EventCommon> events;

(events, decibelArray) = GetForwardTracks(
spectrogram,
parameters,
segmentStartOffset,
threshold.Value);
(events, decibelArray) = GetForwardTracks(
spectrogram,
parameters,
segmentStartOffset,
decibelThreshold.Value);

spectralEvents.AddRange(events);
spectralEvents.AddRange(events);

var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Chirps:{threshold.Value:F0}dB)", threshold.Value);
plots.Add(plot);
}
var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Chirps:{decibelThreshold.Value:F0}dB)", decibelThreshold.Value);
plots.Add(plot);

return (spectralEvents, plots);
}
Expand Down
11 changes: 0 additions & 11 deletions src/AudioAnalysisTools/Tracks/ForwardTrackParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,5 @@ public class ForwardTrackParameters : CommonParameters
public TimeSpan HarmonicsStartDifference { get; set; }

public int HarmonicsHertzGap { get; set; }

/// <summary>
/// Gets or sets a value indicating whether a short sequence of chirp tracks are to be considered a combined event.
/// To qualify for combining, the event start times should not be greater than the specified seconds interval....
/// AND the difference in minimum frequency values (the Hertz gap) between consecutive tracks should not exceed the specified Hertz interval.
/// </summary>
public bool CombinePossibleSyllableSequence { get; set; }

public double SyllableStartDifference { get; set; }

public int SyllableHertzGap { get; set; }
}
}
6 changes: 4 additions & 2 deletions src/AudioAnalysisTools/Tracks/OnebinTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public static (List<EventCommon> Events, List<Plot> DecibelPlots) GetOnebinTrack
}

/// <summary>
/// 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.
/// This method returns whistle (spectral peak) tracks enclosed in spectral events.
/// It averages dB log values incorrectly but it is faster than doing many log conversions.
/// </summary>
/// <param name="sonogram">The spectrogram to be searched.</param>
/// <returns>A list of acoustic events containing whistle tracks.</returns>
public static (List<EventCommon> ListOfevents, double[] CombinedIntensityArray) GetOnebinTracks(
SpectrogramStandard sonogram,
OnebinTrackParameters parameters,
Expand Down
25 changes: 11 additions & 14 deletions src/AudioAnalysisTools/Tracks/OneframeTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,26 @@ public static class OneframeTrackAlgorithm
public static (List<EventCommon> Events, List<Plot> DecibelPlots) GetOneFrameTracks(
SpectrogramStandard spectrogram,
OneframeTrackParameters parameters,
double? decibelThreshold,
TimeSpan segmentStartOffset,
string profileName)
{
var decibelThresholds = parameters.DecibelThresholds;
var spectralEvents = new List<EventCommon>();
var plots = new List<Plot>();

foreach (var threshold in decibelThresholds)
{
double[] decibelArray;
List<EventCommon> events;
double[] decibelArray;
List<EventCommon> events;

(events, decibelArray) = GetOneFrameTracks(
spectrogram,
parameters,
segmentStartOffset,
threshold.Value);
(events, decibelArray) = GetOneFrameTracks(
spectrogram,
parameters,
segmentStartOffset,
decibelThreshold.Value);

spectralEvents.AddRange(events);
spectralEvents.AddRange(events);

var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Clicks:{threshold.Value:F0}dB)", threshold.Value);
plots.Add(plot);
}
var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Clicks:{decibelThreshold.Value:F0}dB)", decibelThreshold.Value);
plots.Add(plot);

return (spectralEvents, plots);
}
Expand Down
25 changes: 11 additions & 14 deletions src/AudioAnalysisTools/Tracks/UpwardTrackAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,26 @@ public static class UpwardTrackAlgorithm
public static (List<EventCommon> Events, List<Plot> DecibelPlots) GetUpwardTracks(
SpectrogramStandard spectrogram,
UpwardTrackParameters parameters,
double? decibelThreshold,
TimeSpan segmentStartOffset,
string profileName)
{
var decibelThresholds = parameters.DecibelThresholds;
var spectralEvents = new List<EventCommon>();
var plots = new List<Plot>();

foreach (var threshold in decibelThresholds)
{
double[] decibelArray;
List<EventCommon> events;
double[] decibelArray;
List<EventCommon> events;

(events, decibelArray) = GetUpwardTracks(
spectrogram,
parameters,
segmentStartOffset,
threshold.Value);
(events, decibelArray) = GetUpwardTracks(
spectrogram,
parameters,
segmentStartOffset,
decibelThreshold.Value);

spectralEvents.AddRange(events);
spectralEvents.AddRange(events);

var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Whips:{threshold.Value:F0}dB)", threshold.Value);
plots.Add(plot);
}
var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Whips:{decibelThreshold.Value:F0}dB)", decibelThreshold.Value);
plots.Add(plot);

return (spectralEvents, plots);
}
Expand Down

0 comments on commit cf30bdf

Please sign in to comment.