%
% PURPOSE: Examine impulse response versus time constant.  This was
% regarding the effect of the KVH spikes on Mike's filter.

% AUTHOR:  Rob McEwen
% DATE:    98/11/9
%
% NOTE: The corner frequency = bandwidth (-3dB) for Butterworth only.
%
 Tf = 2;      %Max time in sec for plot
 Ff = 100;    %Max freq in Hz for plot
%
% Butterworth Filter Analysis
%
 fs    = 20;          % Sampling rate, Hertz
 tau   = 20;          % Filter time constant, seconds
 order = 4;           % Filter order
%
 Ts = 1/fs;
 fc = 1/tau/2/pi;     % Filter corner frequency
 fc1= .2;             % Hertz
 fc2= 1;              % Hertz
 fc3= 2;              % Hertz
%
% In Matlab, the frequency argument to a filter function must be 
% normalized by the Nyquist frequency.
% 
 [bb,aa] = butter(order,fc1/fs/2);
 buttersys1 = tf(bb,aa,Ts);
 [bb,aa] = butter(order,fc2/fs/2);
 buttersys2 = tf(bb,aa,Ts);
 [bb,aa] = butter(order,fc3/fs/2);
 buttersys3 = tf(bb,aa,Ts);
 figure(1);
 clf;
 impulse(buttersys1, buttersys2, buttersys3);
 figure(2);
 clf;
 bode(buttersys1, buttersys2, buttersys3);
 [zz,pp,kk] = butter(order,fc1/fs/2);
 disp 'BUTTERWORTH # 1'
 zrootinfo1(pp,Ts);
 [zz,pp,kk] = butter(order,fc2/fs/2);
 disp 'BUTTERWORTH # 2'
 zrootinfo1(pp,Ts);
 [zz,pp,kk] = butter(order,fc3/fs/2);
 disp 'BUTTERWORTH # 3'
 zrootinfo1(pp,Ts);

