function [ret,x0,str]=psddemo(t,x,u,flag);
%PSDDEMO	is the M-file description of the SIMULINK system named PSDDEMO.
%	The block-diagram can be displayed by typing: PSDDEMO.
%
%	SYS=PSDDEMO(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 PSDDEMO 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 PSDDEMO with a FLAG of zero:
%	[SIZES]=PSDDEMO([],[],[],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,345,125])
     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',	'')


%     Subsystem  ['Power spectral',13,'density'].

new_system([sys,'/',['Power spectral',13,'density']])
set_param([sys,'/',['Power spectral',13,'density']],'Location',[0,0,287,181])

add_block('built-in/Inport',[sys,'/',['Power spectral',13,'density/input signal']])
set_param([sys,'/',['Power spectral',13,'density/input signal']],...
		'Port','1',...
		'position',[50,55,70,75])

add_block('built-in/S-function',[sys,'/',['Power spectral',13,'density/S-function block ',13,'which calls M-file']])
set_param([sys,'/',['Power spectral',13,'density/S-function block ',13,'which calls M-file']],...
		'function name','sfunpsd',...
		'parameters','fftpts,npts,HowOften,offset,ts,0',...
		'position',[160,46,210,84])
add_line([sys,'/',['Power spectral',13,'density']],[75,65;155,65])
set_param([sys,'/',['Power spectral',13,'density']],...
		'Mask Display','plot(0,0,100,100,[14,91,91,14,14],[86,86,40,40,86],[85,82,80,79,75,67,63,60,57,53,41,36,33,27,24],[49,50,53,50,49,51,54,66,54,50,50,52,81,51,49])')
set_param([sys,'/',['Power spectral',13,'density']],...
		'Mask Type','Spectrum analayser.',...
		'Mask Dialogue','Spectrum anlayser using graph window.|Length of buffer:|Number of points for fft:|Plot after how many points:|Sample time:')
set_param([sys,'/',['Power spectral',13,'density']],...
		'Mask Translate','npts=@1; fftpts=@2; HowOften=@3; ts=@4(1); if length(@4) > 1, offset = @4(2), else, offset = 0; end')
set_param([sys,'/',['Power spectral',13,'density']],...
		'Mask Help','This block when hooked to the output of a system displays the frequency content of the buffer in the graph window. For more information, see the M-file sfunpsd.')
set_param([sys,'/',['Power spectral',13,'density']],...
		'Mask Entries','128\/512\/64\/0.1\/')


%     Finished composite block ['Power spectral',13,'density'].

set_param([sys,'/',['Power spectral',13,'density']],...
		'position',[225,40,255,80])

add_block('built-in/Signal Generator',[sys,'/','Signal Gen.'])
set_param([sys,'/','Signal Gen.'],...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','5.000000',...
		'Freq Range','15.625000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[65,43,110,77])
add_line(sys,[115,60;220,60])
% 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
