function [r,zin] = tloss(gam,c1,d1,z1,zm)
% tloss(gam,c1,d1,z1,zm) is transmission line function w. loss
% returns a pressure or voltage ratio r and input impedance zin
% from inputs f (frequency Hz),c1 (line sound speed m/s),
% d1 (line length meters),z1 line impedance (MRayl or ohms)
% zm load impedance (MRayl or ohms)
% gam= gamma, a complex wavenumber as a function of frequency 
% T. L. Szabo July 2004 Diagnostic Ultrasound Imaging: Inside Out
ng=size(gam);      % determine size of array gam
if ng(2) ~=1
    zmarray=zm;
else
    zmarray=zm*ones(ng); % create zm array
end
% calculate ratio:pressure p2/p1 or voltage v2/v1
r=zmarray./(zmarray.*cosh(gam)+z1*sinh(gam));
% calculate zin
zin=z1*(zmarray.*cosh(gam)+z1*sinh(gam))./(zmarray.*sinh(gam)+z1*cosh(gam)); 

