  % data cruncher and calibrator for MPX-5 

% This program dimensionalizes and plots the flight test data.  This 
% file also adds time lead if desired.  The different time histories 
% will require different calibrations.   



  l=length(file);

  time= file(3:l,1);



% Alpha lead is alead/100; 
  alead =0.0;

  AL = [file((3+alead):l,2)'  file(l,2)*ones(alead,1)']';

  alpha =(-14.99*AL +36.58);  


% Elevator Lead is elead/100; seconds 

   elead = 7.0;
        

  el = [file((3+elead):l,3)'  file(l,3)*ones(elead,1)']';


%  Calibration for old data (DR series data) 
    de = (17.14*el -40.45);


%   TIME DELAY in Normal Acceleration

%    slnt = file(l,5)*ones(1,5);
    
%    naz = [file(8:l,5)' slnt]'; 

      naz = file(3:l,5);

  az = (2.0*naz - 4.84); 

   v = 3.28*interp1(vel(:,2),vel(:,1),file(3:l,7))./cos(alpha/57.3);


% TIME LEAD in Pitch RATE is qlead/100 seconds

     qlead = 6.0;

     slant = file(l,8)*ones(1,qlead);

     nq = [file((3+qlead):l,8)' slant]';
  

 
     q = (39.4*nq - 93.37); 
     qq=q;

  

 % num=[10];
 % den=[1 10];

 
      
 % [alpha,x]=lsim(num,den,alpha,time);
 % [de,x]=lsim(num,den,de,time);
 % [az,x]=lsim(num,den,az,time);
                        
 % [q,x]=lsim(num,den,q,time);
 % [beta,x]=lsim(num,den,beta,time);


  clg

  figure(1)
  subplot(5,1,2),plot(time,alpha) 
  grid
%  xlabel('time (sec)')
  ylabel('alpha (deg)')
%  print -Pgq  
 
  subplot(5,1,1),plot(time,de);
%  xlabel('time (sec)')
  ylabel('de (deg)') 
  grid 
%  axis([0.0 12 -30 30])
%  print  -Pgq

  subplot(5,1,3),plot(time,az)
  grid 
%  xlabel('time (sec)')
  ylabel('az (g)')
%  print -Pgq


   subplot(5,1,5), plot(time,v)
   grid  
%  axis([0.0 12 0 100])
   xlabel('time (sec)')
   ylabel('velocity (ft/sec)') 


%  print -Pgq  

   subplot(5,1,4),plot(time,q)
%   xlabel('time (sec)')
   ylabel('q (deg/sec)')
   grid
%   print -Pgq
 
   

%   plot(time,beta)
%   xlabel('time (sec)')
%   ylabel('beta')
%   title(r)
%   grid
%   print -Pgq

         
