From 7ea4b8ce79a24fbf2841d5049e5f0b266712c190 Mon Sep 17 00:00:00 2001 From: towsey Date: Fri, 17 Apr 2020 16:33:07 +1000 Subject: [PATCH] Get upwards tracks drawing correctly. Issue # 297. Also corrected some spelling mistakes. --- .../Recognizers/Base/FowardTrackParameters.cs | 2 +- src/AudioAnalysisTools/Events/Tracks/Track.cs | 2 +- .../Events/Tracks/TrackExtractor.cs | 14 ++++++++------ .../GenericRecognizer/GenericRecognizerTests.cs | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/AnalysisPrograms/Recognizers/Base/FowardTrackParameters.cs b/src/AnalysisPrograms/Recognizers/Base/FowardTrackParameters.cs index c7bb67e2c..8ce97d09c 100644 --- a/src/AnalysisPrograms/Recognizers/Base/FowardTrackParameters.cs +++ b/src/AnalysisPrograms/Recognizers/Base/FowardTrackParameters.cs @@ -88,7 +88,7 @@ public static (List 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 diff --git a/src/AudioAnalysisTools/Events/Tracks/Track.cs b/src/AudioAnalysisTools/Events/Tracks/Track.cs index 2350c9548..b818f713c 100644 --- a/src/AudioAnalysisTools/Events/Tracks/Track.cs +++ b/src/AudioAnalysisTools/Events/Tracks/Track.cs @@ -188,7 +188,7 @@ public double[] GetTrackFrequencyProfile() /// /// Returns the maximum amplitude in each time frame. - /// TODO + /// TODO ############################################ /// public double[] GetAmplitudeOverTimeFrames() { diff --git a/src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs b/src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs index ed5d4cad4..3c3a5964f 100644 --- a/src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs +++ b/src/AudioAnalysisTools/Events/Tracks/TrackExtractor.cs @@ -10,7 +10,7 @@ namespace AudioAnalysisTools.Events.Tracks public static class TrackExtractor { - public static List GetFowardTracks(double[,] peaks, double minDuration, double maxDuration, double threshold, UnitConverters converter) + public static List GetForwardTracks(double[,] peaks, double minDuration, double maxDuration, double threshold, UnitConverters converter) { int frameCount = peaks.GetLength(0); int bandwidthBinCount = peaks.GetLength(1); @@ -25,7 +25,7 @@ public static List 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) @@ -38,7 +38,7 @@ public static List 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]); @@ -136,9 +136,10 @@ public static List 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) { @@ -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) diff --git a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizer/GenericRecognizerTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizer/GenericRecognizerTests.cs index d765a7a8a..99a6f72b1 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizer/GenericRecognizerTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Recognizers/GenericRecognizer/GenericRecognizerTests.cs @@ -311,7 +311,7 @@ public void TestHarmonicsAlgorithm() } [TestMethod] - public void TestFowardTrackAlgorithm() + public void TestForwardTrackAlgorithm() { // Set up the recognizer parameters. var windowSize = 512; @@ -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; @@ -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)