Skip to content

Commit

Permalink
Get upwards tracks drawing correctly.
Browse files Browse the repository at this point in the history
Issue # 297. Also corrected some spelling mistakes.
  • Loading branch information
towsey committed Apr 17, 2020
1 parent 83eb327 commit 7ea4b8c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static (List<AcousticEvent> Events, double[] CombinedIntensity) GetFoward
}
}

var tracks = TrackExtractor.GetFowardTracks(peaks, minDuration, maxDuration, decibelThreshold, converter);
var tracks = TrackExtractor.GetForwardTracks(peaks, minDuration, maxDuration, decibelThreshold, converter);

// initialise tracks as events and get the combined intensity array.
// list of accumulated acoustic events
Expand Down
2 changes: 1 addition & 1 deletion src/AudioAnalysisTools/Events/Tracks/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public double[] GetTrackFrequencyProfile()

/// <summary>
/// Returns the maximum amplitude in each time frame.
/// TODO
/// TODO ############################################
/// </summary>
public double[] GetAmplitudeOverTimeFrames()
{
Expand Down
14 changes: 8 additions & 6 deletions src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AudioAnalysisTools.Events.Tracks

public static class TrackExtractor
{
public static List<Track> GetFowardTracks(double[,] peaks, double minDuration, double maxDuration, double threshold, UnitConverters converter)
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);
Expand All @@ -25,7 +25,7 @@ public static List<Track> GetFowardTracks(double[,] peaks, double minDuration, d
for (int col = 3; col < bandwidthBinCount - 3; col++)
{
// Visit each spectral peak in order. Each may be start of possible track
var track = GetFowardTrack(peaks, row, col, threshold, converter);
var track = GetForwardTrack(peaks, row, col, threshold, converter);

//If track has length within duration bounds, then add the track to list.
if (track.TrackDurationSeconds >= minDuration && track.TrackDurationSeconds <= maxDuration)
Expand All @@ -38,7 +38,7 @@ public static List<Track> GetFowardTracks(double[,] peaks, double minDuration, d
return tracks;
}

public static Track GetFowardTrack(double[,] peaks, int startRow, int startBin, double threshold, UnitConverters converter)
public static Track GetForwardTrack(double[,] peaks, int startRow, int startBin, double threshold, UnitConverters converter)
{
var track = new Track(converter, TrackType.FowardTrack);
track.SetPoint(startRow, startBin, peaks[startRow, startBin]);
Expand Down Expand Up @@ -136,9 +136,10 @@ public static List<Track> GetUpwardTracks(double[,] peaks, int minBin, int maxBi

// Look for possible track starts and initialise as track.
// Each row is a time frame which is a spectrum. Each column is a frequency bin
for (int row = 0; row < frameCount; row++)
// We want to scane down each freq bin starting from the bottom bin.
for (int col = minBin; col < maxBin; col++)
{
for (int col = minBin; col < maxBin; col++)
for (int row = 0; row < frameCount; row++)
{
if (peaks[row, col] < threshold)
{
Expand Down Expand Up @@ -167,8 +168,9 @@ public static Track GetUpwardTrack(double[,] peaks, int startRow, int startBin,
// set the start point in peaks matrix to zero to prevent return to this point.
peaks[startRow, startBin] = 0.0;

//Now move to next higher freq bin.
int row = startRow;
for (int bin = startBin; bin < maxBin - 1; bin++)
for (int bin = startBin + 1; bin < maxBin - 1; bin++)
{
// Avoid row edge effects.
if (row < 1 || row > peaks.GetLength(0) - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void TestHarmonicsAlgorithm()
}

[TestMethod]
public void TestFowardTrackAlgorithm()
public void TestForwardTrackAlgorithm()
{
// Set up the recognizer parameters.
var windowSize = 512;
Expand Down Expand Up @@ -598,7 +598,7 @@ public void Test2UpwardsTrackAlgorithm()
var windowStep = 512;
var minHertz = 500;
var maxHertz = 6000;
var minBandwidthHertz = 100;
var minBandwidthHertz = 200;
var maxBandwidthHertz = 5000;
var decibelThreshold = 2.0;
var combineProximalSimilarEvents = false;
Expand Down Expand Up @@ -662,7 +662,7 @@ public void Test2UpwardsTrackAlgorithm()
var outputDirectory = new DirectoryInfo("C:\\temp");
GenericRecognizer.SaveDebugSpectrogram(allResults2, null, outputDirectory, "UpwardTracks2");

Assert.AreEqual(5, allResults2.Events.Count);
Assert.AreEqual(10, allResults2.Events.Count);
}

public SpectrogramStandard CreateArtificialSpectrogramToTestTracksAndHarmonics(SonogramConfig config)
Expand Down

0 comments on commit 7ea4b8c

Please sign in to comment.