%
% PURPOSE: Backdifference Altex time to reveal jitter.
% AUTHOR: Rob McEwen
% DATE: 99/12/1
%
% MODS: 99/12/8 This doesn't work now; I've included the backdifference
% in DynamicControl.cc.

  Ts = .02    % seconds
  TsC= Ts*10; % seconds
  szS = size(dataSim);
  dimS = szS(1)-1;
  bdSTime = dataSim(2:szS(1),1) - dataSim(1:dimS,1);

  szC = size(dataDC);
  dimC = szC(1)-1;
  bdCTime = dataDC(2:szC(1),1) - dataDC(1:dimC,1);
  bdCTime2= dataDC(2:szC(1),2) - dataDC(1:dimC,2);



  aveSTs = mean(bdSTime);
  stdSTs = std(bdSTime);
  aveCTs = mean(bdCTime);
  stdCTs = std(bdCTime);

  disp([' The average Simulation sampling period is ' num2str(aveSTs)])
  disp([' The standard deviation is ' num2str(stdSTs) ...
        ' or ' num2str(stdSTs/aveSTs*100) ' percent.'])

  disp([' The average Simulation sampling period is ' num2str(aveCTs)])
  disp([' The standard deviation is ' num2str(stdCTs) ...
        ' or ' num2str(stdCTs/aveCTs*100) ' percent.'])

  caseName = 'QNX';
  str = [', Case:',caseName,' RSM ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 760];
  i = 0;

  i=i+1;
  figure(i)
  clf
  set(gcf,'position',FigurePosn)
  [tS, bdCTimeS] = stairs(dataDC(2:szC,1), bdCTime/TsC);
  [tS, bdCTimeS1]= stairs(dataDC(2:szC,1), bdCTime2/TsC);
  plot(tS, [bdCTimeS bdCTimeS1]);
  grid on
  ylabel('Number of Sample Periods')
  title(['Backdifference Control of Time, in Integer Sample Periods',str]);

  i=i+1;
  figure(i)
  clf
  set(gcf,'position',FigurePosn)
  [tS, bdCTimeS] = stairs(dataDC(2:szC,1), bdCTime/TsC);
  [tS, bdCTimeS1]= stairs(dataDC(2:szC,1), bdCTime2/TsC);
  plot(tS, [bdCTimeS bdCTimeS1]);
  grid on
  axis([2 10 .6 1.4])
  ylabel('Number of Sample Periods')
  title(['Backdifference Control of Time, in Integer Sample Periods',str]);


  return



  
  i=i+1;
  figure(i)
  clf
  set(gcf,'position',FigurePosn)
  plot(dataSim(2:szS,1), bdSTime/Ts);
  grid on
  axis([0 60 0 10])
  ylabel('Number of Sample Periods')
  title(['Backdifference of Simulation Time, in Integer Sample Periods',str]);

  i=i+1;
  figure(i)
  clf
  set(gcf,'position',FigurePosn)
  [tS, bdSTimeS] = stairs(dataSim(2:szS,1), bdSTime/Ts);
  plot(tS, bdSTimeS);
  grid on
  axis([2 5 0 10])
  ylabel('Number of Sample Periods')
  title(['Backdifference of Simulation Time, in Integer Sample Periods',str]);
