# Pitch estimation using the autocorrelation method

I have the following code:

// input: speech segment
[y,Fs,bits]= wavread('/media/A03036C33036A068/scilab/30msec_voiced.wav');
max_value=max(abs(y));
y=y/max_value;
t=(1/Fs:1/Fs:(length(y)/Fs))*1000;
subplot(2,1,1);
plot(t,y);
xtitle('A 30 millisecond segment of speech','time in milliseconds');
sum1=0;autocorrelation=0;
for l=0:(length(y)-1)
sum1=0;
for u=1:(length(y)-l)
s=y(u)*y(u+l);
sum1=sum1+s;
end
autocor(l+1)=sum1;
end
kk=(1/Fs:1/Fs:(length(autocor)/Fs))*1000;
subplot(2,1,2);
plot(kk,autocor);
xtitle('Autocorrelation of the 30 millisecond segment of speech','time in milliseconds');
auto=autocor(21:160);
max1=0;
for uu=1:140
if(auto(uu)>max1)
max1=auto(uu);
sample_no=uu;
end
end
pitch_period_To=(20+sample_no)*(1/Fs)
pitch_freq_Fo=1/pitch_period_To


In this, I am not getting the meaning of pitch_period_To=(20+sample_no)*(1/Fs). Why did they add 20?

## 1 Answer

An offset of 20 samples is added as 8 lines above (auto=autocor(21:160)) this offset is cut away from the autocorrelation sequence. In the line you mention, this offset has therefore to be considered.

This is done in order to cut away the first maximum (at time lags around zero) and avoid pitch errors caused by picking a delay value that does not make sense for the task of fundamental frequency estimation.

(By the way, your code does not perform pitch estimation but fundamental frequency estimation. There's a difference between these two terms as pitch relates to a perceptual property of a tone while fundamental frequency is a technical property - Wikipedia on "Pitch".)