Barometric Pressure to Altitude

How to use international barometric formula below to calculate the altitude correctly, if we can obtain the temperature and the barometric pressure?

h = 44330 * [ 1 - ( p / p0 ) ^ ( 1 / 5.255) ]

h = altitude (m)
p = measured pressure (Pa)
p0 = reference pressure at sea level.

(1) Is it correct to calibrate altitude using the temperature?
The actual altitude = the raw altitude result * the actual average temperature / the standard average temperature
Here, the average temperature is the mean between the sea level and the location where measured.

(2) How should we set p0 to suit the weather when measured?

For example:
(a) For calibration: in the beginning, we measured p = 989.5 hPa, t = 13.7 ℃, and input h_input = 100 m.
(b) For testing: we measured p = 877.2 hPa, t = 7.2 ℃.

first assume: p0 = 989.5 hPa, h = 44330 * [ 1 - ( 877.2 / 989.5 ) ^ ( 1 / 5.255) ] = 1004.65 m
then temperature calibration: in the standard atmospheric model, the temperatures at 0m and 1004.65m are about 15.0 ℃ and 8.5 ℃, so h1 = h * (273 + (13.7 + 7.2)/2) / (273 + (15 + 8.5)/2 ) = 1000.06m, which means the difference of the altitude is 1000.06 m.
last result: the final actual altitude is h2 = h1 + h_input = 1100.06 m

Is the process for altimeter right? Any opinions will be appreciated.

Wikipedia as an article on this.

(1) Is it correct to calibrate altitude using the temperature? Yes.
http://www.jma.go.jp/jma/jma-eng/jma-center/ric/material/1_Lecture_Notes/CP5-Pressure.pdf

(2) How should we set p0 to suit the weather when measured? You can get the pressure at ground level from your local airport.
In an airplane, the altimeter is set to field elevation prior to take off; the barometric pressure is then shown in a little window.
Once airborne, the pressure is then adjusted to the local conditions while flying, so when you land the altimeter will read the correct elevation for the new airfield.

“The altimeter shows the aircraft’s altitude above sea-level by measuring the difference between the pressure in a stack of aneroid capsules inside the altimeter and the atmospheric pressure obtained through the static system. It is adjustable for local barometric pressure which must be set correctly to obtain accurate altitude readings. As the aircraft ascends, the capsules expand and the static pressure drops, causing the altimeter to indicate a higher altitude. The opposite effect occurs when descending.”
“A 3-pointer Wikipedia:pressure altimeter. The small hand is in thousands of feet, the larger hand is in hundreds of feet and the long thin hand is in tens of thousands of feet. The dial on the right side displays the set ground atmospheric pressure, which can be adjusted with the knob on the bottom left. Thus, this altimeter is displaying an altitude of 10,180 feet with a ground pressure of 29.92 inHg. The stripes at the bottom are fully concealed at 15,000 feet and above and fully visible at 10,000 feet and below. At 10,180 feet, only 3% of them are hidden.”

The constant 44330 is calculated assuming that the atmospheric temperature is 15 C at sea level, and that the temperature decreases with altitude by 6.5 K/km.

At least in the U.S., airports report first the air pressure corrected to sea level, then the local pressure. If only one number is reported, it is almost certainly the pressure corrected to sea level (not the local pressure).

(1) Is it correct to calibrate altitude using the temperature?

It depends how you are getting the barometric pressure - when for example with BMP085 then it is temperature corrected already.

This is what I used with BMP085 (BMP085 gives you an abs_Pressure corrected on temperature):

// MyAltitude
float readAltitude(float abs_Pressure, float sealevel_Pressure) {
  float altitude;
  altitude = 44330.0 * (1.0 - pow(abs_Pressure /sealevel_Pressure, 0.19029495));
  return altitude;
}

// Sea level corrected pressure
float readp0(float myAltitude, float abs_Pressure) {
  float p0;
  p0 = abs_Pressure / pow((1.0 - ( myAltitude / 44330.0 )), 5.255);
  return p0;
}

"sealevel_Pressure" (pressure corrected to Sea level) above must be the value you get from the nearest airport or meteo station.

The temperature in the formula is for the base elevation, not your elevation. A little more detailed version looks like this:

elevation = (T0/L ) * (1 - (P/P0)^(LR/mg))

In addition to the base temperature and pressure (T0,P0) you also need to know the lapse rate. In the standard atmosphere this is defined to be -6.5°C/km, but in the real world it deviates from this value from place to place, season to season and hour to hour. It also isn't necessarily constant at any one place. It can even be a positive number over some vertical distance. And determining the lapse rate isn't as easy as obtaining the other two values. Even the value of R can change with variations in humidity. So at best all you can do is approximate what your absolute elevation is with this formula.

Barometric altimeters are frequently used to determine relative elevation changes over short periods of time. For that most devices employ an offset elevation (or pressure) that is set to calibrate the altimeter to the current elevation. Then you have a reasonably good number over a limited elevation range, at least for a little while.

E.G.

h =44330 * [ 1 - ( p / p0 ) ^ ( 1 / 5.255) ] + h0