📄 pdetect.m
字号:
function [pcode, pgain, pk]=pdetect(pdelay,sube1,bkl,bkh,fracflg)
global h len cbsize szsubf pcbsize fstfrm intp pdmin pdmax pdlyindx
if fracflg==1
% Fractional delay search
start=intp+pdmin; % Start point for computing fractional delay vector
c=bkh-bkl; i=0;
while (i<=c)
m=fix(pdlyindx(bkl+i));
frac=pdlyindx(bkl+i)-m;
if frac>10e-6
[pdelay,fracdly(i+1,:)]=interpolate(pdelay,start,szsubf,frac,m); % All interpolate.m all equal either 1 or 0 (avoid FirstCom flag getting error)
for j=0:szsubf-1 %Convolution of the fractional delays with weighting filter
endpt=min(j,len-1);
y(i+1,j+1)=sum(h(1:endpt+1).*fracdly(i+1,1+j:-1:1+j-endpt));
end
yy(i+1,:)=y(i+1,:);
cor(i+1)=sum(yy(i+1,:).*sube1);
eng(i+1)=sum(yy(i+1,:).*yy(i+1,:));
gain(i+1)=cor(i+1)/eng(i+1);
peak(i+1)=gain(i+1)*cor(i+1);
else
peak(i+1)=-10e5;
gain(i+1)=0.0;
end
i=i+1;
end
[pk,pcode]=max(peak); % Find the best estimate of fractional delay and gain
pgain=gain(pcode);
pcode=bkl+pcode-1;
else
% Integer delay search
strptr=pdmax+1-fix(pdlyindx(bkh)); % Find computation start point in pitch delay buffer
endptr=pdmax+1-ceil(pdlyindx(bkl)); % Find computation end point in pitch delay buffer
for i=0:szsubf-1
endpt=min(i,len-1); %compute conv before interpolation
y(endptr,i+1)=sum(h(1:endpt+1).*pdelay(endptr+i:-1:i-endpt+endptr));
end
for i=endptr-1:-1:strptr
y(i,1)=h(1)*pdelay(i); % End point correction
y(i,2:len)=y(i+1,1:len-1)+h(2:len)*pdelay(i);
y(i,len+1:szsubf)=y(i+1,len:szsubf-1);
end
for i=strptr:endptr
yy(i,:)=y(i,:);
m=intp+pdmin-i; % M=pitch delay
if m<szsubf
yy(i,m+1:szsubf)=y(i,m+1:szsubf)+y(i,1:szsubf-m); % For m<size of sub-frame,
if m<fix(szsubf/2) % do 2nd and 3rd convolution addition
ilow=(2*m)+1;
ihigh=szsubf;
yy(i,ilow:ihigh)=yy(i,ilow:ihigh)+y(i,1:szsubf-(2*m));
end
end
end
% Compute Correlation and Eng. and get the best pitch coefficient
for i=strptr:endptr
cor(i)=sum(yy(i,:).*sube1);
eng(i)=sum(yy(i,:).*yy(i,:));
gain(i)=cor(i)/eng(i);
peak(i)=gain(i)*cor(i);
end
[pk,pcode]=max(peak(strptr:endptr)); % Find the best estimate of integer pitch delay and gain
pcode=pcode+strptr-1;
pgain=gain(pcode);
pcode=find(pdlyindx==(pdmax+1-pcode)); % Translate the position into corresponding index in pitch delay table
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -