


  load qgyro 

  gt = qgyro;

  potbias= 5.30 

  p=[1 14];

 
 gt1=gt([3:length(gt)],[1:4]);

  t = gt1(:,1);
 
 gt1(:,2)=gt1(:,2)-potbias; 
 


   num=[41583];
   den = conv(conv(p,p),conv(p,p));




 gt1(:,2)=23.81*gt1(:,2);

  figure(1) 
  plot( gt1(:,1), gt1(:,2))
  grid on
  title('Angular position')
  xlabel('Seconds')
  ylabel('degrees')
   


  num=[41583 0];
  den = conv(conv(p,p),conv(p,p));


  

 [Y,X] = lsim(num,den,gt1(:,2),gt1(:,1));


 figure(2) 
 plot(gt1(:,1),Y)
 grid on
 title('Filtered Angular Rate')    
 xlabel('Seconds')
 ylabel('degrees')
        

 [Z,X]= lsim (num,den,gt1(:,3),t);
 figure(3) 
 plot(t,Z) 
  grid on
 title('Filtered Angular Rate')
 xlabel('Seconds')
 ylabel('Volts/second')


 [tg,X]=lsim(num,den,gt1(:,3),gt1(:,1));

 
  plot(tg(:,1),tg);


  plot(tg(500:1000),Y(500:1000));


  [p,S]=polyfit(tg(500:1000),Y(500:1000),1);,


  cal= p(1)*tg(500:1000) +p(2);

  hold on



  plot(tg(500:1000),cal,'--')





  hold off

 
  plot(gt1([500:1000],1),cal);
  hold on 
  plot(gt1([500:1000],1),gt1([500:1000],2));
  plot(gt1([500:1000],1),Y([500:1000]),'--');

 grid on
  


