function y = antenna_array(ps)

persistent c fc pstemp hp psa

if isempty(fc)
    fc = 1e9;
end

if isempty(pstemp)
    pstemp = [1;1;1;1];
    psa = [0 0 0 0]';
end

if isempty(hp) 
    hp          = polarpattern;
    hp.TitleTop = 'Azimuth Pattern';
end

% If figure was closed in session
if ~ishandle(hp.Parent)
    hp          = polarpattern;
    hp.TitleTop = 'Azimuth Pattern';
end

if isempty(c)
    vp = physconst('lightspeed');
    lambda = vp/fc;
    d = dipole;
    d.Length = lambda/2;
    d.Width = lambda/100;
    %% Transmitter Locations
    load Txloc
    %% Receiver Locations
    R = 20*lambda;
    az = [15 45 315 345];
    x = R*cosd(az);
    y = R*sind(az);
    rxloc = [x' y' zeros(numel(az),1)];
    %% The model
    c = conformalArray;
    c.Element = d;
    c.ElementPosition = [arrayloc; rxloc];
    c.AmplitudeTaper = [1 1 1 1 0 0 0 0];
    c.PhaseShift     = [0 0 0 0 0 0 0 0];
end

if ~isequal(pstemp,ps)
    pst = ps(1:4)';
    psa = atan2(imag(pst(1:4)),real(pst(1:4))).*180/pi;
    c.PhaseShift(1:4) = psa;
    Datx = pattern(c,fc,0:1:359,0);
    replace(hp,0:1:359,Datx');
    pstemp = ps;
end

y = psa;