wolffd@0: function [pitch,salience]=CorrelogramPitch(correlogram, width, sr, low, high); wolffd@0: % pitch=CorrelogramPitch(correlogram, width [, sr, lowPitch, highPitch]) wolffd@0: % computes the pitch of a correlogram sequence by finding the time lag wolffd@0: % with the largest correlation energy. wolffd@0: % wolffd@0: % (c) 1998 Interval Research Corporation wolffd@0: wolffd@0: if nargin < 3; sr=22254.54; end; wolffd@0: if nargin < 4; low=0; end; wolffd@0: if nargin < 5; high=inf; end; wolffd@0: wolffd@0: dropLow = floor(sr/high); wolffd@0: if low > 0 wolffd@0: dropHigh = min(width,ceil(sr/low)); wolffd@0: else wolffd@0: dropHigh = width; wolffd@0: end wolffd@0: wolffd@0: [pixels frames] = size(correlogram); wolffd@0: channels = pixels/width; wolffd@0: if channels < 1 | floor(channels) ~= channels wolffd@0: error('Correlogram Size Error'); wolffd@0: end wolffd@0: wolffd@0: pitch = zeros(1,frames); wolffd@0: salience = zeros(1,frames); wolffd@0: for j=1:frames wolffd@0: % Get one frame from the correlogram, reshape it, and compute wolffd@0: % the sum (as a function of time lag) across all channels. wolffd@0: if channels == 1 wolffd@0: summary=reshape(correlogram(:,j),channels,width); wolffd@0: else wolffd@0: summary=sum(reshape(correlogram(:,j),channels,width)); wolffd@0: end wolffd@0: zeroLag = summary(1); wolffd@0: % Now we need to find the first pitch past the peak at zero wolffd@0: % lag. The following lines smooth the summary pitch a bit, then wolffd@0: % look for the first point where the summary goes back up. wolffd@0: % Everything up to this point is zeroed out. wolffd@0: windowLength=16; wolffd@0: sumfilt=filter(ones(1,windowLength),[1],summary); wolffd@0: sumdif=sumfilt(2:width)-sumfilt(1:width-1); wolffd@0: sumdif(1:windowLength) = zeros(1,windowLength); wolffd@0: valleys=find(sumdif>0); wolffd@0: summary(1:valleys(1)) = zeros(1,valleys(1)); wolffd@0: summary(1:dropLow) = zeros(1,dropLow); wolffd@0: summary(dropHigh:width) = zeros(1,width-dropHigh+1); wolffd@0: plot(summary); wolffd@0: drawnow; wolffd@0: % Now find the location of the biggest peak and call this the pitch wolffd@0: [m p] = max(summary); wolffd@0: pitch(j) = sr/(p-1); wolffd@0: salience(j) = m/zeroLag; wolffd@0: end