diff --git a/src/AudioAnalysisTools/DSP/MFCCStuff.cs b/src/AudioAnalysisTools/DSP/MFCCStuff.cs index cfa6f2114..6148cdb9c 100644 --- a/src/AudioAnalysisTools/DSP/MFCCStuff.cs +++ b/src/AudioAnalysisTools/DSP/MFCCStuff.cs @@ -524,24 +524,38 @@ public static double InverseHerzTranform(double m, double c, double div) } /// - /// cosines. + /// Returns a matrix of cosine basis functions. + /// These are prepared prior to performing a DCT, Discrete Cosine Transform. + /// The rows k = 0 to coeffCount are the basis functions. + /// The columns, m = 0 to M where M = signalLength or the length of the required DCT. + /// The value of m/M ranges from 0 to 1.0. + /// The value of Pi*m/M ranges from 0 to Pi radians. + /// The value of k*Pi*m/M ranges from 0 to k*Pi radians. WHen k=2, 2Pi radians corresponds to one rotation. /// - /// Same as bin count or filter bank count ie length of spectrum = N. - /// count of coefficients. - public static double[,] Cosines(int spectrumLength, int coeffCount) + /// The length of the signal to be processed. e.g. the frequency bin count or filter bank count or ... + /// The number of basis funcitons = the rquired number of DCT coefficients. + public static double[,] Cosines(int signalLength, int coeffCount) { - double[,] cosines = new double[coeffCount + 1, spectrumLength]; //get an extra coefficient because do not want DC coeff + double[,] cosines = new double[coeffCount + 1, signalLength]; //get an extra coefficient because do not want DC coeff at [0]. for (int k = 0; k < coeffCount + 1; k++) { - double kPiOnM = k * Math.PI / spectrumLength; + double kPiOnM = k * Math.PI / signalLength; // for each spectral bin - for (int m = 0; m < spectrumLength; m++) + for (int m = 0; m < signalLength; m++) { cosines[k, m] = Math.Cos(kPiOnM * (m + 0.5)); //can also be Cos(kPiOnM * (m - 0.5) } } + //following two lines write matrix of cos values for checking. + //string txtPath = @"C:\temp\cosines.txt"; + //FileTools.WriteMatrix2File_Formatted(cosines, txtPath, "F3"); + + //following two lines write bmp image of cos values for checking. + //string bmpPath = @"C:\temp\cosines.png"; + //ImageTools.DrawMatrix(cosines, bmpPath, true); + return cosines; }