Skip to content

Commit

Permalink
Iron bugs out of track extraction
Browse files Browse the repository at this point in the history
Issue #297
  • Loading branch information
towsey committed Apr 21, 2020
1 parent faf39a5 commit aaa3fa7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/AnalysisPrograms/Recognizers/Base/OnebinTrackParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static (List<AcousticEvent> ListOfevents, double[] CombinedIntensityArray

if (netAmplitude >= decibelThreshold)
{
peaks[tf, bin] = Math.Max(0.0, netAmplitude);
peaks[tf, bin] = sonogramData[tf, bin];
}
}
}
Expand Down Expand Up @@ -162,19 +162,19 @@ public static (List<AcousticEvent> ListOfevents, double[] CombinedIntensityArray
var combinedIntensityArray = new double[frameCount];
foreach (var track in tracks)
{
var ae = new AcousticEvent(segmentStartOffset, track.StartTimeSeconds, track.TrackDurationSeconds, track.LowFreqHertz, track.HighFreqHertz);
var tr = new List<Track>
var ae = new AcousticEvent(segmentStartOffset, track)
{
track,
SegmentDurationSeconds = frameCount * converter.StepSize,
};
ae.AddTracks(tr);

events.Add(ae);

// fill the intensity array
var startRow = converter.FrameFromStartTime(track.StartTimeSeconds);
var amplitudeTrack = track.GetAmplitudeOverTimeFrames();
for (int i = 0; i < amplitudeTrack.Length; i++)
{
//combinedIntensityArray[startRow + i] += amplitudeTrack[i];
combinedIntensityArray[startRow + i] = Math.Max(combinedIntensityArray[startRow + i], amplitudeTrack[i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,11 @@ public static (List<AcousticEvent> Events, double[] CombinedIntensity) GetUpward
var temporalIntensityArray = new double[frameCount];
foreach (var track in tracks)
{
var ae = new AcousticEvent(segmentStartOffset, track.StartTimeSeconds, track.TrackDurationSeconds, track.LowFreqHertz, track.HighFreqHertz)
var ae = new AcousticEvent(segmentStartOffset, track)
{
SegmentDurationSeconds = frameCount * frameStep,
};

var tr = new List<Track>
{
track,
};
ae.AddTracks(tr);
events.Add(ae);

// fill the intensity array
Expand Down
25 changes: 16 additions & 9 deletions src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static List<Track> GetOnebinTracks(double[,] peaks, double minDuration, d
{
for (int col = 3; col < bandwidthBinCount - 3; col++)
{
if (peaks[row, col] < threshold)
{
continue;
}

// Visit each spectral peak in order. Each may be start of possible whistle track
var track = GetOnebinTrack(peaks, row, col, threshold, converter);

Expand Down Expand Up @@ -60,7 +65,7 @@ public static Track GetOnebinTrack(double[,] peaks, int startRow, int bin, doubl
{
// explore track in vicinity.
int nhStart = Math.Max(row - 2, 0);
int nhEnd = Math.Min(row + 4, peaks.GetLength(0));
int nhEnd = Math.Min(row + 3, peaks.GetLength(0));
int nhWidth = nhEnd - nhStart + 1;
double avIntensity = 0.0;
for (int nh = nhStart; nh < nhEnd; nh++)
Expand All @@ -69,22 +74,19 @@ public static Track GetOnebinTrack(double[,] peaks, int startRow, int bin, doubl
}

avIntensity /= (double)nhWidth;
track.SetPoint(row, bin, peaks[row, bin]);

// Set visited value to zero so as not to revisit.....
peaks[row, bin] = 0.0;

// if track has come to an end
// next line is for debug purposes
//var info = track.CheckPoint(row, bin);

// Check if track has come to an end - average value is less than threshold.
if (avIntensity < threshold)
{
return track;
}

track.SetPoint(row, bin, peaks[row, bin]);

// next line is for debug purposes
//var info = track.CheckPoint(row, bin);
}

return track;
Expand All @@ -93,7 +95,7 @@ public static Track GetOnebinTrack(double[,] peaks, int startRow, int bin, doubl
public static List<Track> GetForwardTracks(double[,] peaks, double minDuration, double maxDuration, double threshold, UnitConverters converter)
{
int frameCount = peaks.GetLength(0);
int bandwidthBinCount = peaks.GetLength(1);
int binCount = peaks.GetLength(1);

var tracks = new List<Track>();

Expand All @@ -102,8 +104,13 @@ public static List<Track> GetForwardTracks(double[,] peaks, double minDuration,
// Each row is a time frame which is a spectrum. Each column is a frequency bin
for (int row = 0; row < frameCount; row++)
{
for (int col = 3; col < bandwidthBinCount - 3; col++)
for (int col = 3; col < binCount - 3; col++)
{
if (peaks[row, col] < threshold)
{
continue;
}

// Visit each spectral peak in order. Each may be start of possible track
var track = GetForwardTrack(peaks, row, col, threshold, converter);

Expand Down

0 comments on commit aaa3fa7

Please sign in to comment.