function xdot = lim_filt2(t,x)
% 
%  Second-order linear model with limiter; augmented with Fourier
%  integrals, used to obtain G(jw,a)
%
%  JH Taylor, 5 December 1998 -- revised 10 July 2002
%
%  to get G(jw,a): [mag,phase] = ggen(model,a,w,ns,magtol,phtol,dim)
%  example: >> [mag,phase] = ggen('lim_filt2',1.5,0.2,4,1,5)
%  -> mag & phase for model "lim_filt2", a = 1.5,  w = 0.2 rad/sec,
%     # states = 4, magnitude_tolerance = 1 dB, phase_tol = 5 deg
  
load temp_gwsim % get a, w, ns from file written by sidf_io
if ns ~= 4, error('Sorry - I have 4 states'); end ;
%% 
u = a*sin(w*t);
zeta = 0.15;  % damping
xdot(1) = x(2);
xdot(2) = u - x(1) - 2*zeta*x(2);
%% the PLANT is second-order, but we need to define the output y
%% and set up the Fourier integrals:  The following is a limiter --
if abs(x(1)) < 1
   y = x(1);
else
   y = sign(x(1));
end
xdot(3) = y*sin(w*t);  % in-phase Fourier integral
xdot(4) = y*cos(w*t);  % quadrature Fourier integral
xdot = xdot(:);        % needed for matlab 5.x and higher
%% end of model lim_filt2
