clear all
close all

path = 'X:\707976 EPBuoyPrototypeAndTesting\TestMachine\Test Data\March27_2012\';
filename = 'D000002_120327_150416';
load([path filename '.mat']);

figure

plot(diff(time-EpochSecs(1)));
xlabel('sample number')
ylabel('Time Difference');


figure
plot(time-EpochSecs(1),BatteryVoltage);
xlabel('time (seconds)');
ylabel('Battery Voltage');



idx = 1:15850;
figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 8.5 11]); 


ah1 = subplot(5,1,1)
plot(time(idx)-time(idx(1)),PistonDistance(idx));
xlabel('time (seconds)');
ylabel('Piston Distance (inches)');

ah2 = subplot(5,1,2)
plot(time(idx(1:end-1))-time(idx(1)),diff(PistonDistance(idx))/(time(idx(2))-time(idx(1))));
xlabel('time (seconds)');
ylabel('Piston Speed (ips)');

ah3 = subplot(5,1,3)
plot(time(idx)-time(idx(1)),RectifiedVoltage(idx));
xlabel('time (seconds)');
ylabel('Rectified Voltage (V)');

ah4 = subplot(5,1,4)
plot(time(idx)-time(idx(1)),RectifiedCurrent(idx));
xlabel('time (seconds)');
ylabel('Rectified Current (A)');


ah5 = subplot(5,1,5)
plot(time(idx)-time(idx(1)),ConvertedCurrent(idx));
xlabel('time (seconds)');
ylabel('Converted Current (A)');



linkaxes([ah1 ah2 ah3 ah4 ah5],'x');

print('-dpdf',[path 'LastHurrah2']);





figure('Position',[19 45 1538 1093],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 8.5 11]); 

ah1 = subplot(6,1,1)
plot(time-EpochSecs(1),RectifiedVoltage);
xlabel('time (seconds)');
ylabel('Rectified Voltage (V)');

ah2 = subplot(6,1,2)
plot(time-EpochSecs(1),RectifiedCurrent);
xlabel('time (seconds)');
ylabel('Rectified Current (A)');


ah3 = subplot(6,1,3)
plot(time-EpochSecs(1),ConvertedCurrent);
xlabel('time (seconds)');
ylabel('Converted Current (A)');

ah4 = subplot(6,1,4)
plot(time-EpochSecs(1),BatteryVoltage);
xlabel('time (seconds)');
ylabel('Battery Voltage (V)');

ah5 = subplot(6,1,5)
plot(time-EpochSecs(1),BatteryCurrent);
xlabel('time (seconds)');
ylabel('Battery Current (A)');

ah6 = subplot(6,1,6)
plot(time-EpochSecs(1),BatteryCurrent.*BatteryVoltage);
xlabel('time (seconds)');
ylabel('Battery Power (W)');


linkaxes([ah1 ah2 ah3 ah4 ah5 ah6],'x');

print('-dpdf',[path 'FailurePlot']);


figure
plot(time-EpochSecs(1),BatteryCurrent);
xlabel('time (seconds)');
ylabel('');

figure
plot(time-EpochSecs(1),LoadDumpVoltage);
xlabel('time (seconds)');
ylabel('Load Dump Voltage');

plot(time-EpochSecs(1),LoadDumpCurrent);
xlabel('time (seconds)');
ylabel('Load Dump Current');

figure
plot(time-EpochSecs(1),UpperSpringTemperature);
xlabel('time (seconds)');
ylabel('Upper Spring Temperature');

figure
plot(time-EpochSecs(1),LowerSpringTemperature);
xlabel('time (seconds)');
ylabel('Lower Spring Temperature');

figure
plot(time-EpochSecs(1),UpperSpringPressure);
xlabel('time (seconds)');
ylabel('Upper Spring Pressure');

figure
plot(time-EpochSecs(1),LowerSpringPressure);
xlabel('time (seconds)');
ylabel('Lower Spring Pressure');

figure
plot(time-EpochSecs(1),LoadCellForce);
xlabel('time (seconds)');
ylabel('Load Cell Force');

figure
plot(time-EpochSecs(1),PistonDistance);
xlabel('time (seconds)');
ylabel('Piston Distance');

figure
plot(time-EpochSecs(1),LoadDumpTemp);
xlabel('time (seconds)');
ylabel('Load Dump Temperature');

figure
plot(time-EpochSecs(1),LoadDumpRelayPos);
xlabel('time (seconds)');
ylabel('Load Dump Relay Position');

figure
plot(time-EpochSecs(1),SafetyRelayPos);
xlabel('time (seconds)');
ylabel('Extend/Retract Flag');


figure
ah1 = subplot(4,1,1)
plot(time-EpochSecs(1),'-x');
ylabel('Time (seconds)');

ah2 = subplot(4,1,2)
plot(diff(time-EpochSecs(1)),'-x');
ylabel('Time Difference');

ah3 = subplot(4,1,3)
plot(LoadDumpVoltage,'-x');
ylabel('Load Dump Voltage');

ah4 = subplot(4,1,4)
plot(LoadDumpCurrent/10,'-x');
xlabel('sample number');
ylabel('Load Dump Current');

linkaxes([ah1 ah2 ah3 ah4],'x');

figure
ah1 = subplot(2,1,1)
plot(LoadDumpVoltage(2:end),diff(time-EpochSecs(1)))
ylabel('Time Difference');
xlabel('Load Dump Voltage');

ah2 = subplot(2,1,2)
plot(LoadDumpCurrent(2:end)/10,diff(time-EpochSecs(1)))
ylabel('Time Difference');
xlabel('Load Dump Current');
