Skip to content

Commit

Permalink
Changes to the sideband activity filter
Browse files Browse the repository at this point in the history
Issue #390 I changed the way the event filter is working that filters on acoustic activity in the sidebands. I changed the name of a variable and its function. The sidebnad filter now checks for two kinds of sideband activity - the average background decibels in the sidebands, and it looks for brief events in the sidebands.
  • Loading branch information
towsey authored and atruskie committed Nov 1, 2020
1 parent e80aa2c commit 772e18d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PostProcessing:
SidebandActivity:
LowerHertzBuffer: 0 #200
UpperHertzBuffer: 0
DecibelBuffer: 0.0 #9.0
MaxAverageSidebandDecibels: 0.0 #9.0

# Options to save results files
# 1: Available options for saving spectrograms (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PostProcessing:
SidebandActivity:
LowerHertzBuffer: 150
UpperHertzBuffer: 200
DecibelBuffer: 6.0
MaxAverageSidebandDecibels: 6.0

# Options to save results files
# 1: Available options for saving spectrograms (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PostProcessing:
SidebandActivity:
LowerHertzBuffer: 0
UpperHertzBuffer: 200
DecibelBuffer: 2.0
MaxAverageSidebandDecibels: 2.0

# Options to save results files
# 1: Available options for saving spectrograms (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PostProcessing:
SidebandActivity:
LowerHertzBuffer: 150
UpperHertzBuffer: 400
DecibelBuffer: 0.0
MaxAverageSidebandDecibels: 3.0

# Options to save results files
# 1: Available options for saving spectrograms (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DecibelThresholds:
- 18.0
- 24.0
- 30.0
- 36.0

# Each of these profiles will be analyzed
# This profile is required for the species-specific recogniser and must have the current name.
Expand All @@ -36,8 +37,8 @@ Profiles:
# min and max of the freq band to search
MinHertz: 300
MaxHertz: 600
MinDuration: 0.2
MaxDuration: 0.9
MinDuration: 0.3
MaxDuration: 0.6

#################### POST-PROCESSING of EVENTS ###################

Expand All @@ -54,7 +55,7 @@ PostProcessing:
# 2: Combine possible syllable sequences
SyllableSequence:
CombinePossibleSyllableSequence: true
SyllableStartDifference: 1.4
SyllableStartDifference: 0.7
SyllableHertzGap: 100
FilterSyllableSequence: false
SyllableMaxCount: 6
Expand All @@ -74,7 +75,7 @@ PostProcessing:
SidebandActivity:
LowerHertzBuffer: 0
UpperHertzBuffer: 0
DecibelBuffer: 3.0 # use this value when combining sequences
MaxAverageSidebandDecibels: 3.0

# Various options to save results files
# 1: Available options for saving spectrograms (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
32 changes: 17 additions & 15 deletions src/AudioAnalysisTools/Events/EventFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,25 @@ public static (int Count, double AveragePeriod, double SdPeriod) GetPeriodicity(
/// <param name="spectrogram">A matrix of the spectrogram in which event occurs.</param>
/// <param name="lowerHertzBuffer">The band width of the required lower buffer. 100-200Hz is often appropriate.</param>
/// <param name="upperHertzBuffer">The band width of the required upper buffer. 300-500Hz is often appropriate.</param>
/// <param name="decibelThreshold">The decibel threshold for acoustic activity in a sideband.</param>
/// <param name="thresholdForAverageDecibelsInSidebands">The max allowed value for the average decibels value (over all spectrogram cells) in a sideband of an event.</param>
/// <param name="segmentStartOffset">Start time of the current recording segment.</param>
/// <returns>A list of filtered events.</returns>
public static List<EventCommon> FilterEventsOnSidebandActivity(
List<SpectralEvent> events,
double analysisThreshold,
BaseSonogram spectrogram,
int lowerHertzBuffer,
int upperHertzBuffer,
double decibelThreshold,
double thresholdForAverageDecibelsInSidebands,
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 @@ -323,27 +326,27 @@ public static List<EventCommon> FilterEventsOnSidebandActivity(
foreach (var ev in events)
{
var avEventDecibels = EventExtentions.GetAverageDecibelsInEvent(ev, spectrogramData, converter);
var maxSidebandEventDecibels = Math.Max(0.0, avEventDecibels - decibelBuffer);

var retainEvent1 = true;
var retainEvent2 = true;

if (lowerHertzBuffer > 0)
{
var lowerSidebandMatrix = GetLowerEventSideband(ev, spectrogramData, lowerHertzBuffer, lowerBinGap, converter);
retainEvent1 = IsSidebandActivityBelowThreshold(
avEventDecibels,
analysisThreshold,
lowerSidebandMatrix,
decibelThreshold);
maxSidebandEventDecibels,
thresholdForAverageDecibelsInSidebands);
}

if (upperHertzBuffer > 0)
{
var upperSidebandMatrix = GetUpperEventSideband(ev, spectrogramData, upperHertzBuffer, upperBinGap, converter);
retainEvent2 = IsSidebandActivityBelowThreshold(
avEventDecibels,
analysisThreshold,
upperSidebandMatrix,
decibelThreshold);
maxSidebandEventDecibels,
thresholdForAverageDecibelsInSidebands);
}

if (retainEvent1 && retainEvent2)
Expand All @@ -358,18 +361,17 @@ public static List<EventCommon> FilterEventsOnSidebandActivity(
}

public static bool IsSidebandActivityBelowThreshold(
double avEventDecibels,
double analysisThreshold,
double[,] sidebandMatrix,
double sidebandThreshold)
double maxSidebandEventDecibels,
double thresholdForAverageDecibelsInSidebands)
{
var averageRowDecibels = MatrixTools.GetRowAverages(sidebandMatrix);
var averageColDecibels = MatrixTools.GetColumnAverages(sidebandMatrix);
var averageMatrixDecibels = averageColDecibels.Average();

// Is the average acoustic activity in the sideband below the user set threshold?
//bool avBgBelowThreshold = averageMatrixDecibels < analysisThreshold;
bool avBgBelowThreshold = averageMatrixDecibels < sidebandThreshold;
bool avBgBelowThreshold = averageMatrixDecibels < thresholdForAverageDecibelsInSidebands;
if (!avBgBelowThreshold)
{
return false;
Expand All @@ -378,8 +380,8 @@ public static bool IsSidebandActivityBelowThreshold(
// Also need to cover possibility that there is much acoustic activity concentrated in one freq bin or time frame.
// Therefore, also require that there be at most one sideband bin and one sideband frame containing acoustic activity
// that is greater than the average in the event.
int noisyRowCount = averageRowDecibels.Count(x => x > avEventDecibels);
int noisyColCount = averageColDecibels.Count(x => x > avEventDecibels);
int noisyRowCount = averageRowDecibels.Count(x => x > maxSidebandEventDecibels);
int noisyColCount = averageColDecibels.Count(x => x > maxSidebandEventDecibels);
bool doRetain = noisyRowCount <= 1 && noisyColCount <= 1;
return doRetain;
}
Expand Down
10 changes: 4 additions & 6 deletions src/AudioAnalysisTools/Events/Types/EventPostProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static class EventPostProcessing

public static List<EventCommon> PostProcessingOfSpectralEvents(
List<EventCommon> newEvents,
double analysisThreshold,
PostProcessingConfig postprocessingConfig,
BaseSonogram spectrogram,
TimeSpan segmentStartOffset)
Expand Down Expand Up @@ -92,11 +91,10 @@ public static List<EventCommon> PostProcessingOfSpectralEvents(
var spectralEvents2 = newEvents.Cast<SpectralEvent>().ToList();
newEvents = EventFilters.FilterEventsOnSidebandActivity(
spectralEvents2,
analysisThreshold,
spectrogram,
sidebandActivity.LowerHertzBuffer,
sidebandActivity.UpperHertzBuffer,
sidebandActivity.DecibelBuffer,
sidebandActivity.MaxAverageSidebandDecibels,
segmentStartOffset);
Log.Debug($"Event count after filtering on acoustic activity in sidebands = {newEvents.Count}");
}
Expand Down Expand Up @@ -198,11 +196,11 @@ public class SidebandConfig
public int LowerHertzBuffer { get; set; }

/// <summary>
/// Gets or sets a value indicating the decibel gap/difference between acoustic activity in the event and in the upper and lower buffer zones.
/// BufferAcousticActivity must be LessThan (EventAcousticActivity - DecibelBuffer)
/// Gets or sets a value indicating the maximum value of the average decibels of acoustic activity
/// in the upper and lower sidebands of an event. The average is over all spectrogram cells in each sideband.
/// This value is used only if LowerHertzBuffer > 0 OR UpperHertzBuffer > 0.
/// </summary>
public double DecibelBuffer { get; set; }
public double MaxAverageSidebandDecibels { get; set; }
}

/// <summary>
Expand Down

0 comments on commit 772e18d

Please sign in to comment.