% Code to generate the graphs of correlation outlined in section 5.3.1 for
% the circular, linear and planar array topologies.
% Tim Brown, January 2012

% Note, files correl_fsp.m, ptheta.m and ang.dat are required to run this
% code.

% Generate spatial correlation variable horizontal separation d.
l = 0;
d_range = [0:0.01:2];
correl_horiz = zeros(1,length(d_range));
nn = 1;
for d = d_range
    correl_horiz(1,nn) = real(correl_fsp(d,l,20,20));
    nn = nn + 1;
end

% Generate spatial correlation for variable vertical separation l.
l_range = [0:0.01:2];
d = 0;
correl_vert = zeros(1,length(l_range));
nn = 1;
for l = l_range
    correl_vert(1,nn) = real(correl_fsp(d,l,20,20));
    nn = nn + 1;
end

figure
plot(d_range,correl_horiz,l_range,correl_vert)
set(gcf,'color','white')
set(gca,'FontSize',16)
xlabel('Linear Spacing in {\lambda}')
ylabel('{\rho_{mn}}')
legend('Horizontal Spacing','Vertical Spacing')

% Generate correlation for variable circle radius
r_range = [0:0.01:2];
n_elem_range = [2 3 4 6 10];
l = 0;
correl_circ = zeros(length(n_elem_range),length(r_range));
nnn = 1;
for nn = n_elem_range
  rr = 1;
  for r = r_range
      d = r * sqrt(2*(1-cos(2*pi/nn)));
      correl_circ(nnn,rr) = real(correl_fsp(d,l,20,20));
      rr = rr + 1;
  end
  nnn = nnn + 1;
end

figure
plot(r_range,correl_circ)
legend('2 Elements','3 Elements','4 Elements', ...
       '6 Elements','10 Elements')
set(gcf,'color','white')
set(gca,'FontSize',16)
xlabel('Radius in {\lambda}')
ylabel('{\rho_{mn}}')
