//mslope.sce
//www.basicairdata.eu JLJ 2013
//Sample data handling of pitot sensor data for
//m slope/sensitivity calculation 
//Data file "hcla12x10Hz 1250 Pa" must be present in the current directory
clear all;
xdel(winsid())
y=read("hcla12x10Hz 1250 Pa",150,1)
//Sensor offset
u_reference=6; //Reference instrument uncertainty Pa
u_sensor=18; //Sensor under test uncertainty Pa
o=14790; //14790.16
u_o=18/(14790)^0.5;
pressure_reference=1250;
meany=mean(y);
sdevy=stdev(y);
[samplesize zz]=size(y)
samplet=linspace(1,samplesize,samplesize)
hand1=figure(1,"BackgroundColor",[1,1,1]);
plot(samplet,y);
title("Sensor Output plotting","fontsize",4)
xlabel("Sample number","fontsize",4)
ylabel("Decimal count, sensor output","fontsize",4)
printf("Measurements average %.2f\n",meany)
mideal=1250/(27852-14745)
mcorrected=pressure_reference/(meany-o)
printf("m value from data %.5f\n",mcorrected)
printf("m ideal %.5f\n",mideal)
//Uncertainty esteem
reference_size=samplesize/10;
sensor_size=samplesize;
//Average deviation calculation
u_meanreference=ceil(u_reference/(reference_size)^0.5); //Pa
u_meansensor=ceil(u_sensor/(sensor_size)^0.5);//Pa

u_m=((1/(meany-o))^2*u_meanreference^2+2*pressure_reference^2*(meany-o)^(-4)*u_meansensor^2)^0.5
printf("u_m uncertainty of m %.5f, or %.2f%% \n",u_m,u_m/mcorrected*100 )
u_y=((meany-14790)^2*u_m^2+mcorrected^2*u_sensor^2+u_o^2)^0.5
printf("u_y uncertainty of y %.0f Pa\n",ceil(u_y))
