Code covered by the BSD License  

Highlights from
Simuwave

image thumbnail

Simuwave

by

 

A Simulink library for wavelet processing on 1-D signals

Register(t,x,u,flag,l)
function [sys,x0,str,ts] = Register(t,x,u,flag,l)
%	An S-function which implements a register of length l.
%   Input: u :    Single valued data at the current time which
%                 is being buffered.
%   Output:       past input values
%   Parameters:   l = length of register = delay + 1
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
	[sys,x0,str,ts] = mdlInitializeSizes(l);
	%%%%%%%%%%  
	% Update %
	%%%%%%%%%%
case 2,                                               
    sys = mdlUpdate(t,x,u);
	%%%%%%%%%%
	% Output %
	%%%%%%%%%%
case 3,                                               
    sys = mdlOutputs(t,x,u);    
	%%%%%%%%%%%%%
	% Terminate %
	%%%%%%%%%%%%%
case 9,
    sys = mdlTerminate;
	%%%%%%%%%%%%%%%%%%%%
	% Unexpected flags %
	%%%%%%%%%%%%%%%%%%%%
otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end
% end buffer
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes(W)
disp('Using Register.m');
if W < 2
	sizes = simsizes;
	sizes.NumContStates  = 0;
	sizes.NumDiscStates  = 0;
	sizes.NumOutputs     = W;
	sizes.NumInputs      = 1;
	sizes.DirFeedthrough = 1;
	sizes.NumSampleTimes = 1;
	sys = simsizes(sizes);
	x0  = [];
	str = [];
	ts  = [-1 0];
else
	sizes = simsizes;
	sizes.NumContStates  = 0;
	sizes.NumDiscStates  = W-1;
	sizes.NumOutputs     = W;
	sizes.NumInputs      = 1;
	sizes.DirFeedthrough = 1;
	sizes.NumSampleTimes = 1;
	sys = simsizes(sizes);
	x0  = zeros(W-1,1);
	str = [];
	ts  = [-1 0];
end
% end mdlInitializeSizes
%
%=======================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=======================================================================
%
function sys = mdlUpdate(t,x,u)
W = length(x);
if W < 1
	sys = [];
else
	% Denoting the current time instant by t, we have:
	% x(1) = u(t), ..., x(W) = u(t-(W-1)).
	if W > 1
		x(2:W) = x(1:W-1);
	end
	x(1) = u;
	sys = x;
end
%end mdlUpdate
%
%=======================================================================
% mdlOutputs
% Return the output vector for the S-function
%=======================================================================
%
function sys = mdlOutputs(t,x,u)
if length(x) < 1
	sys = u;
else
	sys = [u;x];
end
%end mdlOutputs
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys = mdlTerminate
sys = [];
% end mdlTerminate

Contact us