fbana3.m
来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 134 行
M
134 行
% Function: perform third stage of the Formant Based Linear Prediction Analysis
% ==> allocate the formants
function [FF,FB,Froot]=fbana3(signal,basic,cofa,voicetype,nframe);
%retrieve the basic specification
F_len=basic(5);
O_lap=basic(6);
Order=basic(4);
M_len=F_len-O_lap;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% %%%%%%
%%%%%%% Formant Allocation %%%%%%
%%%%%%% %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This step will create the following variables :
%
% FF = matrix of formant frequency
% FB = matrix of formant bandwidth
% Froot = matrix of formant roots
FF=zeros(nframe,5); % matrix for formant frequency
FB=zeros(nframe,5); % matrix for formant bandwidth
Froot=zeros(nframe,10); % matrix for formant roots
Fmethod=2;
%
% so far, Fmethod==2 produce the best synthetic speech
%
if Fmethod==1
%%----------------------------------------------------------------%
%% Fmethod=1 %
%% Directly split linear prediction frame by frame %
%% coefficients into 5 formant coefficients %
%%----------------------------------------------------------------%
for kf=1:nframe
cofa1=cofa(kf,:);
%[fpoly,bpoly,ff,fb]=splitlp3(cofa1); % without pole modification
[fpoly,bpoly,ff,fb]=splitlp5(cofa1); % with pole modification
fpoles=roots(fpoly)';
bpoles=roots(bpoly)';
Froot(kf,:)=fpoles;
FF(kf,:)=ff;
FB(kf,:)=fb;
end
% smooth the formant track
[FF,FB,Froot]=smfmtk(FF,FB);
elseif Fmethod==2
%%----------------------------------------------------------------%
%% Fmethod=2 %
%% Split linear prediction coefficients into formant and smooth %
%% the formant track at the same time %
%%----------------------------------------------------------------%
[Froot,FF,FB]=smfrmt1(cofa);
end %% if Fmethod==1
%%%-----------------------------%
%%% smoothing the formant track %
%%%-----------------------------%
% find error frame
for kf=1:nframe-1
rcd(kf)=0; % rcd==0 --> no error ; rcd==-1 --> error
if voicetype(kf)
ff=FF(kf,:);
fb=FB(kf,:);
% the formant bandwidth is bigger than frequency
if ~isempty(find( (ff-fb)<0 ))
rcd(kf)=-1;
% the second and third bandwidth to formant ratio should not exceed .5
elseif fb(2)/ff(2)>.5 & fb(3)/ff(3)>.5
rcd(kf)=-1;
elseif ff(5)>4600
rcd(kf)=-1;
end
end
end
%correct error frame
for kf=1:nframe-1
if voicetype(kf) & rcd(kf)==-1
back=kf-1;
while rcd(back)==-1
back=back-1;
end
forward=kf+1;
while rcd(forward)==-1
forward=forward+1;
end
w1=kf-back;
w2=forward-kf;
cofb=real(poly(Froot(back,:)));
coff=real(poly(Froot(forward,:)));
cofa1=polystab(w1/(w1+w2)*cofb+w2/(w1+w2)*coff);
rr=roots(cofa1);
rr=rr(:)';
rr=rr(imag(rr)>0);
ff=angle(rr)/pi*5000;
rad=abs(rr); % pole radius
tmp=(4*rad-1-rad.^2)./(2*rad);
fb=acos(tmp)/pi*10000; % formant bandwidth
[ff,idx]=sort(ff);
fb=fb(idx);
if ~isempty(find( (ff-fb)<0 ))
%zplane(cofa1,[]);pause(1);
disp('Formant Estimation may not be stable in the following frame!');
disp(kf)
Froot(kf,:)=Froot(back,:);
FF(kf,:)=FF(back,:);
FB(kf,:)=FB(back,:);
else
Froot(kf,:)=[rr conj(rr)];
FF(kf,:)=ff;
FB(kf,:)=fb;
end
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?