clear;
close all;

%% From the AD92 Datasheet
% For voltages above 3V, the AD592 is a high-impedance current source. The
% following points are directly from the datasheet for the AD592.

tC = [-25 0 70 105 ];
iO = [248 273 343 378];

% Solve for this relationship and evaluate for a full curve over the
% operational ranges of the device. 

P = polyfit(tC,iO,1)

tCx = [-25:1:125];
iOy = polyval(P,tCx);

kx  = tCx + 273.15;
avg = mean(iOy/kx)
plot(tC,iO,'.',tCx,iOy);
xlabel('TEMPERATURE ^{\circ}C');
ylabel('I_{OUT} - uA');
grid on;

%% Doriss II Installation
% The LRS has two of these sensors installed, and each with a 1.1 k\Omega
% resistor. The following serves to get a best guess estimate of the
% temperature to start with, which may be enough for initial testing
% purposes. 

R = 1.1e3;
vout = iOy*1e-6*R;

figure;
plot(vout,tCx);
grid on;
xlabel('Voltage Output (V)');
ylabel('Temperature (^{\circ}C)');
title('Uncalibrated Temperature Relationship with 1.1K\Omega Load Resistor');
P2 = polyfit(vout,tCx,1)
gtext(['T = ' num2str(P2(1))  '(V) + ' num2str(P2(2))]);