gcfit.m

来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 117 行

M
117
字号
% Script : fit the gain envelop with a straight line, parabola or spline function.
%
%   gcfit.m is a call_function executed by "env_fit" on figure(Gcset_f).

  val=get(env_fit,'Value');
 
  % create the modeled envelop
  axx=1:nframe;

  if exist('menv')==0
     menv1=[];
     for kk=1:length(knob_xx)-1

              x1x=knob_xx(kk);
              x2x=knob_xx(kk+1);
              y1y=knob_yy(kk);
              y2y=knob_yy(kk+1);
              xxa=(y1y-y2y)/(x1x-x2x);
              xxb=(x1x*y2y-x2x*y1y)/(x1x-x2x);

              qx1=find( axx==x1x );
              qx2=find( axx==x2x );

              nyy=xxa*axx(qx1:qx2)+xxb;
              nyylen=length(nyy);
              menv1=[menv1 nyy(1:nyylen-1)]; 
      end
      menv=[menv1 nyy(nyylen)];
   end

  % model the segmental envelope accoding to the selected polymonial

  figure(Gcdis_f);

  [xx,yy]=ginput(1);  % obtain which section to model
  x_idx=max( find( knob_xx<xx ) );
  x1x=knob_xx(x_idx);
  x2x=knob_xx(x_idx+1);
  y1y=knob_yy(x_idx);
  y2y=knob_yy(x_idx+1);

  qx1=find( axx==x1x );
  qx2=find( axx==x2x );
 
  val=get(env_fit,'Value');
  if val==1
       %-------------------------------------------------------% 
       %      use a straight line to fit the gain envelope     %
       %-------------------------------------------------------%

       xxa=(y1y-y2y)/(x1x-x2x);
       xxb=(x1x*y2y-x2x*y1y)/(x1x-x2x);
       menv1=xxa*axx(qx1:qx2)+xxb;
  elseif val==2
       %-------------------------------------------------------% 
       %   use a parabola (1) to fit the gain envelope         %
       %-------------------------------------------------------%

        [dum,menv1]=parafit([x1x x2x],[y1y y2y],1,axx(qx1:qx2) );

  elseif val==3
       %-------------------------------------------------------% 
       %   use a parabola (2) to fit the gain envelope         %
       %-------------------------------------------------------%

        [dum,menv1]=parafit([x1x x2x],[y1y y2y],2,axx(qx1:qx2) );

  elseif val==4
       %-------------------------------------------------------% 
       %   use a cubic to fit the pitch wave            %
       %-------------------------------------------------------%
        [dum,menv1]=cubfit([x1x x2x],[y1y y2y],axx(qx1:qx2) );

  elseif val==5
       %-------------------------------------------------------% 
       %   use the default pitch wave                           %
       %-------------------------------------------------------%
        menv1=genv1(qx1:qx2);

  end
  menv(qx1:qx2)=menv1;

  %% plot the gain perturbation

  gcpert=randn(1,nframe)*gb1.*genv1;
  plot(1:nframe,gcpert,'r'); hold on;

  % plot the gain envelop
  plot(1:nframe,genv1,'k');

  % plot the modeled gain envelop
  plot(1:nframe,menv(1:nframe),'g--');

  % plot the spline knobs
  plot(knob_xx,knob_yy,'g*');

  %% plot the voicing boundary
  v=axis;
  for kk=1:length(vcbound)
     plot([(vcbound(kk)-1) (vcbound(kk)-1)],[v(3) v(4)],'c');
  end
  hold off;
  title('Gain envelope (black line) and Gain Perturbation (red line) ');

  %% label the voicing classification
  text((vcbound(1)-1)/2-1/2, 0.9*v(4)+0.1*v(3), 'U');
  for kk=1:length(vcbound)-1
     if vctyp(vcbound(kk))==0
         text((vcbound(kk)-1)/2+(vcbound(kk+1)-1)/2-1, 0.9*v(4)+0.1*v(3), 'U');
     else
         text((vcbound(kk)-1)/2+(vcbound(kk+1)-1)/2-1, 0.9*v(4)+0.1*v(3), 'V');
     end
  end
  text((vcbound(kk+1)-1)/2+nframe/2-1, 0.9*v(4)+0.1*v(3), 'U');
 
  clear xx yy x_idx x1x x2x y1y y2y nyy menv1 axx xxa xxb qx1 qx2 o_yy;

⌨️ 快捷键说明

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