function [pitch, ratio, cps]=pitch_cps(x, sammin, sammax, thr) % Syntax: [pitch, ratio, cps]=pitch_cps(x, sammin, sammax, thr) % or: [pitch, ratio, cps]=pitch_cps(x) % % Pitch determination using cepstral method. % x - frames of signal. % sammin - minimal pitch period in samples - default 20 % sammax - maximal pitch period in samples - default 160 % thr - threshold for voiced/unvoiced determination - default ... % pitch - pitch period, or 0, if unvoiced % ratio - between c(max) and c(0) % cps - complete cpestral vector % % the cepstrum is calculated as c=ifft(log(abs(fft(x)).^2)). % The peak is then detected in the region of interest. The frame is declared % voiced, if that peak reaches at least thr*c(0). Its position determinates % the pitch. The length of fft is chosen to be at least 2*sammax. if nargin==1, sammin=20; sammax=160; thr = 0.5; % ????? else if (nargin ~= 4) error ('Bad no. of arguments'); end end [r,c]=size(x); if r>c, x=x'; end lx=length(x); if lx <= sammax disp ('for lx<=sammax, the results will not be very good...'); end ptsfft = 2^ceil(log2(sammax*2)); x=[x zeros(1,ptsfft-lx)]; lx=length(x); c=abs(ifft(log(abs(fft(x)).^2))); cps=c; % output c0=c(1); c(1:sammin)=zeros(1,sammin); c(sammax+2:lx)=zeros(1,lx-sammax-1); [maxc,ind]=max(c); ratio = maxc / c0; if ratio > thr, pitch=ind-1; else pitch=0; end