Skip to content

Commit

Permalink
insert configs into generic recogniser classes
Browse files Browse the repository at this point in the history
Issue #281  insert configs into generic recogniser classes
  • Loading branch information
towsey committed Jan 26, 2020
1 parent 0d255d4 commit 262dde4
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,59 @@ ResampleRate: 22050
# SegmentDuration: units=seconds;
SegmentDuration: 60
# SegmentOverlap: units=seconds;
SegmentOverlap: 0
SegmentOverla: 0

# Each of these profiles will be analyzed
Profiles:
Territorial:
Algorithm: BlobRecognizer
Parameters:
FrameSize: 512
FrameStep: 512
# min and max of the freq band to search
MinHz: 800
MaxHz: 8000
BottomHzBuffer: 400
TopHzBuffer: 0
MinDuration: 0.15
MaxDuration: 0.8
DecibelThreshold: 9.0
Wingbeats:
Algorithm: OscillationRecognizer
Parameters:
# MinHz: 200
# MaxHz: 2000
# DecibelThreshold: 6.0
# duration of DCT in seconds
# DctDuration: 0.5
# minimum acceptable value of a DCT coefficient
# DctThreshold: 0.5
# ignore oscillation rates below the min & above the max threshold
# A sample of four wingbeats yielded an average of 5.1 +/-0.5 beats/s.
# 95% confidence interval (2 SDs) is therefore approx 4-6 beats/s.
# OSCILLATIONS PER SECOND
# MinOscilFreq: 4
# MaxOscilFreq: 6
# Minimum and maximum duration for the length of a true call.
# MinDuration: 1.0
# MaxDuration: 10.0
# Event threshold - use this to determine FP / FN trade-off for events.
# EventThreshold: 0.5
#Agonist:
# This notation means the Groote profile has all of the settings that the Standard profile has,
# however, the MinHz and MaxHz properties have been overridden.
# <<: *STANDARD
# DctDuration: 0.3
FrameSize: 512
FrameStep: 512
MinHz: 200
MaxHz: 2000
DecibelThreshold: 6.0
# duration of DCT in seconds
DctDuration: 0.5
# minimum acceptable value of a DCT coefficient
DctThreshold: 0.5
# ignore oscillation rates below the min & above the max threshold
# A sample of four wingbeats yielded an average of 5.1 +/-0.5 beats/s.
# 95% confidence interval (2 SDs) is therefore approx 4-6 beats/s.
# OSCILLATIONS PER SECOND
MinOscilFreq: 4
MaxOscilFreq: 6
# Minimum and maximum duration for the length of a true call.
MinDuration: 1.0
MaxDuration: 10.0
# Event threshold - use this to determine FP / FN trade-off for events.
EventThreshold: 0.5


# Common settings
#Standard: &STANDARD
#EventThreshold: 0.2
# Common settings
#BgNoiseThreshold: 3.0

# This notation means the a profile has all of the settings that the Standard profile has,
# however, the DctDuration parameter has been overridden.
# <<: *STANDARD
# DctDuration: 0.3




# Available options (case-sensitive): [False/Never | True/Always | WhenEventsDetected]
Expand Down
56 changes: 53 additions & 3 deletions src/AnalysisPrograms/Recognizers/GenericBlobRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,58 @@ namespace Recognizers

public class GenericBlobRecognizer
{
public class BlobConfig
{
/// <summary>
/// Gets or sets the frame or Window size, i.e. number of signal samples. Must be power of 2. Typically 512.
/// </summary>
public int FrameSize { get; set; }

/// <summary>
/// Gets or sets the frame or Window step i.e. before start of next frame.
/// The overlap can be any number of samples but less than the frame length/size.
/// </summary>
public int FrameStep { get; set; }

/// <summary>
/// Gets or sets the bottom bound of the rectangle. Units are Hertz.
/// </summary>
public int MinHz { get; set; }

/// <summary>
/// Gets or sets the the top bound of the rectangle. Units are Hertz.
/// </summary>
public int MaxHz { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) below the blob rectangle. Units are Hertz.
/// </summary>
public int BottomHzBuffer { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) above the blob rectangle. Units are Hertz.
/// Quite often this will be set to zero Herz because upper bounds variable, depending on distance of the source.
/// </summary>
public int TopHzBuffer { get; set; }

/// <summary>
/// Gets or sets the minimum allowed duration of the acoustic event. Units are seconds.
/// </summary>
public double MinDuration { get; set; }

/// <summary>
/// Gets or sets the maximum allowed duration of the acoustic event. Units are seconds.
/// </summary>
public double MaxDuration { get; set; }

/// <summary>
/// Gets or sets the threshold of "loudness" of an acoustic event. Units are decibels.
/// </summary>
public double DecibelThreshold { get; set; }
}

/// <summary>
/// THis method does the work.
/// Detects a concentration of acoustic energy that falls within the bounds of a rectangle.
/// </summary>
/// <param name="audioRecording">the recording.</param>
/// <param name="configuration">the config file.</param>
Expand All @@ -28,8 +78,8 @@ public static RecognizerResults BlobRecognizer(AudioRecording audioRecording, Co
ConfigFile.TryGetProfile(configuration, profileName, out var profile);

// get the common properties
string speciesName = configuration[AnalysisKeys.SpeciesName] ?? "Pteropus species";
string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? "Pteropus";
string speciesName = configuration[AnalysisKeys.SpeciesName] ?? profileName;
string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? profileName;

// The following parameters worked well on a ten minute recording containing 14-16 calls.
// Note: if you lower the dB threshold, you need to increase maxDurationSeconds
Expand Down
77 changes: 77 additions & 0 deletions src/AnalysisPrograms/Recognizers/GenericOscillationRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,83 @@ namespace Recognizers

public class GenericOscillationRecognizer
{
public class OscillationConfig
{
/// <summary>
/// Gets or sets the frame or Window size, i.e. number of signal samples. Must be power of 2. Typically 512.
/// </summary>
public int FrameSize { get; set; }

/// <summary>
/// Gets or sets the frame or Window step i.e. before start of next frame.
/// The overlap can be any number of samples but less than the frame length/size.
/// </summary>
public int FrameStep { get; set; }

/// <summary>
/// Gets or sets the bottom bound of the rectangle. Units are Hertz.
/// </summary>
public int MinHz { get; set; }

/// <summary>
/// Gets or sets the the top bound of the rectangle. Units are Hertz.
/// </summary>
public int MaxHz { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) below the blob rectangle. Units are Hertz.
/// </summary>
public int BottomHzBuffer { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) above the blob rectangle. Units are Hertz.
/// Quite often this will be set to zero Herz because upper bounds variable, depending on distance of the source.
/// </summary>
public int TopHzBuffer { get; set; }

/// <summary>
/// Gets or sets the minimum allowed duration of the acoustic event. Units are seconds.
/// </summary>
public double MinDuration { get; set; }

/// <summary>
/// Gets or sets the maximum allowed duration of the acoustic event. Units are seconds.
/// </summary>
public double MaxDuration { get; set; }

/// <summary>
/// Gets or sets the threshold of "loudness" of an acoustic event. Units are decibels.
/// </summary>
public double DecibelThreshold { get; set; }

/// <summary>
/// Gets or sets the time duration (in seconds) of a Discrete Cosine Transform.
/// </summary>
public double DctDuration { get; set; }

/// <summary>
/// Gets or sets the minimum acceptable value of a DCT coefficient.
/// </summary>
public double DctThreshold { get; set; }

/// <summary>
/// Gets or sets the minimum OSCILLATIONS PER SECOND
/// Ignore oscillation rates below the min & above the max threshold.
/// </summary>
public int MinOscilFreq { get; set; }

/// <summary>
/// Gets or sets the maximum OSCILLATIONS PER SECOND
/// Ignore oscillation rates below the min & above the max threshold.
/// </summary>
public int MaxOscilFreq { get; set; }

/// <summary>
/// Gets or sets the Event threshold - use this to determine FP / FN trade-off for events.
/// </summary>
public double EventThreshold { get; set; }
}

/// <summary>
/// THis method does the work.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/AnalysisPrograms/Recognizers/GenericRecognizers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ public override RecognizerResults Recognize(
RecognizerResults results = new RecognizerResults();

var algorithmName = profile.GetString("Algorithm");
//var parameters = profile.GetString("Parameters");
var parameters = profile.GetString("Parameters");

switch (algorithmName)
{
case "BlobRecognizer":
GrLog.Info(" Use algorithm One: " + algorithmName);
// var blobConfig = genericConfig.ToDictionary<string, string>();

results = GenericBlobRecognizer.BlobRecognizer(audioRecording, genericConfig, name, segmentStartOffset);
GrLog.Debug(name + " event count = " + results.Events.Count);
break;
Expand Down
64 changes: 58 additions & 6 deletions src/AnalysisPrograms/Recognizers/GenericWhistleRecognizer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// <copyright file="GenericWhistleRecognizer.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>

namespace AudioAnalysisTools.RecognizerTools
{
class GenericWhistleRecognizer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class GenericWhistleRecognizer
{
public class WhistleConfig
{
/// <summary>
/// Gets or sets the frame or Window size, i.e. number of signal samples. Must be power of 2. Typically 512.
/// </summary>
public int FrameSize { get; set; }

/// <summary>
/// Gets or sets the frame or Window step i.e. before start of next frame.
/// The overlap can be any number of samples but less than the frame length/size.
/// </summary>
public int FrameStep { get; set; }

/// <summary>
/// Gets or sets the bottom bound of the band in which whistle must occur. Units are Hertz.
/// </summary>
public int MinHz { get; set; }

/// <summary>
/// Gets or sets the the top bound of the band in which whistle must occur. Units are Hertz.
/// </summary>
public int MaxHz { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) below the whistle band. Units are Hertz.
/// </summary>
public int BottomHzBuffer { get; set; }

/// <summary>
/// Gets or sets the buffer (bandwidth of silence) above the whistle band. Units are Hertz.
/// </summary>
public int TopHzBuffer { get; set; }

/// <summary>
/// Gets or sets the minimum allowed duration of the whistle. Units are seconds.
/// </summary>
public double MinDuration { get; set; }

/// <summary>
/// Gets or sets the maximum allowed duration of the whistle. Units are seconds.
/// </summary>
public double MaxDuration { get; set; }

/// <summary>
/// Gets or sets the threshold of "loudness" of a whistle. Units are decibels.
/// </summary>
public double DecibelThreshold { get; set; }
}
}
}

0 comments on commit 262dde4

Please sign in to comment.