PSPECSCOPE_c
//PSPECSCOPE_c Scicos vector memory visualization block
//Classical interface function ver1.0 - scilab-4.1
//24 Mars 2007 - INRIA - Author : A.Layec
function [x,y,typ]=PSPECSCOPE_c(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=[];
case 'getorigin' then
[x,y]=standard_origin(arg1)
case 'set' then
x=arg1;
graphics=arg1.graphics;
exprs=graphics.exprs(1:14); //for future work
model=arg1.model;
while %t do
[ok,nu,wid,Tse,fftsiz,wtyp,sec_s,n_sec,...
axlog,yunit,y_dim,cfreq,fdenorm,view_in,herit,...
exprs] = getvalue(..
'Set Scope parameters',..
['In size';
'Output window number (automatic:-1)';
'Sampling period';
'Size of input buffer (FFT size)';
'Type of window (re:1, tr:2, hm:3; hn:4)';
'Size of the overlap buffer';
'Number of average';
'Axes scale flags [X,Y] (LIN:0, LOG:1)';
'Y axis units (U^2:0, dB:1, dB/Hz:2)';
'Y axis bound [min,max] (autoscale:-1)';
'Center Frequency (plot from DC:-1)';
'Denormalization Frequency (no:0)';
'Display input buffer (no:0)';
'Inherit (no:0, yes:1)'],..
list('vec',1,..
'vec',1,..
'vec',1,..
'vec',1,..
'vec',1,..
'vec',1,..
'vec',1,..
'vec',-1,..
'vec',1,..
'vec',-1,..
'vec',1,..
'vec',1,..
'vec',1,..
'vec',1),exprs)
if ~ok then break,end //user cancel modification
mess=[]
//check values of user param
if Tse<=0 then
mess=[mess;'Sampling period must be greather than zero';' ']
ok=%f
end
if size(y_dim,'*')>=2 then
if y_dim(1)<>-1 & y_dim(2)<>-1 then
if y_dim(1)>=y_dim(2) then
mess=[mess;'Ymax must be greater than Ymin';' ']
ok=%f
end
end
end
if size(axlog,'*')<2 then
mess=[mess;'Bad size for Axes scale flags';' ']
ok=%f
else
if axlog(2)==1 & yunit==0 then
if size(y_dim,'*')>=2 then
if y_dim(1)<>-1 & y_dim(2)<>-1 then
if y_dim(1)<=0 | y_dim(2)<=0 then
mess=[mess;'Can''t use LOG y axis with '+...
'[ymin,ymax] negative values';' ']
ok=%f
end
end
end
end
end
if sec_s>fftsiz then
mess=[mess;'Overlap buffer size must be less or equal than '+...
'input buffer size';' ']
ok=%f
end
if ~ok then
message(['Some specified values are inconsistent:';
' ';mess])
end
//adjust size of ports block
if ok then
if nu==0 then nu=-1, end
if herit==1 then
[model,graphics,ok]=check_io(model,graphics,nu,[],[],[])
else
[model,graphics,ok]=check_io(model,graphics,nu,[],1,[])
end
end
//auto adjustement of some values
if ok then
if n_sec<=0 then n_sec=1, end
if Tse<=0 then Tse=1, end;
xlog=axlog(1); ylog=axlog(2);
if yunit>=1 then ylog=0, end
if xlog<>1 then xlog=0, end;
if ylog<>1 then ylog=0, end;
if yunit<>1&yunit<>2 then yunit=0, end;
if size(y_dim,'*')==1 then //autoscale
ymin=%eps;
ymax=1;
scaltyp=1
else
if y_dim(1)==-1 & y_dim(2)==-1 then //autoscale
ymin=%eps;
ymax=1;
scaltyp=1
else
ymin=y_dim(1);
ymax=y_dim(2);
scaltyp=0
end
end
if view_in<>1 then view_in=0, end;
end
//fft automatic switch algorithm
global MODNUMFFT
if MODNUMFFT==2 then
USE_FFTW=%t
else
USE_FFTW=%f
end
if USE_FFTW then
ffttyp=2
n_work=0
else
if (fftsiz<=2^15) then
m=2^(int(log10(fftsiz+0.5)/log10(2)));
if (m==fftsiz) then //fft842
ffttyp=0
n_work=0
else
[l,ierr]=dfftsize(fftsiz);
if ierr<>0 then
message(['Problem in the fft switch algorithm';
'Please change the size of the input buffer'])
ok=%f
else //fftmx
ffttyp=1
n_work=l
end
end
else
[l,ierr]=dfftsize(fftsiz);
if ierr<>0 then
message(['Problem in the fft switch algorithm';
'Please change the size of the input buffer'])
ok=%f
else //fftmx
ffttyp=1
n_work=l
end
end
end
//set model
if ok then
ipar=[fftsiz; //1
sec_s; //2
n_sec; //3
ffttyp; //4
n_work; //5
xlog; //6
ylog; //7
wtyp; //8
wid; //9
yunit; //10
scaltyp;//11
view_in;//12
]
rpar=[Tse;cfreq;fdenorm;ymin;ymax]
model.dstate=[0;0]
model.rpar=rpar(:)
model.ipar=ipar(:)
graphics.exprs(1:14)=exprs; //for future work
x.graphics=graphics;
x.model=model
break
end
end
case 'define' then
//ipar
wid = -1 //ipar(9)
fftsiz = 4096 //ipar(1)
sec_s = 1024 //ipar(2)
n_sec = 16 //ipar(3)
ffttyp = 0 //ipar(4)
n_work = 0 //ipar(5)
wtyp = 1 //ipar(8)
xlog = 0 //ipar(6)
ylog = 1 //ipar(7)
yunit = 0 //ipar(10)
scaltyp = 1 //ipar(11)
view_in = 0 //ipar(12)
ipar = [fftsiz; //1
sec_s; //2
n_sec; //3
ffttyp; //4
n_work; //5
xlog; //6
ylog; //7
wtyp; //8
wid; //9
yunit; //10
scaltyp;//11
view_in;//12
]
//rpar
Tse = 1 //rpar(1)
cfreq = -1 //rpar(2)
fdenorm = 0 //rpar(3)
ymin = %eps //rpar(4)
ymax = %eps //rpar(5)
rpar = [Tse;cfreq;fdenorm;ymin;ymax]
herit = 0
nu = -1
model=scicos_model()
model.sim=list('pspec_scope',4)
model.in=nu
model.out=[]
model.evtin=[1]
model.evtout=[]
model.dstate=[0;0]
model.ipar=ipar(:)
model.rpar=rpar(:)
model.blocktype='d'
model.firing=[]
model.dep_ut=[%t %f]
exprs=[string(nu) //1 in size
string(wid) //2 windows id
string(Tse) //3 sampling period
string(fftsiz) //4 size of fft
string(wtyp) //5 type of window
string(sec_s) //6 size of overlap
string(n_sec) //7 number of average
sci2exp([xlog ylog]) //8 axes lin/log flag
string(yunit) //9 y axis units
sci2exp([-1 -1]) //10 y axis bounds
string(cfreq) //11 plot from a center freq
string(fdenorm) //12 denormalization freq
string(view_in) //13 display input buffer
string(herit) //14 Inherit
];
gr_i=['thick=xget(''thickness'');';
'pat=xget(''pattern'');';
'fnt=xget(''font'');';
'xset(''thickness'',2);';
'xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);';
'l=0.12;';
'h=0.12;';
'a=orig(1)+sz(1)/5;';
'b=orig(1)+(1-1/5)*sz(1);';
'c=orig(2)+sz(2)/5;';
'd=orig(2)+(1-1/5)*sz(2);';
'ii=6;';
'll=(b-a)/(ii-1);';
'xd=(0:ii-1)*ll + a;';
//CAMARCHEDANSB4SCICOS
//'yd=rand(1:ii)*(d-c-h*sz(2)) + c + 0.5*h*sz(2);';
'yd=[0.9,0.4,0.8,0.7,0.3,0.5]*(d-c-h*sz(2)) + c + 0.5*h*sz(2);';
'xx=[orig(1)+sz(1)/5,xd;orig(1)+(1-1/5)*sz(1),xd];';
'yy=[orig(2)+sz(2)/5,c*ones(1,ii);orig(2)+sz(2)/5,yd];';
'xpoly(xx(:,1),yy(:,1));';
'for jj=2:(ii+1)';
' xpoly(xx(:,jj),yy(:,jj));';
// ' xfarc(xx(2,jj)-l/2*sz(1),yy(2,jj)+h*sz(2),l*sz(1),h*sz(2),0,64*360);';
'end';
'txt=''FFT'';'
'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));';
]
x=standard_define([2 2],model,exprs,gr_i)
end
endfunction