// // Programmer: Patricio de la Cuadra // Programmer: Craig Stuart Sapp // Creation Date: Spring 2000 // Last Modified: Mon Jul 16 15:27:28 PDT 2001 // Filename: ...sig/maint/code/Filter/Pitch/Pitch_ML.cpp // Web Address: http://sig.sapp.org/src/sigSignal/Pitch_ML.cpp // Documentation: http://sig.sapp.org/doc/classes/Pitch // Syntax: C++; close to C // // Reference: Noll, Michael. ``Pitch determination of human speech by the // harmonic product spectrum, the harmonic sum spectrum, and a // maximum likelihood estimate,'' Proceedings of the Symposium // on Computer Processing in Communications, April 8-10, 1969. // #include "Pitch.h" #include #include "transforms.h" ////////////////////////////// // // ML -- Maximum Likelihood // input parameters are: // signal = array of the windows signal frame already zero padded // size = number of elements in the signal frame // minIndex = minimum frequency index to assign as a pitch // maxIndex = maximum frequency index to assign as a pitch // harmonics = number of harmonics to consider // spectrum = the spectrum values used to generate a pitch value. // (same size as paddedFrame) // tspectrum = temporary holding space for abs spectrum. // refmatrix = spectrum of test signal // csize = number of columns in refmatrix // int Pitch::ML(double* signal, int size, int minIndex, int maxIndex, double* spectrum, double* tspectrum, double** refmatrix, int csize) { int i, j; static int count = 0; count++; // generate the magnitude spectrum absfft(tspectrum, signal, 1024); /* note: normalizing will not affect the outcome double norm = 0; for (i=0; i<512; i++) { if (tspectrum[i] > norm) { norm = tspectrum[i]; } } for (i=0; i<512; i++) { tspectrum[i] = tspectrum[i] / norm; } */ // matrix multiply the absolute spectrum with the test matrix // and keep track of maximum amplitude value int maxLocation = 0; for (j=0; j spectrum[maxLocation]) { maxLocation = j; } } return maxLocation; } ////////////////////////////// // // Pitch::createMLTextMatrix -- // // parameters: // matrix = matrix to store resulting spectra in. // rows = number of rows in matrix // columns = number of columns in matrix // step = distance between columns. 1/2 = half step, 1/4 = quarter tone // harmonics = number of harmonic to consider // srate = sampling rate // window = signal window before transform (length = rows) // void Pitch::createMLRefMatrix(double** matrix, int rows, int columns, double minFreq, double step, int harmonics, double srate) { int i, j; double signal[1024]; double max = -1.0; double freq = 0.0; // generate a spectrum for each test signal // keeping track of the max amplitude for normalization for (j=0; j max) { max = matrix[j][i]; } } } // normalize the spectrum set for (j=0; j