function DT=deltaT(data)
%This function computes the change in temperature in a bomb calorimetry
%experiment. The program asks for input "times" for pre-burn and post-burn
%regions. The program then fits straight lines to these regions and
%extrapolates to the region of rapid temperature change.
%The program then finds the time when area1 and area2 are equal.
%Area1 is the area between the temperature data and the pre-burn line
%computed up to a given time ts. Area2 is the area between the post-burn
%line and the temperature data computed from a given time ts.
%INPUT VARIABLE
% data = temperature measurements at equal intervals of time
% here we assume data is an 1 by n vector
%OUTPUT VARIABLE
% DT = delta T the measured rise in temperature at time ts
% when area1 equals area2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%plot thermogram
plot(data)
%input pre-burn and post-burn times
tpre = input('Input the end of the pre-burn time = ');
tpost = input('Input the beginning of the post-burn time = ');
n=size(data); %data size
t=1:1:n(2); %arbitrary times to be used as x-values in linear fit
%pre-burn line
p1=polyfit(t(1:tpre),data(1:tpre),1); %p1 has slope and intercept
preline=polyval(p1,t); %this evaluates the line over all times t
hold on
plot(preline,'r') %this plots the pre-burn line with thermogram
%post-burn line
p2=polyfit(t(tpost:n(2)),data(tpost:n(2)),1); %p2 has slope and intercept
postline=polyval(p2,t); %this evaluates the line over all times
plot(postline,'r') %this plots the post-burn line with thermogram
area1=0; %Here we simply initialize area1 and area2
area2=2; %to get things started.
ts=tpre; %x=ts is the vertical line where the areas are defined.
while area1 < area2
ts=ts+1;
area1=sum((data(tpre:ts)-preline(tpre:ts)));
area2=sum((postline(ts:tpost)-data(ts:tpost)));
end
line([ts ts],[preline(ts) postline(ts)],'color','r') %final vertical line
%ts is a good approximation of the time when the two areas are equal
DT=postline(ts)-preline(ts);