-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work on whistle algorithm #477
Changes from 4 commits
f7e0adb
2e58655
d743f11
2aed2b1
42552f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,11 @@ public static (List<EventCommon> Events, List<Plot> DecibelPlots) GetOnebinTrack | |
segmentStartOffset, | ||
decibelThreshold.Value); | ||
|
||
foreach (var ev in events) | ||
{ | ||
ev.Name = profileName; | ||
} | ||
|
||
spectralEvents.AddRange(events); | ||
|
||
var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Whistles:{decibelThreshold.Value:F0}dB)", decibelThreshold.Value); | ||
|
@@ -66,8 +71,22 @@ public static (List<EventCommon> ListOfevents, double[] CombinedIntensityArray) | |
int binCount = sonogramData.GetLength(1); | ||
int nyquist = sonogram.NyquistFrequency; | ||
double binWidth = nyquist / (double)binCount; | ||
int minBin = (int)Math.Round(parameters.MinHertz.Value / binWidth); | ||
int maxBin = (int)Math.Round(parameters.MaxHertz.Value / binWidth); | ||
|
||
// set lower frequency bins of the search band | ||
int minSearchBin = (int)Math.Floor(parameters.SearchbandMinHertz.Value / binWidth); | ||
if (minSearchBin < 1) | ||
{ | ||
minSearchBin = 1; | ||
} | ||
|
||
// set top search bin allowing for the top sideband. | ||
int maxSearchBin = (int)Math.Floor(parameters.SearchbandMaxHertz.Value / binWidth) - 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The incorrect parameters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have made the corrections as requested. I have also made an extensive class summary for the OneBinTrackAlgorithm class i.e. the class used to find whistles. I hope this will be helpful in understanding the algorithm and explaining the "magic numbers". In fact all the track algorithms require that a lot of thought be given to the choice of sample rate, frame size and frame step. The typical values are not always appropriate depending on the target call. |
||
if (maxSearchBin > binCount - 6) | ||
{ | ||
maxSearchBin = binCount - 6; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this magic number |
||
} | ||
|
||
// get max and min duration for the whistle event. | ||
double minDuration = parameters.MinDuration.Value; | ||
double maxDuration = parameters.MaxDuration.Value; | ||
|
||
|
@@ -79,20 +98,23 @@ public static (List<EventCommon> ListOfevents, double[] CombinedIntensityArray) | |
|
||
//Find all bin peaks and place in peaks matrix | ||
var peaks = new double[frameCount, binCount]; | ||
|
||
// tf = timeframes | ||
for (int tf = 0; tf < frameCount; tf++) | ||
{ | ||
for (int bin = minBin + 1; bin < maxBin - 1; bin++) | ||
for (int bin = minSearchBin; bin <= maxSearchBin; bin++) | ||
{ | ||
if (sonogramData[tf, bin] < decibelThreshold) | ||
{ | ||
continue; | ||
} | ||
|
||
// here we define the amplitude profile of a whistle. The buffer zone around whistle is five bins wide. | ||
// here we define the amplitude profile of a whistle. | ||
// The buffer zone around centre of whistle is five bins wide. Ignore bins -2 and +2 | ||
var bandIntensity = ((sonogramData[tf, bin - 1] * 0.5) + sonogramData[tf, bin] + (sonogramData[tf, bin + 1] * 0.5)) / 2.0; | ||
var topSidebandIntensity = (sonogramData[tf, bin + 3] + sonogramData[tf, bin + 4] + sonogramData[tf, bin + 5]) / 3.0; | ||
var netAmplitude = 0.0; | ||
if (bin < 4) | ||
if (bin < 5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More magic numbers |
||
{ | ||
netAmplitude = bandIntensity - topSidebandIntensity; | ||
} | ||
|
@@ -138,7 +160,7 @@ public static (List<EventCommon> ListOfevents, double[] CombinedIntensityArray) | |
{ | ||
SegmentStartSeconds = segmentStartOffset.TotalSeconds, | ||
SegmentDurationSeconds = frameCount * converter.SecondsPerFrameStep, | ||
Name = "Whistle", | ||
Name = "Whistle", // this name can be overridden later. | ||
}; | ||
|
||
events.Add(ae); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,16 @@ namespace AnalysisPrograms.Recognizers.Base | |
[YamlTypeTag(typeof(OnebinTrackParameters))] | ||
public class OnebinTrackParameters : CommonParameters | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating the minimum Hertz value of the search band. | ||
/// </summary> | ||
public int? SearchbandMinHertz { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating the maximum Hertz value of the search band. | ||
/// </summary> | ||
public int? SearchbandMaxHertz { get; set; } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These do not appear to be used. They're redundant? Remove? |
||
/// <summary> | ||
/// Gets or sets a value indicating whether proximal whistle tracks are to be combined. | ||
/// Proximal means the whistle tracks are in the same frequency band | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this validation is disabled?
Revert change or delete validation (and explain).