function [L,R]=nffc(s,ptr,winlen,lmin,lmax,thr) % % Syntax: [L,R]=nffc(s,ptr,winlen,lmin,lmax,thr) % % Computes pitch using normalized cross-correlation method. % s is the ENTIRE signal with lmax zeros added before (for the 1st frame) % ptr is pointer pointing to the beginning sample of a frame. % winlen if the length of frame. % lmin is minimal lag in samples % lmax is maximal lag in samples % thr is a threshold Rmax >= thr => voiced % Rmax < thr => unvoiced % L is lag in samples for voiced, 0 for unvoiced frame % R (facultative) is the vector of NCCF coefficients % nonshifted frame x = s(ptr:(ptr+winlen-1)); e1 = sum(x.^2); R = zeros (1,lmax+1); % shifted versions for ii=0:lmax, % want them all from 0 ... xs = s((ptr-ii):(ptr+winlen-1-ii)); e2 = sum(xs.^2); ncc = sum (xs .* x) / sqrt(e1 * e2); R(ii+1) = ncc; end [Rmax,ii]=max(R(lmin+1:lmax+1)); if Rmax >= thr, L=ii+lmin-1; else L=0; end