Interfacing function
eng


QPSKREC_f

File content


//QPSKREC_f Scicos Genreric QPSK Receiver block
//Classical interface function ver1.0 - scilab-3.0
//8 Février 2005  Author : - IRCOM GROUP - A.Layec
function [x,y,typ]=QPSKREC_f(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  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:6)
   exprs2=graphics.exprs(7:9)
   
   while %t do

      text=['Set Generic QPSK Receiver Block']
      [ok,nb_sym,nbit,typm,nech,typf,inits,exprs1]=getvalue(text,...
      ['Number of Symbols';...
      'Number of bits per symbol'
      'Type of Modulation(0:PSK,1:QAM)';...
      'Samples per symbol';...
      'Type of filtering(0:No filter,1:Generic,2:RRC,3:RC,4:Gauss)';...
      'Initial counter value of Symbol integral'],...
      list('vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1),exprs1)

      if ~ok then break,end;
      
      herit=1
      if(nb_sym<0) then
        message('Only vectorial input is allowed');
        ok=%f
      end
      flag_seq=0;

      if(typm<>0) then
       message('Only PSK Modulation is activated')
       ok=%f
      end
      
      if(nbit<1) then
       message('Number of bits : Wrong parameter')
       ok=%f
      end
      
      sz_in=nb_sym*nech; // input size
      
      if typf==0 then
         nb_coef=nb_sym;
         m1=0;
         pulse=0;
      //Attention il y a un bug à corriger sur le 
      //comportement de la var ok
      elseif typf==1 then
        Nu=-1;
        [ok,Nu,nb_coef,pulse,exprs2]=get_genfir(exprs2)
        m1=2^(int(log(sz_in+nb_coef-1)/log(2))+1) //size of fft input (for zero pading)
      else
       message('Only No Filter and Generic filter are activated')
       ok=%f
      end
     
      m=2^nbit; //number of states
      initso=0; //initial counter of downsampler
      step=1/nech; //Integration step of symbol integral
      amplc=sqrt(2)/2; //Amplitude of output comparator
  
      if ok then
          if herit==1 then
            model.dep_ut=[%t %f]
            if (nbit>1) then
             [model,graphics,ok]=check_io(model,graphics,[sz_in;sz_in],[nb_sym],[],[])
             model.in=[sz_in;sz_in]
            elseif(nbit==1) then
             [model,graphics,ok]=check_io(model,graphics,[sz_in],[nb_sym],[],[])
             model.in=[sz_in]
            end
            model.out=[nb_sym]
            model.evtin=[]
          else
            model.dep_ut=[%f %f]
            if (nbit>1) then
             [model,graphics,ok]=check_io(model,graphics,[sz_in;sz_in],[nb_sym],1,[])
             model.in=[sz_in;sz_in]
            elseif(nbit==1) then
             [model,graphics,ok]=check_io(model,graphics,[sz_in],[nb_sym],[],[])
              model.in=[sz_in]
            end
            model.out=[nb_sym]
            model.evtin=1
          end
          exprs=[exprs1(:)',exprs2(:)']
          graphics.exprs=exprs
          model.dstate=[zeros(nb_coef,1);zeros(nb_coef,1);0;0]
          model.rpar=[pulse(:);step;amplc]
          model.ipar=[nb_coef;m1;nech;inits;initso;m]
          x.graphics=graphics;x.model=model
          break;
      end
   end

case 'define' then
  nb_sym=64 //Number of symbol (output size)
  nbit=2 //Lenght of symbol
  typm=0; //Type of modulation
  nech=12 //Downsample factor
  typf=0; //Type of filtering
  inits=1; //initial counter of symbol integral
  
  flag_seq=0; //Type of receptor(0:vectorial;1:sequential)
  herit=1;
  
  sz_in=nb_sym*nech; // input size
  m=2^nbit; //number of states
  initso=0; //initial counter of downsampler
  step=1/nech; //Integration step of symbol integral
  amplc=sqrt(2)/2; //Amplitude of output comparator
  
  
  //Generic
  pulse=[1;-1;1] //impulse response
  nb_coef=3 //number of filter tap
  plot_rep=0 //flag for plotting rep impulse in graph wind
  m1=2^(int(log(sz_in+nb_coef-1)/log(2))+1) //size of fft input (for zero pading)
  
  //filter_tap
  fe=12 //frequency sampling
  gain=1 //output gain of filter
  r=0.35 //roll-off factor (for RRC,RC)
  b=0.5 //BT factor (for gauss)
  
  model=scicos_model()
  model.sim=list('mpskrec',4)
  model.in=[sz_in;sz_in]
  model.out=[nb_sym]
  model.evtin=[]
  model.evtout=[]
  model.dstate=[zeros(nb_coef,1);zeros(nb_coef,1);0;0]
  model.rpar=[pulse(:);step;amplc]
  model.ipar=[nb_coef;m1;nech;inits;initso;m]
  model.blocktype='d'
  model.firing=[]
  model.dep_ut=[%t %f]

  gr_i=['txt=[''QPSK'';''Receiver''];';
        'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
       ]
  //exprs=[string(nb_sim)]
  exprs1=[string(nb_sym),string(nbit),string(typm),string(nech),string(typf),string(inits)]
  exprs2=[string('-1'),sci2exp(pulse),string(plot_rep)] //genfir
  
  exprs=[exprs1,exprs2]
  
  x=standard_define([2 2],model,exprs,gr_i)
end
endfunction


function [ok,Nu,nb_coef,pulse,exprs]=get_genfir(exprs)
  while %t do
   [ok,nb_coef,pulse,plot_rep,exprs]=getvalue('Set Generic Impulse Response Vector',...
   ['Number of coefficients';...
    'Vector of impulse response';...
    'Plot impulse response (0:No/Windows Id)?'],...
   list('vec',-1,'vec',-1,'vec',1),exprs)
   
   if ~ok then break,end;
   
    Nu=prod(size(nb_coef))
   if Nu<>1 then
    message('Sorry, for the moment only one scalar or vector of symbol can be generated');
    ok=%f
   end
   
   if ok then
    //
    if size(nb_coef,'*')<>1 then
    
     nb_coef=nb_coef(:)
     ptri=1
     ptrf=nb_coef(1)
    elseif nb_coef==-1 then
     Nu=1;
     nb_coef=size(pulse,'*')
     ptri=1
     ptrf=nb_coef
    else
     Nu=1;
     ptri=1
     ptrf=nb_coef
    end
    
    pulse=pulse(:);
    for j=1:Nu
     if j>1 then
     ptri=ptrf+1
     ptrf=ptri+nb_coef(j)-1
     end
     if plot_rep<>0 then
        puls=pulse(ptri:ptrf);
        win=xget("window");
        xset("window",int(plot_rep+j-1));
        xset("wdim",300,200);
        xbasc();
        plot2d3(1:nb_coef(j),puls,,"111",,rect=[0,min(puls),nb_coef(j),max(puls)]);
        xset("window",win);
     end
    end
    break;
   end
  end
endfunction