%% Helios Short Test Flight Data Analysis 7-23-16
% Leads: Joseph Breeden & Christopher Bernard

% Open File
dataLog = fopen('DATALOG.txt','r');
formatSpec = '%d %f %f %d %d %d %f %f %d %d %d %d %d ';
sizeRaw = [13 Inf];
raw = fscanf(dataLog,formatSpec,sizeRaw);
fclose(dataLog);
raw = raw';

% Take out bad data
raw(2376:2402,:) = [];

% Set Arrays
time = raw(:,1); % Time in Milliseconds

% Pressure Graph
plot(time,raw(:,2),'r')
hold on
plot(time,raw(:,7),'b')
hold off
axis([0 3500000 95000 101000])
title('Pressure vs Time');
xlabel('Time (ms)')
ylabel('Pressure (Pa)')
grid on
text(2000000,97500,{'Blue = Inside Balloon','Red = Outside Balloon'})

% Pressure Differance Graph
figure();plot(time,raw(:,2) - raw(:,7),'m')
axis([0 3500000 -1000 1000])
title('Pressure Diff vs Time');
xlabel('Time (ms)')
ylabel('Pressure Differance (Pa)')
grid on

% Temp Graph
figure();plot(time,raw(:,3),'r')
hold on
plot(time,raw(:,8),'b')
hold off
title('Temperature vs Time');
xlabel('Time (ms)')
ylabel('Temperature (dC)')
text(2000000,28,{'Blue = Inside Balloon','Red = Outside Balloon'})
axis([0 3500000 25 45])
grid on

% Pressure Altitude Graph
altitudeFeet1 = (1 - ((raw(:,2) ./ 100) ./ 1013.25).^0.190284) .* 145366.45;
altitudeFeet2 = (1 - ((raw(:,7) ./ 100) ./ 1013.25).^0.190284) .* 145366.45;
altitudeMeters1 = 0.3048 .* altitudeFeet1;
altitudeMeters2 = 0.3048 .* altitudeFeet2;

figure();plot(time,altitudeFeet1,'b')
hold on
plot(time,altitudeFeet2,'r')
hold off
title('Pressure Altitude vs Time')
xlabel('Time (ms)')
ylabel('Altitude (feet)')