Fonction d'interfaçage
fr
DEMODQAM_f
//DEMODQAM_f Scicos MQAM Demodulator block
//Classical interface function ver1.0 - scilab-3
//5 janvier 2005 - IRCOM GROUP - Author : A.Layec
function [x,y,typ]=DEMODQAM_f(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
// nb=arg1.model.ipar;
nb=2^(arg1.model.ipar);
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 Quadrature Amplitude Modulation demodulator block',...
['Number of states';'Inherit (no:0, yes:1)'],...
list('vec',-1,'vec',1),exprs);
if ~ok then break,end;
//Calcule le nombre de bit correspondant au(x) nombre(s) d'états
ipar=log(nb)/log(2)
ipar=ipar(:)
//Teste la parité du nombre de bit
for i=1:size(ipar,'*')
if (ipar(i)/2)<>int(ipar(i)/2) then
message('The number of states must be correctly selected.')
ok=%F
break
end
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=ipar(:);
gr_i=get_gr_i();
if size(nb,'*')<>1 then
gr_i(42)='txt=['' M - QAM'';''Demodulator'']';
else
gr_i(42)='txt=['' '+string(evstr(nb(1)))+' - QAM'';''Demodulator'']';
end
graphics.gr_i(1)=gr_i;
x.graphics=graphics; x.model=model;
break;
end
end
case 'define' then
nb=16
nu=1
herit=1
model=scicos_model()
model.sim=list('demodqam',4)
model.in=[nu;nu]
model.out=nu
model.evtin=[]
model.evtout=[]
model.dstate=[]
model.rpar=[]
model.ipar=log(nb)/log(2)
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
//tt est une chaine texte
//X est une matrice d'entier
function tt=dec2bin(X)
if X==0 then
tt="0"
return
end
tt_t=""
while X<>0
res=int(X/2)
if (X-2*res)==1 then
tt_t=tt_t+"1"
else
tt_t=tt_t+"0"
end
X=res
end
tt=""
for i=length(tt_t):-1:1
tt=tt+part(tt_t,i)
end
endfunction
function tt=adjust_binsize(tt,n)
l_tt=length(tt)
if n<>l_tt then
for j=l_tt:n-1
tt="0"+tt;
end
end
endfunction
function [tt_a,tt_b]=cut_bin(tt,n)
tt_a="";
tt_b="";
for j=1:length(tt)
if j>n then
tt_b=tt_b+part(tt,j);
else
tt_a=tt_a+part(tt,j);
end
end
endfunction
function X=bin2dec(tt)
X=0;
for j=0:length(tt)-1
if part(tt,j+1)=="1" then
X=X+2^(length(tt)-j-1)
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.75*sz(1);sz2=0.75*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'
'l_tt=length(dec2bin(nb(1)-1))'
'for i=1:nb(1)'
' tt(i)=dec2bin(i-1)'
' tt(i)=adjust_binsize(tt(i),l_tt)'
' [tt_a(i),tt_b(i)]=cut_bin(tt(i),l_tt/2)'
' a(i)=bin2dec(tt_a(i))'
' b(i)=bin2dec(tt_b(i))'
'end'
'a=(a/max(a)-0.5)*2'
'b=(b/max(b)-0.5)*2'
'for ii=1:nb(1)'
' aa=a(ii);bb=b(ii)'
' 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 - QAM'';''Demodulator''];'
'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