Skip to content

Commit

Permalink
Changed parameters values to ease neighbourhood test.
Browse files Browse the repository at this point in the history
Issue #319 Final work on Boobook recognizer.
LoggedConsole makes it too difficult to debug large dataset so revert to using Console.Writeline.
  • Loading branch information
towsey committed May 28, 2020
1 parent ad5eb45 commit a00923e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
29 changes: 22 additions & 7 deletions src/AnalysisPrograms/Recognizers/Birds/NinoxBoobook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
SetFrequencyProfileScore((ChirpEvent)ev);
}

if (combinedResults.NewEvents.Count == 0)
{
//Console.WriteLine($"Return zero events.");
return combinedResults;
}

// 2: Combine overlapping events. If the dB threshold is set low, may get lots of little events.
combinedResults.NewEvents = CompositeEvent.CombineOverlappingEvents(chirpEvents.Cast<EventCommon>().ToList());
Console.WriteLine($"Event count after combining overlaps = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after combining overlaps = {combinedResults.NewEvents.Count}");

// 3: Combine proximal events. If the dB threshold is set low, may get lots of little events.
if (genericConfig.CombinePossibleSyllableSequence)
Expand All @@ -123,7 +129,7 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
var startDiff = genericConfig.SyllableStartDifference;
var hertzDiff = genericConfig.SyllableHertzGap;
combinedResults.NewEvents = CompositeEvent.CombineProximalEvents(spectralEvents1, TimeSpan.FromSeconds(startDiff), (int)hertzDiff);
LoggedConsole.WriteLine($"Event count after combining proximals = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after combining proximals = {combinedResults.NewEvents.Count}");
}

// Get the BoobookSyllable config.
Expand All @@ -134,9 +140,12 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
// The idea is that an unambiguous event should have some acoustic space above and below.
// The filter requires that the average acoustic activity in each frame and bin of the upper and lower buffer zones should not exceed the user specified decibel threshold.
// The bandwidth of these two neighbourhoods is determined by the following parameters.
// The decibel threshold is currently set 5/6ths of the user specified threshold.
// ................... THIS IS TO BE WATCHED. IT MAY PROVE TO BE INAPPROPRIATE TO HARD-CODE.
// ########## These parameters could be specified by user in config.yml file.
var upperHertzBuffer = 400;
var lowerHertzBuffer = 150;
var neighbourhoodDbThreshold = chirpConfig.DecibelThreshold.Value * 0.8333;

if (upperHertzBuffer > 0 || lowerHertzBuffer > 0)
{
Expand All @@ -147,15 +156,21 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
lowerHertzBuffer,
upperHertzBuffer,
segmentStartOffset,
chirpConfig.DecibelThreshold.Value);
neighbourhoodDbThreshold);

LoggedConsole.WriteLine($"Event count after filtering on neighbourhood = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after filtering on neighbourhood = {combinedResults.NewEvents.Count}");
}

if (combinedResults.NewEvents.Count == 0)
{
//Console.WriteLine($"Return zero events.");
return combinedResults;
}

// 5: Filter on COMPONENT COUNT in Composite events.
int maxComponentCount = 2;
combinedResults.NewEvents = SpectralEvent.FilterEventsOnCompositeContent(combinedResults.NewEvents, maxComponentCount);
LoggedConsole.WriteLine($"Event count after filtering on component count = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after filtering on component count = {combinedResults.NewEvents.Count}");

// 6: Filter the events for duration in seconds
var minimumEventDuration = chirpConfig.MinDuration;
Expand All @@ -167,14 +182,14 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
}

combinedResults.NewEvents = SpectralEvent.FilterOnDuration(combinedResults.NewEvents, minimumEventDuration.Value, maximumEventDuration.Value);
LoggedConsole.WriteLine($"Event count after filtering on duration = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after filtering on duration = {combinedResults.NewEvents.Count}");

// 7: Filter the events for bandwidth in Hertz
double average = 280;
double sd = 40;
double sigmaThreshold = 3.0;
combinedResults.NewEvents = SpectralEvent.FilterOnBandwidth(combinedResults.NewEvents, average, sd, sigmaThreshold);
LoggedConsole.WriteLine($"Event count after filtering on bandwidth = {combinedResults.NewEvents.Count}");
//Console.WriteLine($"Event count after filtering on bandwidth = {combinedResults.NewEvents.Count}");

//UNCOMMENT following line if you want special debug spectrogram, i.e. with special plots.
// NOTE: Standard spectrograms are produced by setting SaveSonogramImages: "True" or "WhenEventsDetected" in UserName.SpeciesName.yml config file.
Expand Down
4 changes: 2 additions & 2 deletions src/AudioAnalysisTools/Events/SpectralEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ public static double GetAverageAmplitudeInLowerNeighbourhood(SpectralEvent ev, d
double decibelThreshold)
{
// allow a bin gaps above and below the event.
int upperBinGap = 3;
int lowerBinGap = 1;
int upperBinGap = 4;
int lowerBinGap = 2;

var filteredEvents = new List<EventCommon>();
foreach (var ev in events)
Expand Down
4 changes: 2 additions & 2 deletions src/AudioAnalysisTools/Events/Types/CompositeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public static List<EventCommon> CombineProximalEvents(List<SpectralEvent> events
/// Two conditions apply:
/// (1) the events are coincident (have similar start and end times)
/// (2) the events are stacked (their minima and maxima are within the passed frequency gap).
/// NOTE: The difference between this method and CombineProximalEvents() is that stacked events should have both similar start and similar end times.
/// Having similar start and end times means the events are superimposed in the spectrogram.
/// NOTE: The difference between this method and CombineProximalEvents() is that stacked events should have similar start AND similar end times.
/// Having similar start and end times means the events are "stacked" (like pancakes!) in the spectrogram.
/// How closely stacked is determined by the hertzDifference argument. Typicaly, the formant spacing is not large, ~100-200Hz.
/// </summary>
public static List<EventCommon> CombineStackedEvents(List<SpectralEvent> events, TimeSpan timeDifference, int hertzDifference)
Expand Down

0 comments on commit a00923e

Please sign in to comment.