/// <summary> /// This method only called from Indexcalculate when returning image of the sonogram for the passed recording segment. /// </summary> public static double[] ConvertSpectralPeaksToNormalisedArray(double[,] spectrogram) { // convert spectral peaks to frequency and frames var tupleDecibelPeaks = SpectrogramTools.HistogramOfSpectralPeaks(spectrogram); // Item2 is length of Score Array and stores the bin in which the max peak is located. // Normalise this for display in score track return(DataTools.normalise(tupleDecibelPeaks.Item2)); }
} // CalculateSpectralEntropies() /// <summary> /// CALCULATES THE ENTROPY OF DISTRIBUTION of maximum SPECTRAL PEAKS. /// Only spectral peaks between the lowerBinBound and the upperBinBound will be included in calculation. /// </summary> public static double CalculateEntropyOfSpectralPeaks(double[,] amplitudeSpectrogram, int lowerBinBound, int upperBinBound) { // First extract High band SPECTROGRAM which is now noise reduced var midBandSpectrogram = MatrixTools.Submatrix(amplitudeSpectrogram, 0, lowerBinBound, amplitudeSpectrogram.GetLength(0) - 1, upperBinBound - 1); var tupleAmplitudePeaks = SpectrogramTools.HistogramOfSpectralPeaks(midBandSpectrogram); double entropyOfPeakFreqDistr = DataTools.EntropyNormalised(tupleAmplitudePeaks.Item1); if (double.IsNaN(entropyOfPeakFreqDistr)) { entropyOfPeakFreqDistr = 1.0; } return(entropyOfPeakFreqDistr); } // CalculateEntropyOfSpectralPeaks()
/// <summary> /// outputs an array of peak bins indices per frame /// </summary> public static int[] GetPeakBinsIndex(double[,] matrix, int minFreqBin, int maxFreqBin) { // get a submatrix with min and max frequency bins defined in settings. double[,] targetMatrix = GetArbitraryFreqBandMatrix(matrix, minFreqBin, maxFreqBin); // find the peak bins in each spectral of the target matrix int[] peakBins = SpectrogramTools.HistogramOfSpectralPeaks(targetMatrix).Item2; // map the index of peak bins in the target matrix to original input matrix for (int i = 0; i < peakBins.Length; i++) { peakBins[i] = peakBins[i] + minFreqBin - 1; } return(peakBins); }