Skip to content

Commit

Permalink
Update AnthusNovaeseelandiae.cs
Browse files Browse the repository at this point in the history
Issue #321 Removed unused method.
  • Loading branch information
towsey committed Jun 12, 2020
1 parent a5574d2 commit 14e041d
Showing 1 changed file with 3 additions and 64 deletions.
67 changes: 3 additions & 64 deletions src/AnalysisPrograms/Recognizers/Birds/AnthusNovaeseelandiae.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ public static List<EventCommon> FilterEventsOnFrequencyProfile(List<EventCommon>
var componentEvents = ev.ComponentEvents;
var points = EventExtentions.GetCompositeTrack(componentEvents).ToArray();

// Uncomment this line when want to see the composite track profile.
//WriteFrequencyProfile(points);

// For Pipit require minimum of four frames duration.
var length = points.Length;
if (length < 4)
{
continue;
}

//WriteFrequencyProfile(points);

// Only select events having strong downward slope in spectrogram.
var avFirstTwoEvents = (points[0].Hertz.Minimum + points[0].Hertz.Minimum) / 2;
var avLastTwoEvents = (points[length - 1].Hertz.Minimum + points[length - 2].Hertz.Minimum) / 2;
Expand All @@ -167,70 +168,8 @@ public static List<EventCommon> FilterEventsOnFrequencyProfile(List<EventCommon>
return returnEvents;
}

/// <summary>
/// The Boobook call syllable is shaped like an inverted "U". Its total duration is close to 0.15 seconds.
/// The rising portion lasts for 0.06s, followed by a turning portion, 0.03s, followed by the decending portion of 0.06s.
/// The constants for this method were obtained from the calls in a Gympie recording obtained by Yvonne Phillips.
/// </summary>
/// <param name="ev">An event containing at least one forward track i.e. a chirp.</param>
public static void SetFrequencyProfileScore(ChirpEvent ev)
{
const double risingDuration = 0.06;
const double gapDuration = 0.03;
const double fallingDuration = 0.06;

var track = ev.Tracks.First();
var profile = track.GetTrackFrequencyProfile().ToArray();

// get the first point
var firstPoint = track.Points.First();
var frameDuration = firstPoint.Seconds.Maximum - firstPoint.Seconds.Minimum;
var risingFrameCount = (int)Math.Floor(risingDuration / frameDuration);
var gapFrameCount = (int)Math.Floor(gapDuration / frameDuration);
var fallingFrameCount = (int)Math.Floor(fallingDuration / frameDuration);

var startSum = 0.0;
if (profile.Length >= risingFrameCount)
{
for (var i = 0; i <= risingFrameCount; i++)
{
startSum += profile[i];
}
}

int startFrame = risingFrameCount + gapFrameCount;
int endFrame = startFrame + fallingFrameCount;
var endSum = 0.0;
if (profile.Length >= endFrame)
{
for (var i = startFrame; i <= endFrame; i++)
{
endSum += profile[i];
}
}

// set score to 1.0 if the profile has inverted U shape.
double score = 0.0;
if (startSum > 0.0 && endSum < 0.0)
{
score = 1.0;
}

ev.FrequencyProfileScore = score;
}

/// <summary>
/// .
/// </summary>
/// <param name="points">List of spectral points.</param>
public static void WriteFrequencyProfile(ISpectralPoint[] points)
{
/* Here are the frequency profiles of some events.
* Note that the first five frames (0.057 seconds) have positive slope and subsequent frames have negative slope.
* The final frames are likely to be echo and to be avoided.
* Therefore take the first 0.6s to calculate the positive slope, leave a gap of 0.025 seconds and then get negative slope from the next 0.6 seconds.
*/

if (points != null)
{
var str = $"Track({points[0].Seconds.Minimum:F2}):";
Expand Down

0 comments on commit 14e041d

Please sign in to comment.