% PHD_PvD   Investigate P & Q fields using Wait's formulations

% for the following figures, use data generated from...
load 'PHD_PvD_data';

filetype = '-dtiff';

points = 301; limit = 30;
X = 0 : limit/(points-1) : limit;

while 0,    
% --------------------------- plot argand diagrams -----------------

fig=1; figure(fig);  

D=1; T=1; Z=0; mode=1;

parms = ['(0 : ', num2str(limit/(points-1)) ':', num2str(limit), ...
    ',', num2str(D), ',', num2str(T), ',',num2str(Z), ',',num2str(mode), ')' ];

cla; plot (sommerfeld(X,D,T,Z,mode),'k.-','linewidth',2,'markersize',12);

set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('Real part of integrand','fontsize',12)
ylabel('Imaginary part of integrand','fontsize',12)
title(['Sommerfeld', parms],'fontsize',12)
print(filetype, '', ['PvD-' num2str(fig)] )

fig=2; figure(fig);  
cla; plot (X,abs(sommerfeld(X,D,T,Z,mode)),'k-','linewidth',2,'markersize',12);

set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('variable of integration','fontsize',12)
ylabel('abs(integrand)','fontsize',12)
title(['Sommerfeld', parms],'fontsize',12)
print(filetype, '', ['PvD-' num2str(fig)] )


% --------------------------- plot argand diagrams -----------------

fig=3; figure(fig);  

D=2; T=6; Z=0; mode=1;
parms = ['(0 : ', num2str(limit/(points-1)) ':', num2str(limit), ...
    ',', num2str(D), ',', num2str(T), ',',num2str(Z), ',',num2str(mode), ')' ];

cla; plot (sommerfeld(X,D,T,Z,mode),'k.-','linewidth',2,'markersize',12);

set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('Real part of integrand','fontsize',12)
ylabel('Imaginary part of integrand','fontsize',12)
title(['Sommerfeld', parms],'fontsize',12)
print(filetype, '', ['PvD-' num2str(fig)] )

fig=4; figure(fig);  
cla; plot (X,abs(sommerfeld(X,D,T,Z,mode)),'k-','linewidth',2,'markersize',12);

set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('variable of integration','fontsize',12)
ylabel('abs(integrand)','fontsize',12)
title(['Sommerfeld', parms],'fontsize',12)
print(filetype, '', ['PvD-' num2str(fig)] )

end; % matches while

% --------------------------- plot abs(Q) v D for different T -----------------

Z=0; mode=1;
points = 201; limit = 5;
X=linspace(0,limit,points);

% ------------------------ T = 0 to 8 ------------------------
% ------------------------ abs(Q) ----------------------------

fig=5; figure(fig);  
cla; H1 = semilogy(X,abs(Qdata1),'k-','linewidth',3);

hold on;
H2 = semilogy(X,abs(Qdata2),'k-','linewidth',1.5);

axis([0 5 1E-6 1]);
parms = ['D=[x], T=0:8, Z=',num2str(Z), ', mode=',num2str(mode) ];

set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('D: Normalised Offset','fontsize',12)
ylabel('|P| Normalised Horizontal Field','fontsize',12)
title(['PQintegral: ', parms],'fontsize',12)
legend([H1(1) H2(1)], 'Uplink P field', 'Downlink P field')

print(filetype, '', ['PvD-' num2str(fig)] )

% ------------------------ phase(Q) --------------------------

% fiddle the data to avoid plot problem caused by phase at D=0 being
% recorded at 0

Qdata1(1,:) = Qdata1(2,:);
Qdata2(1,:) = Qdata2(2,:);

fig = fig+1; figure(fig); jcount = 9; start = 0;
cla; H1 = plotphase1(X,points, jcount, start, Qdata1,3);
hold on
H2 = plotphase1(X,points, jcount, start, Qdata2,1.5);

axis([0 5 -720 0]);
set(gca, 'YTick', linspace(-1080,0,7));

parms = ['D=[x], T=0:8, Z=',num2str(Z), ', mode=',num2str(mode) ];
set(gca,'LineWidth',1.5,'FontSize',12,'TickDir','out')
xlabel('D: Normalised Offset','fontsize',12)
ylabel('angle(P) Normalised Horizontal Field','fontsize',12)
title(['PQintegral: ', parms],'fontsize',12)
legend([H1(1) H2(1)], 'Uplink P field', 'Downlink P field',3)

print(filetype, '', ['PvD-' num2str(fig)] )
