Interfacing function
eng


VCO_c

File content


//VCO_c Scicos VCO with Frequency divider Event block
//Classical interface function ver1.0 - scilab-4.1
//14 mars 2006 - INRIA - Author : A.Layec
function [x,y,typ]=VCO_c(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  tt1='VCO'
  tt2=[]
  tt3=[]
  if arg1.model.ipar(1)==1 then
   if arg1.model.ipar(3)==0 then
    tt2=['%N'];
   else
    tt1='   VCO'
    if arg1.graphics.flip then
     tt2=['%N  %M'];
    else 
     tt2=['%N  %M'];
    end
   end
  else
   if arg1.model.ipar(3)==0 then
    tt2=[];
   else
    if arg1.graphics.flip then
      tt1='  VCO'
      tt2=['     %M'];
    else
     tt1='  VCO'
     tt2= ['%M     '];
    end
   end
  end
  txt=[tt1;tt2];
  standard_draw(arg1)
case 'getinputs' then
  [x,y,typ]=standard_inputs(arg1)
case 'getoutputs' then
  [x,y,typ]=standard_outputs(arg1)
case 'getorigin' then
  [x,y]=standard_origin(arg1)
case 'set' then
   x=arg1;
   graphics=arg1.graphics;model=arg1.model;
   exprs1=graphics.exprs(1:9)
   exprs2=graphics.exprs(10:12)
   exprs3=graphics.exprs(13:14)

   while %t do
      [ok,pulsation,kv,pas,cross_1,dyn_input,fnl,typ_noise,sratio,pnoise,exprs1]=...
       getvalue('Scicos VCO with Frequency divider Event block',...
       ['Pulsation [rad/s]';'Sensitivity [rad/V]';'Integration step [s]';...
       'Angular position of crossing [rad]';'Dynamical Value (0:no, 1:yes)';...
       'Use input nonlinearity (0:no, 1:yes)';'White Noise (0:no, 1:yes)';...
       'Use second integer frequency divider (0:no or Value)';
       'Phase noise on last input (0:no, 1:yes)'],...
       list('vec',-1,'vec',-1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1),exprs1);

      if ~ok then break,end;

        if (size(pulsation)==size(kv)) then
           Nu = prod(size(pulsation));

           if (dyn_input==1)&(pnoise==1) then
            if sratio<>0 then
             [model,graphics,ok]=check_io(model,graphics,[Nu;Nu;Nu],Nu,1,[1;1])
            else
             [model,graphics,ok]=check_io(model,graphics,[Nu;Nu;Nu],Nu,1,1)
            end
            model.in=[1;1;1]
           elseif (dyn_input==1)|(pnoise==1) then
            if sratio<>0 then
             [model,graphics,ok]=check_io(model,graphics,[Nu;Nu],Nu,1,[1;1])
            else
             [model,graphics,ok]=check_io(model,graphics,[Nu;Nu],Nu,1,1)
            end
            model.in=[1;1]
           else
            if sratio<>0 then
             [model,graphics,ok]=check_io(model,graphics,[Nu],Nu,1,[1;1])
            else
             [model,graphics,ok]=check_io(model,graphics,Nu,Nu,1,1)
            end
            model.in=1
           end

           if ok then

              ///
              if fnl==1 then
               while %t do
                ok2=%f;
                [ok2,gain,coef,plot_tanh,exprs2]=getvalue('Set Hyperbolic Tangent function',...
                ['Gain';'Coefficient';'Plot nonlinearity (0:no, or winid)'],...
                list('vec',1,'vec',1,'vec',1),exprs2);

                if ~ok2 then
                 exprs2=graphics.exprs(10:12); //pourquoi cela?
                 break
                end;

                if ok2 then
                 if plot_tanh<>0 then
                   win=xget("window")
                   xset("window",int(plot_tanh))
                   xset("wdim",300,200)
                   xbasc()
                   i=1:12
                   Fo=pulsation/(2*%pi)
                   plot2d(i,Fo+gain/(2*%pi)*tanh(coef*(i)),2);
                   xgrid(0);
                   xset("window",win);
                 end
                 break;
                end
               end
              else
               gain=evstr(exprs2(1))
               coef=evstr(exprs2(2))
              end
              ///

              ///
              if typ_noise==1 then
               while %t do
                 ok3=%f;
                 [ok3,m,sig,exprs3]=getvalue('Set White Noise on input command',...
                 ['Mean [rad/v]';'Variance [rad/v]'],...
                 list('vec',1,'vec',1),exprs3);

                 if ~ok3 then
                   exprs3=graphics.exprs(13:14); //pourquoi cela?
                  break
                 end;

                 if ok3 then
                   break
                 end
               end
             else
              m=evstr(exprs3(1))
              sig=evstr(exprs3(2))
             end
              ///

              if sratio<>0 then
                model.firing=[0;0]
                cross_2 = sratio
                sratio = 1
              else
                model.firing=[0]
                cross_2 = 0
              end

              ipar=[dyn_input;fnl;sratio;typ_noise;pnoise]
              rpar=[pas;pulsation;cross_1;cross_2;kv;gain;coef;m;sig]

              exprs=[exprs1(:)',exprs2(:)',exprs3(:)']
              graphics.exprs=exprs
              model.rpar=rpar(:)
              model.ipar=ipar(:)
              model.sim=list('vcoblk',4)
              model.dep_ut=[%f %f]
              x.graphics=graphics
              x.model=model
              break;
           end
        else
         message('Vector Pulsation and Vector Sensibilité must have the same size');
        end
   end

case 'define' then
  Nu=1;
  pulsation=2*%pi
  kv=2*%pi*1e3
  pas=0.1
  cross_1=2*%pi
  cross_2=2*%pi
  ci=zeros(10,1)
  dyn_input=0  //choix rapport de division dynamique
  fnl=0        //choix non linéarité
  typ_noise=0  //choix du bruit
  sratio=0     //deuxième diviseur de fréquence à rapport entier
  pnoise=0

  gain=1
  coef=1
  plot_tanh=0

  m=0
  sig=0

  ipar=[dyn_input;fnl;sratio;typ_noise;pnoise]
  rpar=[pas;pulsation;cross_1;cross_2;kv;gain;coef;m;sig]

  model=scicos_model()
  model.sim=list('vcoblk',4)
  model.in=Nu
  model.out=Nu
  model.evtin=1
  model.evtout=1
  model.dstate=ci(:)
  model.rpar=rpar(:)
  model.ipar=ipar(:)
  model.blocktype='d'
  model.firing=[0]
  model.dep_ut=[%f %f]

  gr_i=['xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');']
  exprs1=['2*%pi','2*%pi*1e3',sci2exp(pas),...
          '2*%pi',string(dyn_input),string(fnl),...
           string(typ_noise),string(sratio),string(pnoise)];
  exprs2=[sci2exp(gain),sci2exp(coef),string(plot_tanh)]
  exprs3=[string(m),string(sig)]
  exprs=[exprs1,exprs2,exprs3]
  x=standard_define([2.5 2],model,exprs,gr_i)
end
endfunction