function [ret,x0,str]=simident(t,x,u,flag);
%SIMIDENT	is the M-file description of the SIMULINK system named SIMIDENT.
%	The block-diagram can be displayed by typing: SIMIDENT.
%
%	SYS=SIMIDENT(T,X,U,FLAG) returns depending on FLAG certain
%	system values given time point, T, current state vector, X,
%	and input vector, U.
%	FLAG is used to indicate the type of output to be returned in SYS.
%
%	Setting FLAG=1 causes SIMIDENT to return state derivitives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling SIMIDENT with a FLAG of zero:
%	[SIZES]=SIMIDENT([],[],[],0),  returns a vector, SIZES, which
%	contains the sizes of the state vector and other parameters.
%		SIZES(1) number of states
%		SIZES(2) number of discrete states
%		SIZES(3) number of outputs
%		SIZES(4) number of inputs.
%	For the definition of other parameters in SIZES, see SFUNC.
%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.

%	Copyright (c) 1990-94 by The MathWorks, Inc.

% Note: This M-file is only used for saving graphical information;
%       after the model is loaded into memory an internal model
%       representation is used.

% the system will take on the name of this mfile: 
sys = mfilename;
new_system(sys)
simver(1.3)
if(0 == (nargin + nargout))
     set_param(sys,'Location',[0,0,634,232])
     open_system(sys)
end;
set_param(sys,'algorithm',		'Euler')
set_param(sys,'Start time',	'0.0')
set_param(sys,'Stop time',		'200')
set_param(sys,'Min step size',	'1e16')
set_param(sys,'Max step size',	'1e16')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',	'')

add_block('built-in/Signal Generator',[sys,'/','Noise'])
set_param([sys,'/','Noise'],...
		'Drop Shadow',4,...
		'Peak','0.010000',...
		'Peak Range','0.125000',...
		'Freq','1.000000',...
		'Freq Range','1.315789',...
		'Wave','Rnd',...
		'Units','Rads',...
		'position',[50,173,95,207])

add_block('built-in/Sum',[sys,'/','Diff'])
set_param([sys,'/','Diff'],...
		'ForeGround',0,...
		'hide name',0,...
		'Drop Shadow',4,...
		'inputs','++',...
		'position',[155,140,175,160])

add_block('built-in/Note',[sys,'/',['Try different model',13,'estimators:']])
set_param([sys,'/',['Try different model',13,'estimators:']],...
		'position',[540,65,541,66])

add_block('built-in/Note',[sys,'/','Start the simulation to see an estimate of the filter:'])
set_param([sys,'/','Start the simulation to see an estimate of the filter:'],...
		'position',[220,25,221,26])

add_block('built-in/Discrete Transfer Fcn',[sys,'/','Dis. Transfer Fcn'])
set_param([sys,'/','Dis. Transfer Fcn'],...
		'ForeGround',0,...
		'hide name',0,...
		'Drop Shadow',4,...
		'Numerator','[1 2 3]',...
		'Denominator','[1 1.11 0.33 0.03]',...
		'Sample time','0.05',...
		'position',[220,129,420,171])

add_block('built-in/Signal Generator',[sys,'/','Input signal'])
set_param([sys,'/','Input signal'],...
		'Drop Shadow',4,...
		'Peak','1.000000',...
		'Peak Range','2.272727',...
		'Freq','0.875000',...
		'Freq Range','6.250000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[50,88,95,122])


%     Subsystem  ['AutoRegressive ',13,'with eXternal input',13,'model estimator'].

new_system([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],'Location',[0,0,371,185])

add_block('built-in/Inport',[sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/input noise']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/input noise']],...
		'Port','3',...
		'position',[55,140,75,160])

add_block('built-in/Mux',[sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/Mux']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/Mux']],...
		'inputs','3',...
		'position',[130,82,160,118])

add_block('built-in/Inport',[sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/system output']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/system output']],...
		'Port','2',...
		'position',[55,90,75,110])

add_block('built-in/S-function',[sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/S-function',13,'block']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/S-function',13,'block']],...
		'function name','sfunid',...
		'parameters','order,npts,HowOften,offset,ts,method',...
		'position',[205,80,260,120])

add_block('built-in/Inport',[sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/system input']])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator/system input']],...
		'Port','1',...
		'position',[55,40,75,60])
add_line([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],[165,100;200,100])
add_line([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],[80,100;125,100])
add_line([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],[80,50;110,50;110,90;125,90])
add_line([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],[80,150;110,150;110,110;125,110])
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Mask Display','ARX',...
		'Mask Type','ARX')
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Mask Dialogue','ARX model estimator.\nHook input 1 to system input.\nHook input 2 to system output.|Length of buffer:|Orders of model [na nb nk]:|Calculate after how many points:|Sample time:')
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Mask Translate','method = ''arx''; npts=@1; order=@2; HowOften=@3; ts=@4(1); if length(@4) > 1, offset = @4(2), else, offset = 0; end')
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Mask Help','Hook the system''s input to the first port of this block and the system''s output to second port. The input noise, which is optional, may be hooked to input 3.\nResults are displayed as the estimated output versus the true output in graphical form. Use signals with high harmonic content for best results. ')
set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Mask Entries','256\/[3 4 0]\/64\/0.05\/')


%     Finished composite block ['AutoRegressive ',13,'with eXternal input',13,'model estimator'].

set_param([sys,'/',['AutoRegressive ',13,'with eXternal input',13,'model estimator']],...
		'Drop Shadow',4,...
		'position',[535,122,580,178])
add_line(sys,[180,150;215,150])
add_line(sys,[100,190;115,190;115,155;150,155])
add_line(sys,[100,105;115,105;115,145;150,145])
add_line(sys,[425,150;530,150])
add_line(sys,[100,105;475,105;475,130;530,130])
add_line(sys,[100,190;475,190;475,170;530,170])
% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,xstr]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str] = feval(sys);
	end
end
