Code covered by the BSD License  

Highlights from
Cepstral Pitch

image thumbnail

Cepstral Pitch

by

 

15 Feb 2014 (Updated )

This exercise implements a pitch period detector based on detecting and tracking peaks in speech.

Callbacks_cepstral_pitch_GUI25(f,C,start_path)
function Callbacks_cepstral_pitch_GUI25(f,C,start_path)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%SENSE COMPUTER AND SET FILE DELIMITER
switch(computer)				
    case 'MACI64',		char= '/';
    case 'GLNX86',  char='/';
    case 'PCWIN',	char= '\';
    case 'PCWIN64', char='\';
    case 'GLNXA64', char='/';
end

x=C{1,1};
y=C{1,2};
a=C{1,3};
b=C{1,4};
u=C{1,5};
v=C{1,6};
m=C{1,7};
n=C{1,8};
lengthbutton=C{1,9};
widthbutton=C{1,10};
enterType=C{1,11};
enterString=C{1,12};
enterLabel=C{1,13};
noPanels=C{1,14};
noGraphicPanels=C{1,15};
noButtons=C{1,16};
labelDist=C{1,17};%distance that the label is below the button
noTitles=C{1,18};
buttonTextSize=C{1,19};
labelTextSize=C{1,20};
textboxFont=C{1,21};
textboxString=C{1,22};
textboxWeight=C{1,23};
textboxAngle=C{1,24};
labelHeight=C{1,25};
fileName=C{1,26};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PANELS
for j=0:noPanels-1
uipanel('Parent',f,...
'Units','Normalized',...
'Position',[x(1+4*j) y(1+4*j) x(2+4*j)-x(1+4*j) y(3+4*j)-y(2+4*j)]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%GRAPHIC PANELS
for i=0:noGraphicPanels-1
switch (i+1)
case 1
graphicPanel1 = axes('parent',f,...
'Units','Normalized',...
'Position',[a(1+4*i) b(1+4*i) a(2+4*i)-a(1+4*i) b(3+4*i)-b(2+4*i)],...
'GridLineStyle','--');
case 2
graphicPanel2 = axes('parent',f,...
'Units','Normalized',...
'Position',[a(1+4*i) b(1+4*i) a(2+4*i)-a(1+4*i) b(3+4*i)-b(2+4*i)],...
'GridLineStyle','--');
case 3
graphicPanel3 = axes('parent',f,...
'Units','Normalized',...
'Position',[a(1+4*i) b(1+4*i) a(2+4*i)-a(1+4*i) b(3+4*i)-b(2+4*i)],...
'GridLineStyle','--');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%TITLE BOXES
for k=0:noTitles-1
switch (k+1)
case 1
titleBox1 = uicontrol('parent',f,...
'Units','Normalized',...
'Position',[u(1+4*k) v(1+4*k) u(2+4*k)-u(1+4*k) v(3+4*k)-v(2+4*k)],...
'Style','text',...
'FontSize',textboxFont{k+1},...
'String',textboxString(k+1),...
'FontWeight',textboxWeight{k+1},...
'FontAngle',textboxAngle{k+1});
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%BUTTONS
for i=0:(noButtons-1)
enterColor='w';
if strcmp(enterType{i+1},'pushbutton')==1 ||strcmp(enterType{i+1},'text')==1
enterColor='default';
end
if (strcmp(enterLabel{1,(i+1)},'')==0 &&...
        strcmp(enterLabel{1,(i+1)},'...')==0) %i.e. there is a label
%creating a label for some buttons
uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i)-labelDist-labelHeight(i+1) ...
(m(2+2*i)-m(1+2*i)) labelHeight(i+1)],...
'Style','text',...
'String',enterLabel{i+1},...
'FontSize', labelTextSize(i+1),...
'HorizontalAlignment','center');
end
switch (i+1)
case 1
button1=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button1Callback);
case 2
button2=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button2Callback);
case 3
button3=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button3Callback);
case 4
button4=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button4Callback);
case 5
button5=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button5Callback);
case 6
button6=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button6Callback);
case 7
button7=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button7Callback);
case 8
button8=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button8Callback);
case 9
button9=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button9Callback);
case 10
button10=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button10Callback);
case 11
button11=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button11Callback);
case 12
button12=uicontrol('Parent',f,...
'Units','Normalized',...
'Position',[m(1+2*i) n(1+2*i) (m(2+2*i)-m(1+2*i)) (n(2+2*i)-n(1+2*i))],...
'Style',enterType{i+1},...
'String',enterString{i+1},...
'FontSize', buttonTextSize(1+i),...
'BackgroundColor',enterColor,...
'HorizontalAlignment','center',...
'Callback',@button12Callback);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%USER CODE FOR THE VARIABLES AND CALLBACKS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize Variables
    curr_file=1;
    fs=8000;
    fsd=10000;
    directory_name='abcd';
    wav_file_names='abce';
    fin_path='filename';
    fname='output';
    nsamp=1;
    ss=8000;
    istart=1;
    Lm=40;
    L=400;
    Rm=10;
    R=100;
    imf=1;
    nframes=20;
    nlayers=5;
    nfft=10000;
    xin=[];
    y=[];
    yf=[];
    addnoise=1;
    pthr1=2.5;
    Lmed=5;
    nl=1;
    n=[];
    p1m=[];
    c1m=[];
    xpp=[];
    ypp=[];
    ppdf=[];

% Name the GUI
    set(f,'Name','cepstral pitch detector');

% CALLBACKS
% Callback for button1 -- Get Speech Files Directory
 function button1Callback(h,eventdata)
     directory_name=uigetdir(start_path,'dialog_title');
%      if isempty(getpref('SpeechApps'))
%          url = sprintf('%s%s%s',...
%              'http://www.mathworks.com/matlabcentral/fileexchange/',...
%              '42911-speech-and-audio-files-for-speech-processing-excercises',...
%              '?download=true');
%          [saveloc,~,~] = fileparts(pwd); %save to one level up from current folder
%          % Create a waitbar during download
%          h = waitbar(0.35,'This may take several minutes...',...
%              'Name','Downloading Speech Files...');
%          % Download the zipped file
%          [filestr,status] = urlwrite(url,[saveloc filesep 'speech_files.zip'],...
%              'Timeout',10);
%          if status
%              delete(h);
%              hh1= helpdlg('Downloaded. Select a location to UNZIP the speech files.');
%              uiwait(hh1);
%              unziploc = uigetdir(saveloc,'Select a location to unzip the speech files');
%              h2 = waitbar(0.2,'This may take a minute...',...
%                  'Name','Unzipping the Speech Files to Location Selected...');
%              unzip(filestr,unziploc);
%              delete(h2)
%              addpref('SpeechApps','path',unziploc);
%              hh2= helpdlg('Ready. Select the speech_files folder in the next window');
%              uiwait(hh2);
%          else
%              warndlg('No Internet Connection to MATLAB Central!');
%          end
%          
%      else
%      end
%      directory_name=uigetdir(getpref('SpeechApps','path'));
     A=strvcat(strcat((directory_name),[char,'*.wav']));
     struct_filenames=dir(A);
     wav_file_names={struct_filenames.name};
     set(button2,'String',wav_file_names);
     
% once the popupmenu/drop down menu is created, by default, the first
% selection from the popupmenu/drop down menu id not called
    indexOfDrpDwnMenu=1;
    
% by default first option from the popupmenu/dropdown menu will be loaded
    [curr_file,fs]=loadSelection(directory_name,wav_file_names,indexOfDrpDwnMenu);
 end

% Callback for button2 -- Choose speech file for play and plot
 function button2Callback(h,eventdata)
     indexOfDrpDwnMenu=get(button2,'val');
     [curr_file,fs]=loadSelection(directory_name,wav_file_names,indexOfDrpDwnMenu);
 end

%*************************************************************************
% function -- load selection from designated directory and file
%
function [curr_file,fs]=loadSelection(directory_name,wav_file_names,...
    indexOfDrpDwnMenu);
%
% read in speech/audio file
% fin_path is the complete path of the .wav file that is selected
    fin_path=strcat(directory_name,char,strvcat(wav_file_names(indexOfDrpDwnMenu)));
    
% clear speech/audio file
    clear curr_file;
    
% read in speech/audio signal into curr_file; sampling rate is fs 
    [curr_file,fs]=wavread(fin_path);
    xin=curr_file*32768;
    
% create title information with file, sampling rate, number of samples
    fname=wav_file_names(indexOfDrpDwnMenu);
    FS=num2str(fs);
    nsamp=num2str(length(curr_file));
    file_info_string=strcat('  file: ',fname,', fs: ',FS,' Hz, nsamp:',nsamp);
    
% read in filename (fname) from cell array
    fname=wav_file_names{indexOfDrpDwnMenu};
end

% Callback for button12 -- play original speech file
 function button12Callback(h,eventdata)
     soundsc(curr_file,fs);
 end

% Callback for button3 -- fsd: sampling rate of signal processing
 function button3Callback(h,eventdata)
     fsd=str2num(get(button3,'string'));
     a = [6000 8000 10000 16000 20000];
     fsd = a(get(button3,'val'));
 end

% Callback for button4 -- imf: male/female pitch period range option; 1 for
% male, 2 for female
 function button4Callback(h,eventdata)
     imf=get(button4,'val');
     imf=1;
 end

% Callback for button5 -- Lm: analysis frame length in msec
 function button5Callback(h,eventdata)
     Lm=str2num(get(button5,'string'));
     if ~((Lm >= 1 && Lm <= 100))
        waitfor(errordlg('Lm must be a positive number between 1 and 100'))
        return;
     end
 end

% Callback for button6 == Rm: analysis frame shift in msec
 function button6Callback(h,eventdata)
     Rm=str2num(get(button6,'string'));
     if ~((Rm >= 1 && Rm <= 100))
        waitfor(errordlg('Rm must be a positive number between 1 and 100'))
        return;
     end
 end

% Callback for button7 -- pthr1: cepstral level threshold
% Use pthr1 as follows:
%   - compute cepstral level of largest peak in designated pitch period
%   region and call the value plevel1
%   - remove local region around largest peak by setting cepstral values to
%   zero in this region
%   - compute cepstral level of second largest peak in designated pitch
%   period region and call the value plevel2
%   - form ratio of plevel1 to plevel2 and call this pratio
%   - use rule that pratio > pthr1 ==> voiced region with top pitch period
%   estimate set to quefrency of largest cepstral peak, and secondary pitch
%   period estimate set to quefrency of second largest cepstral peak
%   - use rule that pratio < pthr1 ==> unvoiced region
 function button7Callback(h,eventdata)
     pthr1=str2num(get(button7,'string'));
     if ~((pthr1 >= 2.0 && pthr1 <= 5.0))
        waitfor(errordlg('pthr1 must be a number between 2.0 and 5.0'))
        return
     end
 end

% Callback for button8 -- Lmed: size of median smoother in samples
 function button8Callback(h,eventdata)
     Lmed=str2num(get(button8,'string'));
     if ~((Lmed >= 3 && Lmed <= 11))
        waitfor(errordlg('Lmed must be a positive integer between 3 and 11'))
        return;
     end
     Lmed=round(Lmed);
     set(button8,'string',num2str(Lmed));
 end

% Callback for button9 -- run cepstral pitch detection (unsmoothed)
 function button9Callback(h,eventdata)
     
% check editable buttons for changes
    button3Callback(h,eventdata);
    button4Callback(h,eventdata);
    button5Callback(h,eventdata);
    button6Callback(h,eventdata);
    button7Callback(h,eventdata);
    button8Callback(h,eventdata);
    
% function to setup signal processing parameters for cepstral pitch detector
    [n,p1m,nl,c1m]=setup_cepstral_pitch_detector(xin,fs,fsd,imf,pthr1,nfft,...
        Lm,Rm,Lmed,fname);
 end

%*************************************************************************
function [n,p1m,nl,c1m]=setup_cepstral_pitch_detector(xin,fs,fsd,imf,pthr1,nfft,...
        Lm,Rm,Lmed,fname)
%
% function to set up all signal processing parameters for cepstral pitch
% detection
    clear y ye yf;
    clear pp1 pp2 plevel1 plevel2;
    clear ppdf ppsav pplevel;
    clear p1m c1m ppm plevel1m;
    
% convert frame duration and frame shift to samples at signal processing
% sampling rate
    L=round(Lm*fsd/1000);
    R=round(Rm*fsd/1000);
    
% resample if fs ~= fsd
    y=xin;
    if (fs ~= fsd)
        y=srconv(y,fs,fsd);
    end
    ly=length(y);
    
% highpass filter the speech file
    ye=y;
    yf=filter([1 -1],1,ye);    
   
% compute cepstrum and detect pitch
    idebug=0;
    [pp1,pp2,plevel1,plevel2]=...
        pitch_detect_cepstrum_GUI(yf,fsd,imf,nfft,L,R,fname);
    
% median smooth pitch period contour
    ppdf=smoothpitch(pp1,pp2,plevel1,plevel2,pthr1);
    ppsav=pp1;
    pplevel=plevel1./(25*plevel2);
    
% clear graphics Panel 3
        reset(graphicPanel3);
        axes(graphicPanel3);
        cla;
        
% plot out entire speech file in graphics Panel 3
        nfrm=length(ppdf);
        ss1=L/2+1-R;
        if (ss1 < 1)  ss1=1;  end
        es1=L/2+1+nfrm*R;
        xpp=['Time in Seconds; fs=',num2str(fs),' samples/second'];
        plot((ss1:es1)/fs,yf(ss1:es1),'b');xlabel(xpp);
        ylabel('Value');grid on;
        axis([(L/2+1-R)/fs, (L/2+1+nfrm*R)/fs, min(yf), max(yf)]);
    
% clear graphics Panel 2
        reset(graphicPanel2);
        axes(graphicPanel2);
        cla;
        
% plot unsmoothed pitch period contour in graphics Panel 2
    nl=length(ppdf);
    n=1:length(ppdf);
    plot(n,ppdf,'r','LineWidth',2);
        axis([0 (nfrm+1) min(ppdf) 1.2*max(ppdf)]); grid on;
        xpp=['Frame Number (frames at fsd=',num2str(fsd),' samples/second'];
        ypp=['Pitch Period (frames at fsd=',num2str(fsd),' samples/second'];
        xlabel(xpp),ylabel(ypp); 
        stitle=sprintf(' file: %s',fname);

% clear graphics Panel 1
        reset(graphicPanel1);
        axes(graphicPanel1);
        cla;
        
% plot cepstral peak contour, cepstral second peak contour, and ratio of
% pair of cepstral peaks -- all on graphics Panel 1
    plot(n,plevel1(1:nl),'k','LineWidth',2),hold on;
    plot(n,plevel2(1:nl),'r','LineWidth',2),hold on;
    plot(n,plevel1(1:nl)./(25*plevel2(1:nl)),'b','LineWidth',2); hold on;
    plot([1 nl],[pthr1/25 pthr1/25],'b-.','LineWidth',2);
        axis([0 (nfrm+1) min(plevel1) 1.2*max(plevel1./(25*plevel2))]); grid on;
        xlabel(xpp),ylabel('Confidence Based on pthr1'),...
        legend('cepstral peak level','second peak level','peak ratios/25','pthr1/25 threshold');

    p1m=medf(ppdf,Lmed,length(pp1));
    c1m=medf(plevel1(1:nl),Lmed,nl);
    ppm=p1m;
    plevel1m=c1m(1:nl);
    
% display fname and signal processing parameters on titleBox1
        stitle1=strcat('Cepstral Pitch Detector (Unsmoothed) -- ',stitle);
        set(titleBox1,'string',stitle1);
        set(titleBox1,'FontSize',15);
end

%********************************************************************
function [pd1,pd2,p1,p2]=pitch_detect_cepstrum_GUI(peaksigo,fsd,imf,...
        nfft,L,R,filename)
%
% function to detect primary and secondary cepstral pitch periods
%
% Inputs:
%   peaksigo: highpass filtered input signal for cepstral analysis
%   fsd: input signal sampling rate
%   imf: 1 for male talkers, 2 for female talkers
%   nfft: size of fft for stft computation
%   L: frame duration in samples
%   R: frame shift in samples
%   filename: name of file being processed
%
% Outputs:
%   pd1: pitch period contour based on first candidate
%   pd2: pitch period contour based on second candidate
%   p1: cepstral level at primary cepstral peak 
%   p2: cepstral level at secondary cepstral peak 
%
%   low pitch period corresponds to 300 Hz pitch
%   high pitch period corresponds to 50 Hz pitch

% initialize pd1 and p1
    clear pd1 p1;
    
% set cepstral ranges for male and female talkers
    if (imf == 1)
        ppdlow=round(fsd/250);
        ppdhigh=round(fsd/60);
    elseif (imf == 2)
        ppdlow=round(fsd/350);
        ppdhigh=round(fsd/150);
    end
    
% block input signal into frames of duration L samples, with R sample
% shifts between frames
    ls=length(peaksigo);
    fcenter=L/2;
    
% initialize pitch period and pitch level arrays
    p1=[];
    p2=[];
    pd1=[];
    pd2=[];
    count=1;
    n=ppdlow:ppdhigh;
    
    while (fcenter+L/2 <= ls)
        frame1=peaksigo(max(fcenter-L/2,1):fcenter+L/2);
        lf=length(frame1);
        
% create small random frame if input == 0
        if (max(frame1) < 2)
            frame1=randn(lf,1)*0.001;
        end
        
% window frame and compute real cepstrum
        frame1=frame1.*hamming(lf);
        frame1(lf+1:nfft)=0;
        frame1t=log(abs(fft(frame1,nfft)))';
        framec=ifft(frame1t,nfft);
        
% initialize local frame cepstrum over valid range from ppdlow to ppdhigh
        indexlow=ppdlow+1;
        indexhigh=ppdhigh+1;
        loghsp=framec(indexlow:indexhigh);
        
% find cepstral peak location (ploc) and level (pmax) and save results in
% pd1 (for ploc) and p1 (for pmax)
        pmax=max(loghsp);
        ploc1=find(loghsp == pmax);
        ploc=ploc1+ppdlow-1;
        p1=[p1 pmax];
        pd1=[pd1 ploc];
        
% eliminate strongest peak in order to find highest secondary peak 
% which is spaced away from primary peak
% save secondary peak in pd2 and secondary level in p2
        n1=max(1,ploc1-4);
        n2=min(ploc1+4,length(loghsp));
        loghsp2=loghsp;
        loghsp2(n1:n2)=0;
        pmax2=max(loghsp2);
        p2=[p2 pmax2];
        ploc2=find(loghsp2 == pmax2);
        ploc2=ploc2+ppdlow-1;
        pd2=[pd2 ploc2];
  
% plot cepstral values if debug mode is on
        fcenter=fcenter+R;        
    end
end

% Callback for button10 -- run cepstral pitch detection (smoothed)
 function button10Callback(h,eventdata)
     
% clear grpahics Panel 3
        reset(graphicPanel3);
        axes(graphicPanel3);
        cla;
        
% plot entire speech signal in graphics Panel 3
        nfrm=length(p1m);
        ss1=L/2+1-R;
        if (ss1 < 1) ss1=1; end
        es1=L/2+1+nfrm*R;
        xpp=['Time in Seconds; fs=',num2str(fs),' samples/second'];
        plot((ss1:es1)/fs,yf(ss1:es1),'b');xlabel(xpp);
        ylabel('Value');grid on;
        axis([(L/2+1-R)/fs, (L/2+1+nfrm*R)/fs, min(yf), max(yf)]);
        
% clear graphics Panel 2
        reset(graphicPanel2);
        axes(graphicPanel2);
        cla;
        
% plot median-smoothed pitch period contour in graphics Panel 2
    plot(n,p1m(1:nl),'b','LineWidth',2),grid on;
    hold on; plot(n,ppdf,'r','LineWidth',2);
    xpp=['Frame Number; fsd=',num2str(fsd),' samples/second'];
    xlabel(xpp),ylabel(ypp);
        stitle=sprintf('file: %s, median smoothed (Lmed=5)',fname);
        axis([0 nfrm min(p1m) 1.2*max(p1m)]);
        legend('median smoothed pitch period contour','unsmoothed pitch period contour');
        
% clear graphics Panel 1
        reset(graphicPanel1);
        axes(graphicPanel1);
        cla;
        
% plot median-smoothed confidence score in graphics Panel 1
     plot(n,c1m(1:nl),'k','LineWidth',2), grid on,...
        xlabel(xpp),ylabel('Confidence');
        axis([0 nfrm min(c1m) 1.2*max(c1m)]);
    
% display fname and signal processing parameters on titleBox1
        stitle1=strcat('Cepstral Pitch Detector (Smoothed) -- ',stitle);
        set(titleBox1,'string',stitle1);
        set(titleBox1,'FontSize',15);
        
% save pitch perod contour (appropriately scaled to original sampling rate)
% in mat file
    ppmi=round(p1m'*fs/fsd);
    fsave=strcat('out_cepstrum_',fname(1:length(fname)-4),'.mat');
    save(fsave,'ppmi');
 end

% Callback for button11 -- close GUI
 function button11Callback(h,eventdata)
     close(gcf);
 end
end

Contact us