% Calculating Sea Level Pressure using Barometer height
% NOAA Tech training

close all
clear


Pz = 1010; % Barometer pressure
Ra = 287.05;  % Constant J/kgK
T = 250;  % Temperature K
g = 9.81;  % gravity m/s
Z = 10.;  % height of presure sensor in m
%Ps = surface pressure

%exp((9.81*10)/(287.05*280))*1010
ct = 0;
for i = 0:5:50  % loop trhough different temperatures
    ct = ct + 1;
    t(ct) = T + i;
Ps(ct) = exp((9.81*Z)/(Ra*t(ct)))*Pz;
end
Ps;
figure
plot(t-274.15,Ps,'r*')
xlabel('Air Temp (C)');
ylabel('Pressure(mb)');
title('Air Temperature Effect');
xlim([-25 25])
ylim([ 1011.15 1011.4 ])
grid

ct = 0;
T = 290;
for i = 0:2:50  % loop through different hts
    ct = ct + 1;
    z(ct) = i;
Ps(ct) = exp((9.81*z(ct))/(Ra*T))*Pz;
dp(ct) = Ps(ct)- Pz;
end
Ps;
figure
plot(z,dp,'r*')
xlabel('Sensor Ht (m)');
ylabel(' Ps - 1010(mb)');
title('Surface Pressure Calculation');
grid