% *************************************************************************
%                          Ïà¹ØË¥ÂäµÄ·ÖÎöºÍ·ÂÕæ
% *************************************************************************
clear all; clc
% ***************     #1 Global Parameters   ******************************

AOA = 90*pi/180;       % Angle of Arrival
AS = 0*pi/180;        % Angular Spread
delta = 180*pi/180;     % Angle range
PAS_type = 3;   % 1,Uniform  distribution
                          % 2,Gaussian distribution
                           % 3,Laplace  distribution
L = 20;         % subray number for simulation
diss = 0.5;     % Antenna Spacing between two elements(wave length)
offset0 = [0.0894,-0.0894,0.2826,-0.2826,0.4984,-0.4984,0.7431,-0.7431,1.0257,-1.0257,1.3594,-1.3594,1.7688,-1.7688,2.2961,-2.2961,3.0389,-3.0389,4.3101,-4.3101]'/2;
m = 0;
for AS = 0.5:0.5:30
    m=m+1;
    AS = AS*pi/180;
    offset = AS*offset0;
    corr_t(m,1) = abs(quadl('PAS_laplace',15*pi/180-+delta,15*pi/180+delta,0.000001,0,3.5,AS,15*pi/180,delta));
    corr_t(m,2) = abs(quadl('PAS_laplace',30*pi/180-+delta,30*pi/180+delta,0.000001,0,3.5,AS,30*pi/180,delta));
    corr_t(m,3) = abs(quadl('PAS_laplace',45*pi/180-+delta,45*pi/180+delta,0.000001,0,3.5,AS,45*pi/180,delta));
    
    corr_t(m,4) = abs(quadl('PAS_laplace',15*pi/180-+delta,15*pi/180+delta,0.000001,0,2.5,AS,15*pi/180,delta));
    corr_t(m,5) = abs(quadl('PAS_laplace',30*pi/180-+delta,30*pi/180+delta,0.000001,0,2.5,AS,30*pi/180,delta));
    corr_t(m,6) = abs(quadl('PAS_laplace',45*pi/180-+delta,45*pi/180+delta,0.000001,0,2.5,AS,45*pi/180,delta));
    
    corr_s(m,1) = abs(sum(exp(-j*2*pi*3.5*sin(15*pi/180+offset))))/L;
    corr_s(m,2) = abs(sum(exp(-j*2*pi*3.5*sin(30*pi/180+offset))))/L;
    corr_s(m,3) = abs(sum(exp(-j*2*pi*3.5*sin(45*pi/180+offset))))/L;
    
    corr_s(m,4) = abs(sum(exp(-j*2*pi*2.5*sin(15*pi/180+offset))))/L;
    corr_s(m,5) = abs(sum(exp(-j*2*pi*2.5*sin(30*pi/180+offset))))/L;
    corr_s(m,6) = abs(sum(exp(-j*2*pi*2.5*sin(45*pi/180+offset))))/L;
end

as = 0.5:0.5:30;
figure
hold
plot(as,corr_t(:,1),'r')
plot(as,corr_t(:,2),'b')
plot(as,corr_t(:,3),'c')
plot(as,corr_t(:,4),'r:')
plot(as,corr_t(:,5),'b:')
plot(as,corr_t(:,6),'c:')
grid    
xlabel('Angular spread(¡ã)')
ylabel('ccorrelation')
legend('diss = 3.5¦Ë, DOA = 15¡ã','diss = 3.5¦Ë, DOA = 30¡ã','diss = 3.5¦Ë, DOA = 45¡ã','diss = 2.5¦Ë, DOA = 15¡ã','diss = 2.5¦Ë, DOA = 30¡ã','diss = 2.5¦Ë, DOA = 45¡ã')
title('theory result')

figure
hold
plot(as,corr_s(:,1),'r')
plot(as,corr_s(:,2),'b')
plot(as,corr_s(:,3),'c')
plot(as,corr_s(:,4),'r:')
plot(as,corr_s(:,5),'b:')
plot(as,corr_s(:,6),'c:')
grid    
xlabel('Angular spread(¡ã)')
ylabel('ccorrelation')
legend('diss = 3.5¦Ë, DOA = 15¡ã','diss = 3.5¦Ë, DOA = 30¡ã','diss = 3.5¦Ë, DOA = 45¡ã','diss = 2.5¦Ë, DOA = 15¡ã','diss = 2.5¦Ë, DOA = 30¡ã','diss = 2.5¦Ë, DOA = 45¡ã')
title('simulation result')

