function [ZL]=FreeSpaceZ(c,rho,a,f)

% Impedance of an unflanged pipe terminating into free space neglecting 
% effects of mean flow. (Lewine & Schwinger)

% Input data:
% c - speed of sound in media (m/s)
% rho - density of media (kg/m^3)
% a - radius of pipe's cross-section (m)
% f - frequency vector (Hz)

% Output:
% ZL - termination impedance (Ns/m^3)


S=pi*a^2;									    % Area of cross-section
coeff=[-0.06432,0.33576,-0.59079,0.01336,1];	% Coefficients in Ro-polynomial 

Z=rho*c/S;
ZL=zeros(size(f));

kaf=(2*pi*f/c)*a;

for n=1:length(f)

    ka=kaf(n);
    
    if ka<0.5
        xi=0.6133-0.1168*(ka^2);
        Ro=polyval(coeff,ka);  
    end
         
    if ka>=0.5 & ka<=2.6039
        xi=0.6393-0.1104*ka;
        Ro=polyval(coeff,ka);
    end
         
    if ka>2.6039
        Ro=0;
        xi=0;
    end   
         
    R=-Ro*exp(-i*2*ka*xi);	% Reflection coefficient
    ZL(n)=Z*((1+R)/(1-R));	% Impedance
    
end

