RIFGEN_f
//FILTER_f Scicos Temporal RIF with WFIR Impulse Response Calculation block
//Classical interface function ver1.0 - scilab-2.7
//19 novembre 2003 - IRCOM GROUP - Author : A.Layec
function [x,y,typ]=RIFGEN_f(job,arg1,arg2)
// Copyright INRIA
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;
model=arg1.model
graphics=arg1.graphics
exprs1=graphics.exprs(1:2)
exprs2=graphics.exprs(3:6)
exprs3=graphics.exprs(7:13)
exprs4=graphics.exprs(14:19)
exprs5=graphics.exprs(20:25)
exprs6=graphics.exprs(26:31)
while %t do
[ok,typ,herit,exprs1]=getvalue('Scicos FIR Block',...
['Type of FIR';'Inherit (no:0, yes:1)'],list('vec',1,'vec',1),exprs1);
if ~ok then break,end;
//Attention il y a un bug à corriger sur le
//comportement de la var ok (fait!)
if typ==1 then
[ok2,in_sz,Nu,nb_coef,pulse,exprs2]=get_genfir(exprs2)
elseif typ==2 then
[ok2,in_sz,Nu,nb_coef,pulse,exprs3]=get_wfir(exprs3)
elseif typ==3 then
[ok2,in_sz,Nu,nb_coef,pulse,exprs4]=get_rrcfir(exprs4)
elseif typ==4 then
[ok2,in_sz,Nu,nb_coef,pulse,exprs5]=get_rcfir(exprs5)
elseif typ==5 then
[ok2,in_sz,Nu,nb_coef,pulse,exprs6]=get_gfir(exprs6)
else
message('Type must be in the range [1..5]');
ok=%f;
end
if ok&ok2 then
model.in=sum(in_sz);
model.out=sum(in_sz);
model.dstate=zeros(sum(nb_coef),1);
model.ipar=[Nu;nb_coef(:);in_sz(:)];
model.rpar=pulse(:);
exprs=[exprs1(:)',exprs2(:)',exprs3(:)',exprs4(:)',exprs5(:)',exprs6(:)'];
graphics.exprs=exprs;
sz=model.in;
if herit==1 then
model.dep_ut=[%t %f];
[model,graphics,ok]=check_io(model,graphics,[sz],[sz],[],[]);
else
model.dep_ut=[%t %f];
[model,graphics,ok]=check_io(model,graphics,[sz],[sz],1,[]);
end
x.graphics=graphics
if typ==1 then
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''Generic'';'
'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;'
]
elseif typ==2 then
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''Wfir'';'
'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;'
]
elseif typ==3 then
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''RRCF'';'
'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;'
]
elseif typ==4 then
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''RCF'';'
'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;'
]
elseif typ==5 then
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''Gauss'';'
'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;'
]
end
graphics.gr_i=gr_i
x.graphics=graphics
x.model=model
end
break
end
case 'define' then
Nu=1
typ=1
herit=0
nb_coef=255
plot_rep=0
in_sz=1
//Generic
pulse_gen=[1;-1;1]
//WFIR
filtype="bp";
win_type="re";
low=0.05;
high=0.5;
dp=0.2;
df=0.1;
freq_ech=2;
[pulse,wfm,fr]=wfir(filtype,nb_coef,[low,high],win_type,[dp;df]);
freqband=string(low)+' '+ string(high);
dpdf=string(dp)+' '+string(df);
//filter_tap
fe=12
gain=1
r=0.35
b=0.5
model=scicos_model()
model.sim=list('nfilter',4)
model.in=Nu
model.out=Nu
model.evtin=1
model.evtout=[]
model.dstate=zeros(nb_coef*Nu,1)
model.rpar=pulse(:)
model.ipar=nb_coef
model.blocktype='d'
model.firing=[]
model.dep_ut=[%t %f]
exprs1=[string(typ),string(herit)] //global
exprs2=[string('-1'),sci2exp(pulse_gen),string(in_sz),string(plot_rep)] //genfir
exprs3=[string(nb_coef),string(freq_ech),string(filtype),string(freqband),string(win_type),string(dpdf),string(plot_rep)] //wfir
exprs4=[sci2exp(nb_coef),string(in_sz),sci2exp(fe),sci2exp(r),sci2exp(gain),string(plot_rep)] //rrcfir
exprs5=[sci2exp(nb_coef),string(in_sz),sci2exp(fe),sci2exp(r),sci2exp(gain),string(plot_rep)] //rcfir
exprs6=[sci2exp(nb_coef),string(in_sz),sci2exp(fe),sci2exp(b),sci2exp(gain),string(plot_rep)] //gfir
gr_i=['txt=[''FIR''];';
'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'
'txt=''Generic'';'
'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;'
]
exprs=[exprs1,exprs2,exprs3,exprs4,exprs5,exprs6]
x=standard_define([2.5 2],model,exprs,gr_i)
end
endfunction
function [ok,in_sz,Nu,nb_coef,pulse,exprs]=get_wfir(exprs)
in_sz=[];Nu=[];nb_coef=[];pulse=[];
while %t do
text=[
' WFIR Filter features. DELAY = (n-1) / 2 ';'';..
' PARAMETERS';..
'Size of the filter: filter order';..
'Type of the filter: filter definition';..
' lp - low pass';..
' hp - high pass';..
' bp - band pass';..
'[low,high] freq: 2-vector of cutoff';..
' frequencies (0<low,high<.5)';..
' only low is used when';..
' ftype=''lp'' or ''hp'' ';..
'Type of window: filtering window';..
' re - rectangular tr - triangular';..
' hn - Hanning hm - Hamming';..
' kr - Kaiser ch - Chebychev';..
' NB the last two parameters are used only';..
' for Chebychev and Kaiser window.';'';..
'It is defined as the convolution between';
'the input signal and the WFIR as defined in scilab.'
]
[ok,nb_coef,freq_ech,filtype,lowhigh,win_type,dpdf,plot_rep,exprs]=getvalue(text,..
['Size of the filter';..
'Sampling frequency';..
'Type of wfir filter (lp,hp,bp,sb)';..
'Low - High frequency cutoff';..
'Type of filtering window (re,tr,hn,hm,kr,ch)';..
'Chebychev or Kaiser window parameters: ';..
'Plot impulse response (0:No/Windows Id)?'
],..
list("vec",[1],"vec",[1],"str",[1],"vec",[2],"str",[1],"vec",[2],"vec",[1]),exprs)
low=lowhigh(1);high=lowhigh(2)
dp=dpdf(1);df=dpdf(2);
if ~ok then break,end
if ((filtype~="lp")&(filtype~="hp")&(filtype~="bp")&(filtype~="sb")) then
if (exists(filtype)) then
filtype = eval(filtype)
end
end
if ((win_type~="re")&(win_type~="tr")&(win_type~="hn")&..
(win_type~="hm")&(win_type~="kr")&(win_type~="ch")) then
if (exists(win_type)) then
win_type = eval(win_type)
end
end
if (nb_coef<0) then
message('size of the filter must be positive')
else
if (freq_ech<=0) then
message(' wrong sampling frequency value')
else
if (high<0)|(high/freq_ech>=0.5)|(low<=0)|(low>=high) then
message('wrong filter frequency cutoff values')
else
if (~((filtype=="bp")|(filtype=="lp")|(filtype=="hp")|..
(filtype=="sb"))) then
message('wrong filter type lp, hp, bp, sb')
else
if (~((win_type=="re")|(win_type=="tr")|(win_type=="hn")|..
(win_type=="hm")|(win_type=="kr")|(win_type=="ch"))) then
message('wrong filtering window type re,tr,hn, hm, kr or ch')
else
if ((win_type=="kr")&(dp<0)) then
message('wrong parameter value in Kaser window: beta>0')
else
if ((win_type=="ch")&((dp<=0)|(dp>=0.5)|(df<=0))) then
message('wrong parameter value in chebyshev window')
else
if ok then
low=low/freq_ech
high=high/freq_ech
[pulse,wfm,fr]=wfir(filtype,nb_coef,[low,high],win_type,[dp;df])
if plot_rep<>0 then
win=xget("window")
xset("window",int(plot_rep))
xset("wdim",300,200)
xbasc()
plot2d(fr*freq_ech,wfm,3,'111',' '+filtype+' Filters feature',[0,0,high*freq_ech*2,1]);
graph_title=['Chosen filter transfer function';' for '+filtype+' WFIR block']
x_label='Frequency';
y_label=['Gain values'];
xtitle(graph_title,x_label,y_label)
xset("window",win);
end
//To Be Done
Nu=1
in_sz=1
break
end
end
end
end
end
end
end
end
end
endfunction
function [ok,in_sz,Nu,nb_coef,pulse,exprs]=get_genfir(exprs)
Nu=[];
while %t do
[ok,nb_coef,pulse,in_sz,plot_rep,exprs]=getvalue('Set Generic Impulse Response Vector',...
['Number of coefficients';...
'Vector of impulse response';...
'Size of input vectors'
'Plot impulse response (0:No/Windows Id)?'],...
list('vec',-1,'vec',-1,'vec',-1,'vec',1),exprs)
if ~ok then break,end;
if ok then
//
if size(nb_coef,'*')<>1 then
Nu=prod(size(nb_coef))
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
function [ok,in_sz,Nu,nb_coef,pulse,exprs]=get_rrcfir(exprs)
Nu=[];pulse=[];
while %t do
[ok,nb_coef,in_sz,fe,r,gain,plot_rep,exprs]=getvalue('FIR with Root Raised Cosinus Response',...
['Size of the filter';...
'Size of input vectors';...
'Frequency Sampling';'Roll-Off Factor';'Output Gain';...
'Plot impulse response (0:No/Windows Id)?'],...
list('vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',1),exprs);
if ~ok then break,end;
if size(fe)==size(r)&size(r)==size(gain)&size(r)==size(nb_coef) then
Nu=prod(size(r))
r=r(:)
gain=gain(:)
nb_coef=nb_coef(:)
for j=1:Nu
if execstr('puls=filter_tap(1,nb_coef(j),fe(j),r(j),gain(j))','errcatch')<>0 then
message('Un paramètre est incorrect')
ok=%f
break
end
if j==1 then
ptri=1;
ptrf=nb_coef(1);
else
ptri=ptrf+1;
ptrf=ptri+nb_coef(j)-1;
end
pulse(1,ptri:ptrf)=puls
if plot_rep<>0 then
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
if ok then
break;
end
else
message('Frequency sampling vector,Vector Roll-Off, Vector Gain and Vector nb_coef must have the same size');
end
end
endfunction
function [ok,in_sz,Nu,nb_coef,pulse,exprs]=get_rcfir(exprs)
Nu=[];pulse=[];
while %t do
[ok,nb_coef,in_sz,fe,r,gain,plot_rep,exprs]=getvalue('FIR with Raised Cosinus Response',...
['Size of the filter';...
'Size of input vectors';...
'Frequency Sampling';'Roll-Off Factor';'Output Gain';...
'Plot impulse response (0:No/Windows Id)?'],...
list('vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',1),exprs);
if ~ok then break,end;
if size(fe)==size(r)&size(r)==size(gain)&size(r)==size(nb_coef) then
Nu=prod(size(r))
r=r(:)
gain=gain(:)
nb_coef=nb_coef(:)
for j=1:Nu
if execstr('puls=filter_tap(2,nb_coef(j),fe(j),r(j),gain(j))','errcatch')<>0 then
message('Un paramètre est incorrect')
ok=%f
break
end
if j==1 then
ptri=1;
ptrf=nb_coef(1);
else
ptri=ptrf+1;
ptrf=ptri+nb_coef(j)-1;
end
pulse(1,ptri:ptrf)=puls
if plot_rep<>0 then
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
if ok then
break;
end
else
message('Frequency sampling vector,Vector Roll-Off, Vector Gain and Vector nb_coef must have the same size');
end
end
endfunction
function [ok,in_sz,Nu,nb_coef,pulse,exprs]=get_gfir(exprs)
Nu=[];pulse=[];
while %t do
[ok,nb_coef,in_sz,fe,r,gain,plot_rep,exprs]=getvalue('FIR with Gaussian Response',...
['Size of the filter';...
'Size of input vectors';...
'Frequency Sampling';'BT Factor';'Output Gain';...
'Plot impulse response (0:No/Windows Id)?'],...
list('vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',-1,'vec',1),exprs);
if ~ok then break,end;
if size(fe)==size(r)&size(r)==size(gain)&size(r)==size(nb_coef) then
Nu=prod(size(r))
r=r(:)
gain=gain(:)
nb_coef=nb_coef(:)
for j=1:Nu
if execstr('puls=filter_tap(3,nb_coef(j),fe(j),r(j),gain(j))','errcatch')<>0 then
message('Un paramètre est incorrect')
ok=%f
break
end
if j==1 then
ptri=1;
ptrf=nb_coef(1);
else
ptri=ptrf+1;
ptrf=ptri+nb_coef(j)-1;
end
pulse(1,ptri:ptrf)=puls
if plot_rep<>0 then
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
if ok then
break;
end
else
message('Frequency sampling vector,Vector Roll-Off, Vector Gain and Vector nb_coef must have the same size');
end
end
endfunction