Interfacing function
eng


MODPSK_f

File content


//MODPSK_f Scicos MPSK modulator block
//Classical interface function ver1.0 - scilab-2.7
//25 octobre 2003 Author : - IRCOM GROUP - A.Layec
function [x,y,typ]=MODPSK_f(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  nb=arg1.model.ipar;
//pause
  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;
   exprs=graphics.exprs;

   while %t do

      [ok,nb,herit,exprs]=getvalue('Set M-ary Phase Shift Keying modulator block',...
      ['Number of states';'Inherit (no:0, yes:1)'],...
      list('vec',-1,'vec',1),exprs);

      if ~ok then break,end;

      //teste si le nombre d'état est entier
      if ~is_int(nb) then
        message('The number of states must be integer.')
        ok=%F
      end
      nu=size(nb,'*')

        if ok then
           if herit==1 then
             model.dep_ut=[%t %f]
             [model,graphics,ok]=check_io(model,graphics,nu,[nu;nu],[],[])
           else
             model.dep_ut=[%t %f]
             [model,graphics,ok]=check_io(model,graphics,nu,[nu;nu],1,[])
           end
           graphics.exprs=exprs;
           model.ipar=nb(:);
           gr_i=get_gr_i()
           if size(nb,'*')<>1 then
             gr_i(50)='txt=[''  M - PSK'';''Modulator'']';
           else
             gr_i(50)='txt=[''  '+string(evstr(nb(1)))+' - PSK'';''Modulator'']';
           end
           graphics.gr_i(1)=gr_i
           x.graphics=graphics; x.model=model;
           break;
        end
   end

case 'define' then
  nb=4
  nu=1
  herit=1

  model=scicos_model()
  model.sim=list('modpsk',4)
  model.in=nu
  model.out=[nu;nu]
  model.evtin=[]
  model.evtout=[]
  model.dstate=[]
  model.rpar=[]
  model.ipar=nb
  model.blocktype='d'
  model.firing=[]
  model.dep_ut=[%t %f]
  gr_i=get_gr_i()
  exprs=[sci2exp(nb),string(herit)];
  x=standard_define([2 2],model,exprs,gr_i)
end
endfunction

//X est une matrice de réels
//tt est un boolean
function tt=is_int(X)
 Y=matrix(X,size(X,'*'),1);
 Z=int(X);
 tt=%t;
 for i=1:size(Y,1)
    if (Z(i)-Y(i))<>0 then
      tt=tt&%f;
    else
     tt=tt&%t;
   end
 end
endfunction

function txt=get_gr_i()
  txt=['thick=xget(''thickness'')'
        'pat=xget(''pattern'')'
        'fnt=xget(''font'')'
        'ln_st=xget(""line style"")'
        'sz1=0.86*sz(1);sz2=0.86*sz(2)'
        'xxs=orig(1)+sz(1)/2';
        'yys=orig(2)+sz(2)/2';
        'if nb(1)<16 then'
        '  ww=0.14*sz(1)'
        '  hh=0.14*sz(2)'
        '  eps_deg=10'
        'elseif nb(1)>=32 then'
        '  ww=0.06*sz(1)'
        '  hh=0.06*sz(2)'
        '  eps_deg=4'
        'else'
        '  ww=0.1*sz(1)'
        '  hh=0.1*sz(2)'
        '  eps_deg=7'
        'end'
        'aa1=0'
        'aa2=64*360'
        'xset(""line style"",2)'
        'for ii=1:nb(1)'
        '  phi(ii)=%pi*((2*(ii-1)+1)/nb(1))'
        'end'
        'phi_deg=phi*180/%pi'
        'for ii=1:nb(1)'
        '  phi_b=phi_deg(ii)'
        '  if ii<nb(1) then'
        '    phi_e=phi_deg(ii+1)'
        '  else'
        '    phi_e=phi_deg(1)+360'
        '  end'
        '  phi_d=phi_e-phi_b'
        '  xarc(xxs-sz1/2,yys+sz2/2,sz1,sz2,(phi_b+eps_deg)*64,(phi_d-2*eps_deg)*64)'
        'end'
        'xset(""line style"",ln_st)'
        'clear phi'
        'for ii=1:nb(1)'
        '   phi=%pi*((2*(ii-1)+1)/nb(1))'
        '   aa=cos(phi);bb=sin(phi)'
        '   xxx=xxs+sz1/2*aa-ww/2'
        '   yyy=yys+sz2/2*bb+hh/2'
        '   xfarc(xxx,yyy,ww,hh,aa1,aa2)'
        'end'
        'xpoly([xxs;xxs],[orig(2);orig(2)+sz(2)],""lines"")'
        'xpoly([orig(1);orig(1)+sz(2)],[yys;yys],""lines"")'
        'xset(''font'',5,0)'
        'txt=[''  M - PSK'';''Modulator''];'
        'style=5;'
        'rectstr=stringbox(txt,orig(1),orig(2),0,style,1);'
        'w=(rectstr(1,3)-rectstr(1,2))*%zoom;'
        'h=(rectstr(2,2)-rectstr(2,4))*%zoom;'
        'xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');'
        'e=gce();'
        'e.font_style=style;'
        'xset(''thickness'',thick)'
        'xset(''pattern'',pat)'
        'xset(''font'',fnt(1),fnt(2))']
endfunction