% Multiple Coupled Systems Response Demonstration
% 
% MULTISYS  illustrates the responses of a series of coupled measurement
% systems or "stages," to various forcing functions input to the first 
% stage.  Specifically, the output y of one stage becomes the input F to 
% the next, with no loading of the previous stage.  The default setup is
% a first-order system with characteristic time 0.159 seconds, followed
% by two second-order systems with natural frequency 1 Hz, the first
% being over-damped and the second under-damped.  This could represent
% a temperature display system.  The first stage is a miniature thermo-
% pile giving voltage output.  The second stage is a signal conditioning 
% circuit with high input impedence and amplifier-powered output.  The
% third stage is a large electro-mechanical dial indicating voltage.
% A dial arm such as that tends to be under-damped.
% The default input is a square wave made up of line segments, showing 
% the startup from initial conditions.  The steady response to a simple 
% harmonic input is also  shown.  The user can also specify a custom 
% forcing function to replace the square wave.
% The display is set by one of four modes, selected by the popup menu 
% labeled "Window Mode."
% 
% LINE SEGMENTS MODE
% In line segments mode, the forcing function is made up of the lines 
% connecting the points given in arrays t and F.  The default contents
% of t and F are:
% t=[0 0.499 0.5 0.999 1 1.499 1.5 1.999 2 2.499 2.5 3]';
% F=[1 1 -1 -1 1 1 -1 -1 1 1 -1 -1]';
% comprising a near-perfect square wave.  The interpolation scheme
% requires time to strictly increase, hence the use of the narrow but
% nonzero interval from 0.499 to 0.5 for instance.
% The startup responses of the coupled measurement systems, to this 
% forcing function, are calculated numerically using the Matlab routine 
% ODE45().  The initial conditions of the system can be edited in the 
% design mode.  Pushing the "Return" button returns the responses to the 
% main workspace variables tout and yout.  First you must select the 
% output time basis.  The natural output of ODE45 uses non-uniform time 
% intervals for optimum accuracy and efficiency.  This is the time basis
% used in the display.  You can accept this tout by pressing the "Display" 
% button, or you can specify a uniform sampling frequency by pressing
% the "Resample" button.
%
% STEP INPUT MODE
% Shows the step response of the combined system, with the rise time and
% the settling time of the output stage indicated.  The step input is from
% the initial value Fi to the final value Ff at time zero.  In this case
% the initial conditions specified in the design are ignored; instead, the
% initial condition is the steady state response to input Fi.
% 
% STEADY HARMONIC MODE
% Shows the steady responses of the coupled measurement systems to a 
% sinusoidal forcing function.  In this case initial values are irrelevent.
% The response magnitude B, the total attenuation factor M, and the time 
% delay (Beta sub N, where N is the total system order) are indicated.
%
% DESIGN MODE
% The magnitude response, the phase response, and the system poles in the
% Laplace plane are shown.  Text in a box gives the system constants and
% initial condition for one of the stages.  A pull-down menu selects which
% stage is displayed.  By pushing the "Edit" button, the selected stage
% can be modified.  First the stage order, first or second, is selected.
% Then the stage constants and initial conditions are edited using an
% input dialog.  By pushing the "New" button, a new system is created with
% the specified total number of stages.  This erases all the old settings.
% The new system is designed to behave as a low-pass Butterworth filter
% of order N=2*Nstage-1 and cutoff frequency fc=1 Hz.  The first stage is
% first-order and all following stages are second-order, and all initial
% conditions are reset to zero.  Each stage can then be edited 
% individually.  Hint: a filter can be changed to a different cutoff
% frequency fc as follows:  change tau in the first stage to 1/(2*pi*fc),
% and change fn in each of the other stages to fc.
% 
% MULTISYS(t,F) starts the window in Line Segments mode, and uses
% the given columns of time data t and forcing function data F(t), to 
% replace the default line segments.  t must be strictly increasing.
%
% MULTISYS(tspan,'F') uses the function named 'F' for the
% forcing function.  tspan should be either a two-element array of
% the form [t0 tfinal], or else an array of all the times at which
% display points are desired.  This is consistent with ODE45.
% For example:
%       multisys([0 6*pi],'cos')
% this would use three cycles of the cosine function for input.
% 
% See also FOURCOEF, FUNSPECT, DATASPECT, FIRSTORD, 
% SECONDORD, and SAMPLING.
 
