Skip to content

Commit

Permalink
Add more info concerning post-processing of events
Browse files Browse the repository at this point in the history
Issue #451 Add info concerning combining events and also add more to determination of side-band activity.
  • Loading branch information
towsey committed Feb 20, 2021
1 parent 53945d0 commit 94b33d4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 57 deletions.
24 changes: 10 additions & 14 deletions src/AudioAnalysisTools/Events/EventFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,16 @@ public static List<EventCommon> FilterEventsOnSidebandActivity(
BaseSonogram spectrogram,
int lowerHertzBuffer,
int upperHertzBuffer,
bool filterEventsOnSidebandBackground,
double thresholdForAverageDecibelsInSidebands,
bool filterEventsOnSidebandActivity,
double thresholdForMaxSidebandActivity,
TimeSpan segmentStartOffset)
{
// allow bin gaps below the event.
int lowerBinGap = 2;
int upperBinGap = 2;

//The decibel value of any other event in the sidebands of a focal event
// cannot come within 3 dB of the dB value of the focal event.
//var decibelBuffer = 3.0;

var converter = new UnitConverters(
segmentStartOffset: segmentStartOffset.TotalSeconds,
sampleRate: spectrogram.SampleRate,
Expand All @@ -367,21 +365,19 @@ public static List<EventCommon> FilterEventsOnSidebandActivity(
var filteredEvents = new List<SpectralEvent>();
foreach (var ev in events)
{
//var avEventDecibels = EventExtentions.GetAverageDecibelsInEvent(ev, spectrogramData, converter);
//var maxSidebandEventDecibels = Math.Max(0.0, avEventDecibels - decibelBuffer);

var upperSidebandGood = true;
var lowerSidebandGood = true;
var upperSidebandAccepted = true;
var lowerSidebandAccepted = true;

// Both sidebands are subjected to two tests: the background test and the activity test.
if (lowerHertzBuffer > 0)
{
var lowerSidebandMatrix = GetLowerEventSideband(ev, spectrogramData, lowerHertzBuffer, lowerBinGap, converter);
lowerSidebandGood = IsSidebandActivityBelowThreshold(
lowerSidebandAccepted = IsSidebandActivityBelowThreshold(
lowerSidebandMatrix,
thresholdForMaxSidebandActivity,
thresholdForAverageDecibelsInSidebands);

if (!lowerSidebandGood)
if (!lowerSidebandAccepted)
{
Log.Debug($" EventRejected: Lower sideband has acoustic activity above {thresholdForAverageDecibelsInSidebands} dB");
}
Expand All @@ -390,18 +386,18 @@ public static List<EventCommon> FilterEventsOnSidebandActivity(
if (upperHertzBuffer > 0)
{
var upperSidebandMatrix = GetUpperEventSideband(ev, spectrogramData, upperHertzBuffer, upperBinGap, converter);
upperSidebandGood = IsSidebandActivityBelowThreshold(
upperSidebandAccepted = IsSidebandActivityBelowThreshold(
upperSidebandMatrix,
thresholdForMaxSidebandActivity,
thresholdForAverageDecibelsInSidebands);

if (!upperSidebandGood)
if (!upperSidebandAccepted)
{
Log.Debug($" EventRejected: Upper sideband has acoustic activity above {thresholdForAverageDecibelsInSidebands} dB");
}
}

if (upperSidebandGood && lowerSidebandGood)
if (upperSidebandAccepted && lowerSidebandAccepted)
{
// The acoustic activity in event sidebands is below the threshold. It is likely to be a discrete event.
Log.Debug($" EventAccepted: Both sidebands have acoustic activity below {thresholdForAverageDecibelsInSidebands} dB.");
Expand Down
67 changes: 44 additions & 23 deletions src/AudioAnalysisTools/Events/Types/EventPostProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ public static List<EventCommon> PostProcessingOfSpectralEvents(
// Step 3: Remove events whose bandwidth is too small or large.
// Step 4: Remove events that have excessive noise in their side-bands.

Log.Debug($"Total event count BEFORE post-processing = {newEvents.Count}");
Log.Debug($"\nTotal EVENT COUNT BEFORE post-processing = {newEvents.Count}");

// 1: Combine overlapping events.
// This will be necessary where many small events have been found - possibly because the dB threshold is set low.
if (postprocessingConfig.CombineOverlappingEvents)
{
Log.Debug($"COMBINE EVENTS HAVING TEMPORAl *AND* SPECTRAL OVERLAP");
newEvents = CompositeEvent.CombineOverlappingEvents(newEvents.Cast<EventCommon>().ToList());
Log.Debug($"Event count after combining overlapped events = {newEvents.Count}");
Log.Debug($" Event count after combining overlapped events = {newEvents.Count}");
}

// 2: Combine proximal events, that is, events that may be a sequence of syllables in the same strophe.
Expand Down Expand Up @@ -102,22 +103,32 @@ public static List<EventCommon> PostProcessingOfSpectralEvents(
// 5: Filter events on the amount of acoustic activity in their upper and lower sidebands - their buffer zone.
// 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.
var sidebandActivity = postprocessingConfig.SidebandActivity;
var sidebandActivity = postprocessingConfig.SidebandAcousticActivity;
if ((sidebandActivity != null) && (newEvents.Count > 0))
{
Log.Debug($"FILTER ON SIDEBAND ACTIVITY");
Log.Debug($" Max permitted sideband background = {sidebandActivity.MaxAverageDecibels:F0} dB");
Log.Debug($" Max permitted sideband activity = {sidebandActivity.MaxActivityDecibels:F0} dB");
var spectralEvents2 = newEvents.Cast<SpectralEvent>().ToList();
newEvents = EventFilters.FilterEventsOnSidebandActivity(
spectralEvents2,
spectrogram,
sidebandActivity.LowerHertzBuffer,
sidebandActivity.UpperHertzBuffer,
sidebandActivity.MaxAverageDecibels,
sidebandActivity.MaxActivityDecibels,
segmentStartOffset);
Log.Debug($" Event count after filtering on sideband activity = {newEvents.Count}");
if ((sidebandActivity.LowerSidebandWidth > 0) || (sidebandActivity.UpperSidebandWidth > 0))
{
Log.Debug($"FILTER ON SIDEBAND ACTIVITY");
Log.Debug($" Lower sideband width= {sidebandActivity.LowerSidebandWidth} Hz; Upper sideband width= {sidebandActivity.UpperSidebandWidth} Hz");
Log.Debug($" Max permitted sideband background = {sidebandActivity.MaxBackgroundDecibels:F0} dB");
Log.Debug($" Max permitted sideband activity = {sidebandActivity.MaxActivityDecibels:F0} dB");
var spectralEvents2 = newEvents.Cast<SpectralEvent>().ToList();
newEvents = EventFilters.FilterEventsOnSidebandActivity(
spectralEvents2,
spectrogram,
sidebandActivity.LowerSidebandWidth,
sidebandActivity.UpperSidebandWidth,
sidebandActivity.FilterEventsOnSidebandBackground,
sidebandActivity.MaxBackgroundDecibels,
sidebandActivity.FilterEventsOnSidebandActivity,
sidebandActivity.MaxActivityDecibels,
segmentStartOffset);
Log.Debug($" Event count after filtering on sideband activity = {newEvents.Count}");
}
else
{
Log.Debug($"DO NOT FILTER ON SIDEBAND ACTIVITY: both sidebands assigned zero width.");
}
}

// Write out the events to log.
Expand Down Expand Up @@ -152,9 +163,9 @@ public class PostProcessingConfig
public SyllableSequenceConfig SyllableSequence { get; set; }

/// <summary>
/// Gets or sets the parameters required to filter events on the acoustic acticity in their sidebands.
/// Gets or sets the parameters required to filter events on the acoustic activity in their sidebands.
/// </summary>
public SidebandConfig SidebandActivity { get; set; }
public SidebandConfig SidebandAcousticActivity { get; set; }

/// <summary>
/// Gets or sets the parameters required to filter events on their duration.
Expand Down Expand Up @@ -208,20 +219,30 @@ public class SidebandConfig
/// Gets or sets a value indicating Whether or not to filter events based on acoustic conctent of upper buffer zone.
/// If value = 0, the upper sideband is ignored.
/// </summary>
public int UpperHertzBuffer { get; set; }
public int UpperSidebandWidth { get; set; }

/// <summary>
/// Gets or sets a value indicating Whether or not to filter events based on the acoustic content of their lower buffer zone.
/// If value = 0, the lower sideband is ignored.
/// </summary>
public int LowerHertzBuffer { get; set; }
public int LowerSidebandWidth { get; set; }

/// <summary>
/// Gets or sets a value indicating Whether or not to filter events based on background noise in the sidebands.
/// </summary>
public bool FilterEventsOnSidebandBackground { get; set; }

/// <summary>
/// Gets or sets a value indicating the maximum value of the average decibels of background acoustic activity
/// in the upper and lower sidebands of an event. The average is over all spectrogram cells in each sideband.
/// Gets or sets a value indicating the maximum permissible value of background acoustic activity in the upper and lower sidebands of an event.
/// The background is claculated as the average decibel value over all spectrogram cells in each sideband.
/// This value is used only if LowerHertzBuffer > 0 OR UpperHertzBuffer > 0.
/// </summary>
public double MaxAverageDecibels { get; set; }
public double MaxBackgroundDecibels { get; set; }

/// <summary>
/// Gets or sets a value indicating Whether or not to filter events based on the presence of acoustic "events" in the sidebands.
/// </summary>
public bool FilterEventsOnSidebandActivity { get; set; }

/// <summary>
/// Gets or sets a value indicating the maximum decibel value in a sideband frequency bin or timeframe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public void TestBlobAlgorithm()

// filter on acousstic activity in sidebands.
// zero indicates no filtering.
SidebandActivity = new SidebandConfig()
SidebandAcousticActivity = new SidebandConfig()
{
UpperHertzBuffer = 0,
LowerHertzBuffer = 0,
MaxAverageDecibels = 0,
UpperSidebandWidth = 0,
LowerSidebandWidth = 0,
MaxBackgroundDecibels = 0,
},
},
};
Expand Down Expand Up @@ -186,11 +186,11 @@ public void TestOscillationAlgorithm()

// filter on acousstic activity in sidebands.
// zero indicates no filtering.
SidebandActivity = new SidebandConfig()
SidebandAcousticActivity = new SidebandConfig()
{
UpperHertzBuffer = 0,
LowerHertzBuffer = 0,
MaxAverageDecibels = 0,
UpperSidebandWidth = 0,
LowerSidebandWidth = 0,
MaxBackgroundDecibels = 0,
},
},
};
Expand Down Expand Up @@ -248,11 +248,11 @@ public void TestWhistleAlgorithm()

// filter on acousstic activity in sidebands.
// zero indicates no filtering.
SidebandActivity = new SidebandConfig()
SidebandAcousticActivity = new SidebandConfig()
{
UpperHertzBuffer = 0,
LowerHertzBuffer = 0,
MaxAverageDecibels = 0,
UpperSidebandWidth = 0,
LowerSidebandWidth = 0,
MaxBackgroundDecibels = 0,
},
},
};
Expand Down Expand Up @@ -994,11 +994,11 @@ public void TestAedAlgorithm()

// filter on acousstic activity in sidebands.
// zero indicates no filtering.
SidebandActivity = new SidebandConfig()
SidebandAcousticActivity = new SidebandConfig()
{
UpperHertzBuffer = 0,
LowerHertzBuffer = 0,
MaxAverageDecibels = 0,
UpperSidebandWidth = 0,
LowerSidebandWidth = 0,
MaxBackgroundDecibels = 0,
},
},
};
Expand Down Expand Up @@ -1084,11 +1084,11 @@ public void TestMultipleAlgorithms()

// filter on acousstic activity in sidebands.
// zero indicates no filtering.
SidebandActivity = new SidebandConfig()
SidebandAcousticActivity = new SidebandConfig()
{
UpperHertzBuffer = 0,
LowerHertzBuffer = 0,
MaxAverageDecibels = 0,
UpperSidebandWidth = 0,
LowerSidebandWidth = 0,
MaxBackgroundDecibels = 0,
},
},
};
Expand Down

0 comments on commit 94b33d4

Please sign in to comment.