%
%  This file processes the data from the first order system
%
function data = process_data;
%
%  enter the data as 
%  f (in Hz) Vin (in mV) Vout (in mV) Vin peak time (in ms) Vout peak time (in ms); 
%
  measured = [100 981 815 0.0 1.03;
              120 981 760 0.0 1.01;
              140 975 717 0.0 0.896;
              160 987 668 0.0 0.772;
              180 987 625 0.0 0.83;
              200 987 589 0.0 0.74;
              220 987 558 0.0 0.70;
              240 987 515 0.0 0.655;
              260 987 490 0.0 0.675;
              280 981 466 0.0 0.645;
              300 981 447 0.0 0.619;
              320 981 417 0.0 0.579;
              420 987 325 0.0 0.487;
              520 981 269 0.0 0.453;
              620 981 220 0.0 0.347;
              720 987 196 0.0 0.328;
              820 987 167 0.0 0.269;
              920 975 141 0.0 0.254;
              1020 987 116 0.0 0.223;
              1120 981 116 0.0 0.223;
              80 987 865 0.0 1.120;
              60 981 907 0.0 1.05;
              40 993 938 0.0 1.33;
              20 975 975 0.0 1.26
              ];
%
%  Be sure the rows are sorted by frequency
%
   measured = sortrows(measured,1);
%
%  get the frequency of the measurement
%
  f = measured(:,1); 
%
%  get the magnitude of the transfer function
%
  mag_H = measured(:,3)./measured(:,2);
%
%  compute the time delay of the transfer function
%
  td = measured(:,5)-measured(:,4);
%
%  compute the phase of the transfer function and convert to degrees
%
  phase_H = -td.*f*360/1000;
%
%  put the data into the data array
%
  data = [f mag_H phase_H];
%
  return;