annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/CorrelogramPitch.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [pitch,salience]=CorrelogramPitch(correlogram, width, sr, low, high);
Daniel@0 2 % pitch=CorrelogramPitch(correlogram, width [, sr, lowPitch, highPitch])
Daniel@0 3 % computes the pitch of a correlogram sequence by finding the time lag
Daniel@0 4 % with the largest correlation energy.
Daniel@0 5 %
Daniel@0 6 % (c) 1998 Interval Research Corporation
Daniel@0 7
Daniel@0 8 if nargin < 3; sr=22254.54; end;
Daniel@0 9 if nargin < 4; low=0; end;
Daniel@0 10 if nargin < 5; high=inf; end;
Daniel@0 11
Daniel@0 12 dropLow = floor(sr/high);
Daniel@0 13 if low > 0
Daniel@0 14 dropHigh = min(width,ceil(sr/low));
Daniel@0 15 else
Daniel@0 16 dropHigh = width;
Daniel@0 17 end
Daniel@0 18
Daniel@0 19 [pixels frames] = size(correlogram);
Daniel@0 20 channels = pixels/width;
Daniel@0 21 if channels < 1 | floor(channels) ~= channels
Daniel@0 22 error('Correlogram Size Error');
Daniel@0 23 end
Daniel@0 24
Daniel@0 25 pitch = zeros(1,frames);
Daniel@0 26 salience = zeros(1,frames);
Daniel@0 27 for j=1:frames
Daniel@0 28 % Get one frame from the correlogram, reshape it, and compute
Daniel@0 29 % the sum (as a function of time lag) across all channels.
Daniel@0 30 if channels == 1
Daniel@0 31 summary=reshape(correlogram(:,j),channels,width);
Daniel@0 32 else
Daniel@0 33 summary=sum(reshape(correlogram(:,j),channels,width));
Daniel@0 34 end
Daniel@0 35 zeroLag = summary(1);
Daniel@0 36 % Now we need to find the first pitch past the peak at zero
Daniel@0 37 % lag. The following lines smooth the summary pitch a bit, then
Daniel@0 38 % look for the first point where the summary goes back up.
Daniel@0 39 % Everything up to this point is zeroed out.
Daniel@0 40 windowLength=16;
Daniel@0 41 sumfilt=filter(ones(1,windowLength),[1],summary);
Daniel@0 42 sumdif=sumfilt(2:width)-sumfilt(1:width-1);
Daniel@0 43 sumdif(1:windowLength) = zeros(1,windowLength);
Daniel@0 44 valleys=find(sumdif>0);
Daniel@0 45 summary(1:valleys(1)) = zeros(1,valleys(1));
Daniel@0 46 summary(1:dropLow) = zeros(1,dropLow);
Daniel@0 47 summary(dropHigh:width) = zeros(1,width-dropHigh+1);
Daniel@0 48 plot(summary);
Daniel@0 49 drawnow;
Daniel@0 50 % Now find the location of the biggest peak and call this the pitch
Daniel@0 51 [m p] = max(summary);
Daniel@0 52 pitch(j) = sr/(p-1);
Daniel@0 53 salience(j) = m/zeroLag;
Daniel@0 54 end