%% Source: Microwave Radar and Radiometric Remote Sensing, http://mrs.eecs.umich.edu
%% These MATLAB-based computer codes are made available to the remote
%% sensing community with no restrictions. Users may download them and
%% use them as they see fit. The codes are intended as educational tools
%% with limited ranges of applicability, so no guarantees are attached to
%% any of the codes. 
%%
%Code 8.6: Rain Attenuation Coefficient

%Description: Code computes the extinction coefficient (scattering plus
    %absorption) due to rain at any frequency 0<f<1000GHz,
    %rain rate 0<Rr<150mm/hr, and t>0C.

%Input Variables
    %Rr: rain rate in mm/hr
    %f: frequency in GHz
    
%Output Products
    %kapparain: rain attenuation coefficient in dB/km
    
%Book Reference: Sections 8-8.2

%MATLAB Code:

function [kapparain]=RainExtincCoef(Rr,f)
last=numel(f);

for t=1:last
    if (f(t)<2.9)
        k(t)=6.39e-5 * f(t).^2.03;
    elseif ((f(t)>=2.9)&&(f(t)<54))
        k(t)=4.21e-5 * f(t).^2.42;
    elseif ((f(t)>=54)&&(f(t)<180))
        k(t)=4.09e-2 * f(t).^0.699;
    elseif (f(t)>=180)
        k(t)=3.38 * f(t)^-0.151; 
    end
    
    if(f(t)<8.5)
        b(t)=0.851*f(t)^0.158;
    elseif((f(t)>=8.5)&&(f(t)<25))
        b(t)=1.41*f(t)^-0.0779;
    elseif((f(t)>=25)&&(f(t)<164))
        b(t)=2.63*f(t)^-0.272;
    elseif(f(t)>=164)
        b(t)=0.616*f(t)^0.0126;
    end
end
    kapparain=k.*Rr.^b;
end