%
%  match step response of wheel
%
%  inputs:  t = sample times, y = output at those times
%
function [B,b,Ts]= wheel_match;
%
%  load the data
%
  data = load('Step_Response_50');
  R = data(2,2);
  t = data(:,1);
  y = data(:,4); 
%
%  determine the sample interval Ts
%
  Ts = t(2) - t(1);
%
%  determine how many samples to use
%
  Tmax = 8.0;  % the last time to look at
  temp = find(t>=Tmax);
  N = temp(1);
  t = t(1:N);
  y = y(1:N);
%
%  guess the parameters
%
  C = 75; b = 0.983;
%
%  plot the measured and estimated values
%
  est_y = zeros(1,N);
  delay = 3;
%
  for i = delay:N
       n = i-delay;
       est_y(i) = C*(1-b^n);
  end;
  plot(t, y, 'r', t, est_y, 'b'); grid; xlabel('Time (sec)');
  title(['R = ', num2str(R,3) ', delay = ', num2str(delay,3) ', C = ', num2str(C,3) ', B = ', num2str(C*(1-b)/R,5) ', b = ', num2str(b,5) ',  Ts = ', num2str(Ts,5)]);
   legend('Mesaured','Estimated');