⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path4.m

📁 这是一个用于语音信号处理的工具箱
💻 M
字号:
%PATH1 : Path IV's Frame match by Dynamic time warping.
%FUNCTION: [m,adis]=path4(cofa1,cofa2,speech2,basic,show);
% 
%Input  cofa1 = linear prediction coefficient matrix for speech1.
%       cofa2 = linear prediction coefficient matrix for speech2.
%       speech2 = source speech
%       basic = [measure constraint path order fram_len over_len lens], the 
%                basic parameters.
%       show = display the searching process if show == 1
%
%Output   m = Dynamic time warping function i-->w, w=m(i)
%         adis = final accumulated distance
%
%Please see page 211 of "fundamentals of speech recogniction" by Rabiner 
%       and Juang for this local constraints and the resulting path.
% 

function [m,adis]=path4(cofa1,cofa2,speech2,basic,show);
% variables used in the function:
%       i = index for cofa1.
%       j = index for cofa2.
%       M = number of frames for cofa2.
%       N = number of frames for cofa1.
%       path = possible path, [accumulated distances, i_moving, j_jump....]
%       p_path = possible path of previous frame
%       t_path = path for current point

%%%%%%%%% PLEASE DO NOT EDIT THE FOLLOWING  %%%%%%%%%%%

speech2=speech2(:)';  % convert to row vector 
[N dummy]=size(cofa1);
[M dummy]=size(cofa2);


%retrieve the basic parameters

measure=basic(1);
path_const=basic(3);
order=basic(4);
fram_len=basic(5);
over_len=basic(6);
lens=basic(7);

%%%%%%%%%%%%%%% FINDING the OPTIMAL PATH by Dynamic Programming

%%%%%%% construct the distortion measure matrix

for i=1:N
   for j=1:M
        % boundary condition
        if (i-2*j+1)>0
           DIS(i,j)=-1;
        elseif (2*i-j-1)<0
           DIS(i,j)=-1;
        elseif (2*i-j-2*N+M)>0
           DIS(i,j)=-1;
        elseif (i-2*j-N+2*M)<0
           DIS(i,j)=-1;
        else
           a=cofa1(i,:);
           b=cofa2(j,:);
           test=speech2( (j-1)*lens+order+1:j*lens+order );
           zi=speech2( (j-1)*lens+1: (j-1)*lens+order );
           DIS(i,j)=distance(a,b,test,zi,measure);
        end
   end
end

NM=2*N+2*M+1;
path=ones(M, NM);
path=-1*path;

%%%%%%% Initial condition, first frame
i=1;
j=1;
    path(j,i)=DIS(i,j);

%%%%%%% runing from 2nd frame to the end
for i=2:N

    p_path=path; % the path matrix of previous frame

    for j=1:M
        if DIS(i,j)==-1
           path(j,:)=-1*ones(1,NM);
        else

            % there are three path to this current (i,j) point
            if (i-2)>0 & (j-1)>0
               if DIS(i-2,j-1)>-1          
                  dis(1)=pp_path(j-1,1)+p_path(j,1);
               else
                  dis(1)=Inf;
               end
            else
               dis(1)=Inf;
            end

            if (i-2)>0 & (j-2)>0
               if DIS(i-2,j-2)>-1
                  dis(2)=pp_path(j-2,1)+p_path(j,1);
               else
                  dis(2)=Inf;
               end
            else
               dis(2)=Inf;
            end

            if (i-1)>0 & (j-1)>0
               if DIS(i-1,j-1)>-1
                  dis(3)=p_path(j-1,1);
               else
                  dis(3)=Inf;
               end
            else
               dis(3)=Inf;
            end

            if (i-1)>0 & (j-2)>0
               if DIS(i-1,j-2)>-1
                  dis(4)=p_path(j-2,1);
               else
                  dis(4)=Inf;
               end
            else
               dis(4)=Inf;
            end

            [dummy,indx]=sort(dis);
            if indx(1)==1
               t_path=pp_path(j-1,:);
               t_path=t_path(t_path>-1);
               t_path=[t_path 1 1 1 0];
 
            elseif indx(1)==2
               t_path=pp_path(j-2,:);
               t_path=t_path(t_path>-1);
               t_path=[t_path 1 2 1 0];
  
            elseif indx(1)==3
               t_path=p_path(j-1,:);
               t_path=t_path(t_path>-1);
               t_path=[t_path 1 1];
            elseif indx(1)==4
               t_path=p_path(j-2,:);
               t_path=t_path(t_path>-1);
               t_path=[t_path 1 2];
            end
        
            t_path(1)=dummy(1)+DIS(i,j);
            nl=length(t_path);
            path(j, 1:nl)=t_path;
            fdis(j)=path(j,1);

            % delete the remaining path
            if (nl+1)<NM & path(j,nl+1)~=-1
                path(j,nl+1:NM)=-1*ones(1,NM-nl);
            end

        end % if DIS(i,j)==-1

    end % for j=1:M
    pp_path=p_path; % path matrix of previous two frame

    if show==1
       idx=find( fdis>0 );
       [dum,idxidx]=min( fdis(idx) );
       tmpath=path(idx(idxidx),:);
       tmpath=tmpath(tmpath>-1);
       x=[1 tmpath(2:2:length(tmpath))];
       y=[1 tmpath(3:2:length(tmpath))];
       plot(integ(x),integ(y),'+');
       axis([1 N 1 M]);
       title('Finding the optimal path!');
       xlabel('target');
       ylabel('source');
       drawnow;
       fdis=zeros(1,M);
    end
end % for i=2:N

t_path=path(M,:);
t_path=t_path(t_path >-1);
x=[1 t_path(2:2:length(t_path))];
y=[1 t_path(3:2:length(t_path))];
adis=t_path(1,1);
x=integ(x);
y=integ(y);
m=[x ; y];

if show==1
   plot(x,y,'k+');
   xlabel('target');
   ylabel('source');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -