# Pitch Change Demonstration Code

This m-file demonstrates how to use the Pitch Change Toolkit to calculate how the pitch of a signal changes. Often a single value for the pitch is hard to calculate due to octave ambiguities and other effects at the onset and offset of voicing. But the change in pitch is usually what we care about, and this is easier to calculate.

## Contents

- Preliminaries
- Read audio and model for testing.
- Calculate the necessary correlograms
- Estimate the pitch probabilities of the test sound
- Estimate the pitch (Hz) at each time and plot the results.
- Pitch Change
- Compute a new pitch model
- Measure new pitch model's performance

## Preliminaries

We need both the Auditory Toolbox and Nabney's Netlab. Make sure we have the tools we need on our path. Change these directory names to suit your own installation.

    if ~exist('ERBFilterBank', 'file')
    	path(path, '../../AuditoryToolbox');    % Add the Auditory Toolbox
    end

    if ~exist('mlpfwd', 'file')
        path(path, '../../Netlab');             % Add Netlab for machine learning
    end
    colormap('default');

## Read audio and model for testing.

Lets first test an exisiting pitch model. Read in an audio file and the pitch model

    load grazPitchModel.mat

    [inputSound,inputFs] = audioread('testSpeech.wav');

## Calculate the necessary correlograms

Next we calculate the correlograms of the sound. This requires a cochlear filter bank (gammatone) and the auto-correlation calculation. The correlogram image is unwound and is stored as one column in the correlogramData file.

We can then display one frame of the correlogram (the one frame with the most energy, which is voiced speech.)

    frameRate = 100;
    frameWidth = 512;
    [correlogramData, frameRate, numChannels] = PitchCorrelogram(inputSound, inputFs, frameRate, frameWidth);

    if 1
        frameEnergy = sum(correlogramData.^2);
        [m,i] = max(frameEnergy);           % Find the most energetic frame for plotting
        clf; imagesc(reshape(correlogramData(:,i), [], frameWidth));
        xlabel('Autocorrelation Delay (tau in samples)');
        ylabel('Cochlear Channel');
        title('A Correlogram Frame');
    end

## Estimate the pitch probabilities of the test sound

Given the correlogram, use PCA to reduce its dimensionality, and then use an MLP (multi-layer perceptron) to estimate the pitch-class probability at each time.

    pcaPitch = PCATransform(correlogramData, pitchModel.pcaModel);

    quantizedPitchEvidence = mlpfwd(pitchModel.mlpModel, pcaPitch')';

    % The output is an estimate of the pitch class, as a function of time
    % (frame number, 100 frames/second).
    imagesc(quantizedPitchEvidence);
    xlabel('Frame Number'); ylabel('Pitch Class'); title('Pitch Probabilities');
    axis xy
    % Pitch Class 1 (row 1 in the image below) is used to indicate unvoiced.

## Estimate the pitch (Hz) at each time and plot the results.

Use a Viterbi search to find the optimum tradeoff between observations, prior pitch probabilities, and the pitch-class transition probabilities.

    fileStruct = struct('mlpCorrelogram', quantizedPitchEvidence);
    [viterbiPitch,statePath,pObservations,pTransitions] = ...
        CalculateViterbiPitch(fileStruct, pitchModel);

## Pitch Change

Now estimate the pitch-change signal (by correlating neighboring pitch-probability estimates) and plot the results. The pitch model estimates the likelihood of each possible pitch. We correlate this vector (one dimension per pitch class) over time to get the pitch-change signal. In the plot below, the gray-scale image shows the pitch-change probability signal (computed by correlating over time). While the blue line shows the "exact" position of the peak, computed by fitting the quadratic curve to the peak, and using super-resolution.

    smoothWindowLength = 5;
    debug = 0;
    [deltaPitch, pitchChanges] = PitchChange(quantizedPitchEvidence, smoothWindowLength, debug);

    clf; colormap(1-gray);
    nT = floor(size(pitchChanges,1));
    imagesc(1:size(pitchChanges,2), -nT:nT, pitchChanges);
    hold on;
    cleanPitchChange = deltaPitch;
    cleanPitchChange(isnan(viterbiPitch)) = nan;
    plot(1:size(cleanPitchChange,2), cleanPitchChange);
    hold off;
    xlabel('Frame Number'); ylabel('Pitch Change Signal');
    ylim([-6 6])            % Only care about the center of this change signal

## Compute a new pitch model

The ComputePitchModel routine does all the necessary work to create a new pitch model. It starts with a database name and does the following: 1) Compute all correlograms 2) Find the best PCA model to approximate each correlogram data 3) Reduces the dimensionality of the correlogram data 4) Find best MLP (multi-layer perceptron) to estimate the pitch class All the results are returned in a pitchModel struct, which stores all the necessary data so we can compute with this model.

The MLP training code splits the data so 75% is used for training and 25% is used for testing. The training/testing results are sorted by their true pitch, so the correct result should be monotonic.

This step takes a while.

    pcaThresh = 5;
    databaseToUse = 'graz';
    % We can't fit all the data into memory at once (to compute the PCA) so we
    % subsample the training data.
    fileList = FindPitchFiles(databaseToUse);
    filesToUse = 1:10:length(fileList);         % Big training exercise
    filesToUse = 1:100:length(fileList);        % Small training example
    tic;
    [pitchModel, fileList] = ComputePitchModel('graz', pcaThresh, [], filesToUse);
    save newPitchModel pitchModel
    toc;

    FindFiles: Checking ../PitchTrackingDatabase/Graz for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/LAR/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/FEMALE/REF/F10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/LAR/M10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/MIC/M10 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M01 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M02 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M03 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M04 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M05 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M06 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M07 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M08 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M09 for .f0
    FindFiles: Checking ../PitchTrackingDatabase/Graz/MALE/REF/M10 for .f0
    Finding pitch transition probabilities for 48 files.
    Computing correlogram features for 48 sounds.....
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_sa1.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_si551.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_sx19.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02/mic_F02_si704.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02/mic_F02_si804.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_si837.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_si937.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_sx137.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04/mic_F04_si1110.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04/mic_F04_sx139.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05/mic_F05_si1263.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05/mic_F05_si1363.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_si1416.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_si1516.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_sx257.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07/mic_F07_si1669.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07/mic_F07_si1769.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08/mic_F08_si1822.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08/mic_F08_si1924.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_si1977.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_si2077.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_sx386.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10/mic_F10_si2230.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10/mic_F10_si2330.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M01/mic_M01_si493.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M01/mic_M01_si593.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_si646.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_si746.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_sx63.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M03/mic_M03_si879.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M03/mic_M03_si979.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_si1052.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_si1152.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_sx181.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M05/mic_M05_si1305.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M05/mic_M05_sx190.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M06/mic_M06_si1458.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M06/mic_M06_si1558.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_si1611.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_si1711.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_sx308.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M08/mic_M08_si1864.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M08/mic_M08_si1964.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M09/mic_M09_si2017.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M09/mic_M09_si2117.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_si2170.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_si2270.mat...
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_sx435.mat...
    Finding PCA model with a energy threshold of 5 x Mean Energy
    Channel 1: Computing the principal components of a 512 x 10257 matrix
    Channel 2: Computing the principal components of a 512 x 10257 matrix
    Channel 3: Computing the principal components of a 512 x 10257 matrix
    Channel 4: Computing the principal components of a 512 x 10257 matrix
    Channel 5: Computing the principal components of a 512 x 10257 matrix
    Channel 6: Computing the principal components of a 512 x 10257 matrix
    Channel 7: Computing the principal components of a 512 x 10257 matrix
    Channel 8: Computing the principal components of a 512 x 10257 matrix
    Channel 9: Computing the principal components of a 512 x 10257 matrix
    Channel 10: Computing the principal components of a 512 x 10257 matrix
    Channel 11: Computing the principal components of a 512 x 10257 matrix
    Channel 12: Computing the principal components of a 512 x 10257 matrix
    Channel 13: Computing the principal components of a 512 x 10257 matrix
    Channel 14: Computing the principal components of a 512 x 10257 matrix
    Channel 15: Computing the principal components of a 512 x 10257 matrix
    Channel 16: Computing the principal components of a 512 x 10257 matrix
    Channel 17: Computing the principal components of a 512 x 10257 matrix
    Channel 18: Computing the principal components of a 512 x 10257 matrix
    Channel 19: Computing the principal components of a 512 x 10257 matrix
    Channel 20: Computing the principal components of a 512 x 10257 matrix
    Channel 21: Computing the principal components of a 512 x 10257 matrix
    Channel 22: Computing the principal components of a 512 x 10257 matrix
    Channel 23: Computing the principal components of a 512 x 10257 matrix
    Channel 24: Computing the principal components of a 512 x 10257 matrix
    Channel 25: Computing the principal components of a 512 x 10257 matrix
    Channel 26: Computing the principal components of a 512 x 10257 matrix
    Channel 27: Computing the principal components of a 512 x 10257 matrix
    Channel 28: Computing the principal components of a 512 x 10257 matrix
    Channel 29: Computing the principal components of a 512 x 10257 matrix
    Channel 30: Computing the principal components of a 512 x 10257 matrix
    Channel 31: Computing the principal components of a 512 x 10257 matrix
    Channel 32: Computing the principal components of a 512 x 10257 matrix
    Channel 33: Computing the principal components of a 512 x 10257 matrix
    Channel 34: Computing the principal components of a 512 x 10257 matrix
    Channel 35: Computing the principal components of a 512 x 10257 matrix
    Channel 36: Computing the principal components of a 512 x 10257 matrix
    Channel 37: Computing the principal components of a 512 x 10257 matrix
    Channel 38: Computing the principal components of a 512 x 10257 matrix
    Channel 39: Computing the principal components of a 512 x 10257 matrix
    Channel 40: Computing the principal components of a 512 x 10257 matrix
    Channel 41: Computing the principal components of a 512 x 10257 matrix
    Channel 42: Computing the principal components of a 512 x 10257 matrix
    Channel 43: Computing the principal components of a 512 x 10257 matrix
    Channel 44: Computing the principal components of a 512 x 10257 matrix
    Channel 45: Computing the principal components of a 512 x 10257 matrix
    Channel 46: Computing the principal components of a 512 x 10257 matrix
    Channel 47: Computing the principal components of a 512 x 10257 matrix
    Channel 48: Computing the principal components of a 512 x 10257 matrix
    Finding the MLP model to transform correlogram into pitch probs.
    Cycle    1  Error 384017.579882  Scale 1.000000e+00
    Cycle    2  Error 247910.885624  Scale 5.000000e-01
    Cycle    3  Error 84778.699611  Scale 2.500000e-01
    Cycle    4  Error 68258.050248  Scale 1.250000e-01
    Cycle    5  Error 51694.628885  Scale 6.250000e-02
    Cycle    6  Error 49270.981352  Scale 3.125000e-02
    Cycle    7  Error 45128.698215  Scale 1.562500e-02
    Cycle    8  Error 43585.996495  Scale 7.812500e-03
    Cycle    9  Error 41059.158424  Scale 3.906250e-03
    Cycle   10  Error 40370.004812  Scale 1.953125e-03
    Cycle   11  Error 39716.878648  Scale 9.765625e-04
    Cycle   12  Error 38532.608195  Scale 4.882813e-04
    Cycle   13  Error 37773.938644  Scale 2.441406e-04
    Cycle   14  Error 36982.788449  Scale 1.220703e-04
    Cycle   15  Error 36422.579200  Scale 6.103516e-05
    Cycle   16  Error 35689.625875  Scale 3.051758e-05
    Cycle   17  Error 35387.597617  Scale 1.525879e-05
    Cycle   18  Error 34933.943780  Scale 7.629395e-06
    Cycle   19  Error 34797.095434  Scale 3.814697e-06
    Cycle   20  Error 34400.046941  Scale 1.907349e-06
    Cycle   21  Error 34131.079231  Scale 9.536743e-07
    Cycle   22  Error 33693.202658  Scale 4.768372e-07
    Cycle   23  Error 33693.202658  Scale 2.384186e-07
    Cycle   24  Error 33693.202658  Scale 9.536743e-07
    Cycle   25  Error 33693.202658  Scale 3.814697e-06
    Cycle   26  Error 33693.202658  Scale 1.525879e-05
    Cycle   27  Error 33693.202658  Scale 6.103516e-05
    Cycle   28  Error 33693.202658  Scale 2.441406e-04
    Cycle   29  Error 33693.202658  Scale 9.765625e-04
    Cycle   30  Error 33693.202658  Scale 3.906250e-03
    Cycle   31  Error 33693.202658  Scale 1.562500e-02
    Cycle   32  Error 33693.202658  Scale 6.250000e-02
    Cycle   33  Error 33693.202658  Scale 2.500000e-01
    Cycle   34  Error 33693.202658  Scale 1.000000e+00
    Cycle   35  Error 33693.202658  Scale 4.000000e+00
    Cycle   36  Error 33693.202658  Scale 1.600000e+01
    Cycle   37  Error 33693.202658  Scale 6.400000e+01
    Cycle   38  Error 33452.100798  Scale 2.560000e+02
    Cycle   39  Error 32831.630923  Scale 2.560000e+02
    Cycle   40  Error 32384.020578  Scale 1.280000e+02
    Cycle   41  Error 32326.306516  Scale 6.400000e+01
    Cycle   42  Error 31767.447157  Scale 3.200000e+01
    Cycle   43  Error 31566.401279  Scale 1.600000e+01
    Cycle   44  Error 30461.309360  Scale 8.000000e+00
    Cycle   45  Error 30274.834012  Scale 4.000000e+00
    Cycle   46  Error 29563.949413  Scale 2.000000e+00
    Cycle   47  Error 29446.404319  Scale 1.000000e+00
    Cycle   48  Error 29262.911287  Scale 5.000000e-01
    Cycle   49  Error 29210.158410  Scale 2.500000e-01
    Cycle   50  Error 29085.796155  Scale 1.250000e-01
    Cycle   51  Error 28878.632287  Scale 6.250000e-02
    Cycle   52  Error 28556.024788  Scale 3.125000e-02
    Cycle   53  Error 28002.839537  Scale 1.562500e-02
    Cycle   54  Error 27206.262167  Scale 7.812500e-03
    Cycle   55  Error 27058.424115  Scale 3.906250e-03
    Cycle   56  Error 26779.237474  Scale 1.953125e-03
    Cycle   57  Error 26582.624745  Scale 9.765625e-04
    Cycle   58  Error 26424.152190  Scale 4.882813e-04
    Cycle   59  Error 26315.997703  Scale 2.441406e-04
    Cycle   60  Error 26181.788037  Scale 1.220703e-04
    Cycle   61  Error 26120.499633  Scale 6.103516e-05
    Cycle   62  Error 25854.996541  Scale 3.051758e-05
    Cycle   63  Error 25736.956448  Scale 1.525879e-05
    Cycle   64  Error 25549.325483  Scale 7.629395e-06
    Cycle   65  Error 25336.560870  Scale 3.814697e-06
    Cycle   66  Error 25090.207482  Scale 1.907349e-06
    Cycle   67  Error 24877.176913  Scale 9.536743e-07
    Cycle   68  Error 24336.982075  Scale 4.768372e-07
    Cycle   69  Error 23860.834872  Scale 2.384186e-07
    Cycle   70  Error 23666.674715  Scale 1.192093e-07
    Cycle   71  Error 23436.599271  Scale 5.960464e-08
    Cycle   72  Error 23305.863261  Scale 2.980232e-08
    Cycle   73  Error 23171.717846  Scale 1.490116e-08
    Cycle   74  Error 23098.344723  Scale 7.450581e-09
    Cycle   75  Error 22994.782747  Scale 3.725290e-09
    Cycle   76  Error 22933.894632  Scale 1.862645e-09
    Cycle   77  Error 22842.255538  Scale 9.313226e-10
    Cycle   78  Error 22765.097680  Scale 4.656613e-10
    Cycle   79  Error 22623.511518  Scale 2.328306e-10
    Cycle   80  Error 22548.625249  Scale 1.164153e-10
    Cycle   81  Error 22452.059164  Scale 5.820766e-11
    Cycle   82  Error 22404.690713  Scale 2.910383e-11
    Cycle   83  Error 22289.129162  Scale 1.455192e-11
    Cycle   84  Error 22187.848421  Scale 7.275958e-12
    Cycle   85  Error 21994.203715  Scale 3.637979e-12
    Cycle   86  Error 21872.720926  Scale 1.818989e-12
    Cycle   87  Error 21637.302955  Scale 9.094947e-13
    Cycle   88  Error 21490.675505  Scale 4.547474e-13
    Cycle   89  Error 21281.101762  Scale 2.273737e-13
    Cycle   90  Error 21116.904279  Scale 1.136868e-13
    Cycle   91  Error 20903.008393  Scale 5.684342e-14
    Cycle   92  Error 20696.736840  Scale 2.842171e-14
    Cycle   93  Error 20539.600097  Scale 1.421085e-14
    Cycle   94  Error 20425.506331  Scale 7.105427e-15
    Cycle   95  Error 20273.584201  Scale 3.552714e-15
    Cycle   96  Error 20187.718996  Scale 1.776357e-15
    Cycle   97  Error 20035.483528  Scale 1.000000e-15
    Cycle   98  Error 19913.292640  Scale 1.000000e-15
    Cycle   99  Error 19804.063562  Scale 1.000000e-15
    Cycle  100  Error 19684.189898  Scale 1.000000e-15
    Maximum number of iterations has been exceeded
    Good responses average 0.801333, bad response average 0.00292607, ratio is 273.86.
    Elapsed time is 1410.707479 seconds.

## Measure new pitch model's performance

Measure performance of this model using a set of test data. Most importantly, this function returns a graph that shows two things: 1) the effect of changing the importance of the transition probability matrix (larger, to the right, means prefer normal transitions), and 2)the importance of the prior probabilities (different lines).

    global gPlayPitchSounds
    gPlayPitchSounds = 0;
    tic;
    filesToTest = 2:40:length(fileList);    % Select a different subset for testing.
    filesToTest = 2:100:length(fileList);   % Select a small subset for testing.
    [pitchTrackingError, voicedError, unvoicedError] = ...
        MeasurePitchPerformance(fileList(filesToTest), pitchModel);
    toc;

    Precomputing features for file 1/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_sa2.mat...
    Precomputing features for file 2/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_si552.mat...
    Precomputing features for file 3/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F01/mic_F01_sx20.mat...
    Precomputing features for file 4/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02/mic_F02_si705.mat...
    Precomputing features for file 5/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F02/mic_F02_si805.mat...
    Precomputing features for file 6/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_si838.mat...
    Precomputing features for file 7/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_si938.mat...
    Precomputing features for file 8/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F03/mic_F03_sx93.mat...
    Precomputing features for file 9/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04/mic_F04_si1111.mat...
    Precomputing features for file 10/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F04/mic_F04_sx140.mat...
    Precomputing features for file 11/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05/mic_F05_si1264.mat...
    Precomputing features for file 12/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F05/mic_F05_si1364.mat...
    Precomputing features for file 13/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_si1417.mat...
    Precomputing features for file 14/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_si1517.mat...
    Precomputing features for file 15/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F06/mic_F06_sx258.mat...
    Precomputing features for file 16/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07/mic_F07_si1670.mat...
    Precomputing features for file 17/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F07/mic_F07_si1770.mat...
    Precomputing features for file 18/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08/mic_F08_si1823.mat...
    Precomputing features for file 19/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F08/mic_F08_si1925.mat...
    Precomputing features for file 20/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_si1978.mat...
    Precomputing features for file 21/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_si2078.mat...
    Precomputing features for file 22/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F09/mic_F09_sx387.mat...
    Precomputing features for file 23/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10/mic_F10_si2231.mat...
    Precomputing features for file 24/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/FEMALE/MIC/F10/mic_F10_si2331.mat...
    Precomputing features for file 25/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M01/mic_M01_si494.mat...
    Precomputing features for file 26/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M01/mic_M01_si594.mat...
    Precomputing features for file 27/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_si647.mat...
    Precomputing features for file 28/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_si747.mat...
    Precomputing features for file 29/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M02/mic_M02_sx64.mat...
    Precomputing features for file 30/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M03/mic_M03_si880.mat...
    Precomputing features for file 31/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M03/mic_M03_si980.mat...
    Precomputing features for file 32/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_si1053.mat...
    Precomputing features for file 33/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_si1153.mat...
    Precomputing features for file 34/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M04/mic_M04_sx182.mat...
    Precomputing features for file 35/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M05/mic_M05_si1306.mat...
    Precomputing features for file 36/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M05/mic_M05_sx191.mat...
    Precomputing features for file 37/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M06/mic_M06_si1459.mat...
    Precomputing features for file 38/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M06/mic_M06_si1559.mat...
    Precomputing features for file 39/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_si1612.mat...
    Precomputing features for file 40/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_si1712.mat...
    Precomputing features for file 41/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M07/mic_M07_sx309.mat...
    Precomputing features for file 42/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M08/mic_M08_si1865.mat...
    Precomputing features for file 43/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M08/mic_M08_sx318.mat...
    Precomputing features for file 44/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M09/mic_M09_si2018.mat...
    Precomputing features for file 45/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M09/mic_M09_si2118.mat...
    Precomputing features for file 46/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_si2171.mat...
    Precomputing features for file 47/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_si2271.mat...
    Precomputing features for file 48/48.
     Reading correlogram data from ../PitchTrackingDatabase/Graz/MALE/MIC/M10/mic_M10_sx436.mat...
    All done doing the ComputeAllFeatures.
    Elapsed time is 2450.879444 seconds.