Skip to content

Commit

Permalink
Update MFCCStuff.cs
Browse files Browse the repository at this point in the history
Issue #471 More explanatory comments.
  • Loading branch information
towsey committed Jun 12, 2021
1 parent ab7ee01 commit 236d9a4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/AudioAnalysisTools/DSP/MFCCStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,24 +524,38 @@ public static double InverseHerzTranform(double m, double c, double div)
}

/// <summary>
/// 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.
/// </summary>
/// <param name="spectrumLength">Same as bin count or filter bank count ie length of spectrum = N.</param>
/// <param name="coeffCount">count of coefficients.</param>
public static double[,] Cosines(int spectrumLength, int coeffCount)
/// <param name="signalLength">The length of the signal to be processed. e.g. the frequency bin count or filter bank count or ...</param>
/// <param name="coeffCount">The number of basis funcitons = the rquired number of DCT coefficients.</param>
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;
}

Expand Down

0 comments on commit 236d9a4

Please sign in to comment.