public static SpectralTrack GetVerticalTrack(double[,] peaks, int startRow, int startBin, int maxBin, double threshold) { var track = new SpectralTrack(SpectralTrackType.VerticalTrack, startRow, startBin, peaks[startRow, startBin]); // set the start point in peaks matrix to zero to prevent return to this point. peaks[startRow, startBin] = 0.0; int row = startRow; for (int bin = startBin; bin < maxBin - 1; bin++) { // Avoid row edge effects. if (row < 2 || row > peaks.GetLength(0) - 3) { // arrived back at start of recording or end of recording. // The track has come to end return(track); } if (bin >= maxBin) { // arrived at top of the requested frequency band - track has come to end return(track); } // explore options for track vertical double optionStraight = Math.Max(peaks[row, bin] + peaks[row, bin + 1], peaks[row, bin] + peaks[row - 1, bin + 1]); optionStraight = Math.Max(optionStraight, peaks[row, bin] + peaks[row + 1, bin + 1]); // option for track with negative slope i.e. return to previous row/frame. double optionDown = Math.Max(peaks[row - 1, bin] + peaks[row - 1, bin + 1], peaks[row - 1, bin] + peaks[row - 2, bin + 1]); optionDown = Math.Max(optionDown, peaks[row - 1, bin] + peaks[row - 1, bin + 1]); // option for track with positive slope double optionUp = Math.Max(peaks[row + 1, bin] + peaks[row + 1, bin + 1], peaks[row + 1, bin] + peaks[row + 2, bin + 1]); optionUp = Math.Max(optionUp, peaks[row + 1, bin] + peaks[row + 2, bin + 1]); // get max of the three next possible steps double[] options = { optionStraight, optionDown, optionUp }; var maxId = DataTools.GetMaxIndex(options); // Check if track has come to an end - average value of the two values is less than threshold. var maxValue = options[maxId] / 2; if (maxValue < threshold) { return(track); } // else set visited values to zero so as not to revisit..... peaks[row - 1, bin] = 0.0; peaks[row, bin] = 0.0; peaks[row + 1, bin] = 0.0; // and go to the new time frame if (maxId == 1) { row--; } else if (maxId == 2) { row++; } track.SetPoint(row, bin, maxValue); } return(track); }
public static SpectralTrack GetTrack(double[,] peaks, int startRow, int startBin, double threshold) { var track = new SpectralTrack(SpectralTrackType.HorizontalTrack, startRow, startBin, peaks[startRow, startBin]); // set the start point in peaks matrix to zero to prevent return to this point. peaks[startRow, startBin] = 0.0; int bin = startBin; for (int row = startRow + 1; row < peaks.GetLength(0) - 2; row++) { //cannot take bin value less than 3 because of edge effects. if (bin < 3) { bin = 3; } if (bin > peaks.GetLength(1) - 4) { bin = peaks.GetLength(1) - 4; } // explore options for track ahead double optionStraight = Math.Max(peaks[row, bin] + peaks[row + 1, bin], peaks[row, bin] + peaks[row + 1, bin - 1]); optionStraight = Math.Max(optionStraight, peaks[row, bin] + peaks[row + 1, bin + 1]); // option for track descent double optionDown = Math.Max(peaks[row, bin - 1] + peaks[row + 1, bin - 1], peaks[row, bin - 1] + peaks[row + 1, bin - 2]); optionDown = Math.Max(optionDown, peaks[row, bin - 1] + peaks[row + 1, bin]); // need this option for a steep track descent double optionTwoDown = Math.Max(peaks[row, bin - 2] + peaks[row + 1, bin - 2], peaks[row, bin - 2] + peaks[row + 1, bin - 1]); optionTwoDown = Math.Max(optionTwoDown, peaks[row, bin - 2] + peaks[row + 1, bin - 3]); // option for track asscent double optionUp = Math.Max(peaks[row, bin + 1] + peaks[row + 1, bin + 1], peaks[row, bin + 1] + peaks[row + 1, bin]); optionUp = Math.Max(optionUp, peaks[row, bin + 1] + peaks[row + 1, bin + 2]); // need this option for a steep track asscent double optionTwoUp = Math.Max(peaks[row, bin + 2] + peaks[row + 1, bin + 2], peaks[row, bin + 2] + peaks[row + 1, bin + 1]); optionTwoUp = Math.Max(optionTwoUp, peaks[row, bin + 2] + peaks[row + 1, bin + 3]); // get max of the five next possible steps double[] options = { optionStraight, optionDown, optionUp, optionTwoDown, optionTwoUp }; //double[] options = { optionStraight, optionDown, optionUp, 0.0, 0.0 }; var maxId = DataTools.GetMaxIndex(options); // if track has come to an end var maxValue = options[maxId] / 2; if (maxValue < threshold) { break; } // else set bins to zero so as not to revisit..... for (int col = -2; col <= 2; col++) { peaks[row, bin + col] = 0.0; } // and go to the new frequency bin if (maxId == 1) { bin--; } else if (maxId == 2) { bin++; } else if (maxId == 3) { bin -= 2; } else if (maxId == 4) { bin += 2; } track.SetPoint(row, bin, maxValue); } return(track); }