Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/CorrelogramPitch.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [pitch,salience]=CorrelogramPitch(correlogram, width, sr, low, high); | |
2 % pitch=CorrelogramPitch(correlogram, width [, sr, lowPitch, highPitch]) | |
3 % computes the pitch of a correlogram sequence by finding the time lag | |
4 % with the largest correlation energy. | |
5 % | |
6 % (c) 1998 Interval Research Corporation | |
7 | |
8 if nargin < 3; sr=22254.54; end; | |
9 if nargin < 4; low=0; end; | |
10 if nargin < 5; high=inf; end; | |
11 | |
12 dropLow = floor(sr/high); | |
13 if low > 0 | |
14 dropHigh = min(width,ceil(sr/low)); | |
15 else | |
16 dropHigh = width; | |
17 end | |
18 | |
19 [pixels frames] = size(correlogram); | |
20 channels = pixels/width; | |
21 if channels < 1 | floor(channels) ~= channels | |
22 error('Correlogram Size Error'); | |
23 end | |
24 | |
25 pitch = zeros(1,frames); | |
26 salience = zeros(1,frames); | |
27 for j=1:frames | |
28 % Get one frame from the correlogram, reshape it, and compute | |
29 % the sum (as a function of time lag) across all channels. | |
30 if channels == 1 | |
31 summary=reshape(correlogram(:,j),channels,width); | |
32 else | |
33 summary=sum(reshape(correlogram(:,j),channels,width)); | |
34 end | |
35 zeroLag = summary(1); | |
36 % Now we need to find the first pitch past the peak at zero | |
37 % lag. The following lines smooth the summary pitch a bit, then | |
38 % look for the first point where the summary goes back up. | |
39 % Everything up to this point is zeroed out. | |
40 windowLength=16; | |
41 sumfilt=filter(ones(1,windowLength),[1],summary); | |
42 sumdif=sumfilt(2:width)-sumfilt(1:width-1); | |
43 sumdif(1:windowLength) = zeros(1,windowLength); | |
44 valleys=find(sumdif>0); | |
45 summary(1:valleys(1)) = zeros(1,valleys(1)); | |
46 summary(1:dropLow) = zeros(1,dropLow); | |
47 summary(dropHigh:width) = zeros(1,width-dropHigh+1); | |
48 plot(summary); | |
49 drawnow; | |
50 % Now find the location of the biggest peak and call this the pitch | |
51 [m p] = max(summary); | |
52 pitch(j) = sr/(p-1); | |
53 salience(j) = m/zeroLag; | |
54 end |