%SParam.m
%[ s11, s21 ] = SParam( e, u, f, d )
% Written by Jacob Lewis April 2020.
% This code is to derive the Scattering Parameters from the Constitutive
% Parametres. Put in permitivity(e), permeability(u), frequency(f) and DEM
% thickness(d) and get reflection(s11) and transmission(s21). Use relative
% values for e and u. S-parameters will be complex values in non-dB form.
%
% Inputs:
%   e   Permittivity
%   u   Permeability
%   f   Frequency
%   d   Thickness
% Return:
%   s11 Reflection
%   s21 Transmission

function [ s11, s21 ] = SParam( e, u, f, d )
    if nargin < 4
        d = 0.001;
        if nargin < 3
            error('Not enough arguments');
        end
    end

    w = 2*pi*f;
    c = 299792458;

    g12 = (1-sqrt(u)./sqrt(e))./(1+sqrt(u)./sqrt(e));
    phi = exp(-1j*w*d.*sqrt(e).*sqrt(u)/c);

    s11 = -(g12.*(1-phi.^2))./(1-(g12.*phi).^2);
    s21 = (phi.*(1-g12.^2))./(1-(g12.*phi).^2);

end