Posted By:
8 Oct, 2013 1:16 pm PDT

Relative Humidity to Humidty ratio conversion in Matlab

How to write a function in Matlab, which will take inputs (temperature and relative humidity) and produce Humidity Ratio as an ouput?

Inputs: Temperature (in Kelvin), Relative Humidity (in %)

Output: Humidity Ratio (in kg/kg)

Attachment:None


Here is the function which does the conversion assuming atmospheric pressure. Save the following code in a file: Rel_Humidity2Humidity_Ratio.m

>>Rel_Humidity2Humidity_Ratio(90,300) % this code converts  90% relative humidity ratio at 300K to humidity ratio.

function Humidity_Ratio = Rel_Humidity2Humidity_Ratio(RH,TEMPERATURE)
c2k = 273.16;

C1 = -5.674536e+3;
C2 = 6.3925247;
C3 = -9.677843e-3;
C4 = 6.221570e-7;
C5 = 2.074782e-9;
C6 = -9.484024e-13;
C7 = 4.163502;

C8=-5.8002206e3;
C9=1.3914993e0;
C10=-4.8640239e-2;
C11=4.1764768e-5;
C12=-1.4452093e-8;
C13=6.5459673e0;
p_atm = 101325; % atmospheric pressure Pa

if(TEMPERATURE<c2k)
    p_ws=exp(C1./TEMPERATURE+C2+C3.*TEMPERATURE+C4.*TEMPERATURE.^2+C5.*TEMPERATURE.^3 + C6.*TEMPERATURE.^4+C7.*log(TEMPERATURE));

end
if(TEMPERATURE>=c2k)
    p_ws=exp(C8./TEMPERATURE+C9+C10.*TEMPERATURE+C11.*TEMPERATURE.^2+C12.*TEMPERATURE.^3+C13.*log(TEMPERATURE));
end
p_v = RH*p_ws/100;

Humidity_Ratio=0.62198.*p_v./(p_atm-p_v);

Was it useful?  




Please login to reply to this problem.