
clear all

%%%%%%%%%%% parameter %%%%%%%%%%%%%%%%
alpha1=0.05;
alpha2=0.05;
maxlaml=1.1/0.50;
minlaml=0.9/0.50;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

l=0.1;
c=3e8;
imagg=sqrt(-1);
Z0=120*pi;

l1=alpha1*l;
l2=alpha2*l;
l3=l-l1-l2;

minlam=minlaml*l;
maxlam=maxlaml*l;
minf=c/maxlam;
maxf=c/minlam;

zLmin=-1*l;
zLmax=0;
zCmin=0;
zCA=l1;
zCB=l1+l3;
zCmax=l;
zRmin=l;
zRmax=zRmin+1*l;

delz=1/5000;
zL=[zLmin:delz:zLmax];
zCL=[zCmin:delz:zCA];
zCC=[zCA+delz:delz:zCB];
zCR=[zCB+delz:delz:zCmax];
zR=[zRmin:delz:zRmax];

framemax=96;
M = moviein(framemax);
set(gcf,'Position',[100 100 640 480])

for n=1:framemax

f= minf+1*(maxf-minf)/(framemax-1)*(n-1);

omega = 2*pi*f;
k=omega/c;

ZBl2=imagg*Z0*tan(k*l2);
ZB0=Z0;
ZB=ZBl2*ZB0/(ZBl2+ZB0);
ZAB=Z0*(ZB/Z0+imagg*tan(k*l3))/(1+imagg*(ZB/Z0)*tan(k*l3));
ZAl1=imagg*Z0*tan(k*l1);
ZA=(ZAl1*ZAB)/(ZAl1+ZAB);

GaAL=(ZA-Z0)/(ZA+Z0);
VL=1*(exp(-imagg*k.*zL)+ GaAL*exp(imagg*k.*zL));

V0CL=VL(length(VL))/(exp(imagg*k*l1)-exp(-imagg*k*l1));
zlocalCL=-zCL;
VCL=V0CL*(exp(-imagg*k.*zlocalCL)-exp(imagg*k.*zlocalCL));

GaB=(ZB-Z0)/(ZB+Z0);
V0CC=VL(length(VL))/(exp(imagg*k*l3)+GaB*exp(-imagg*k*l3));
zlocalCC=(zCC-zCB);
VCC=V0CC*(exp(-imagg*k.*zlocalCC)+GaB*exp(imagg*k.*zlocalCC));

V0CR=VCC(length(VCC))/(exp(imagg*k*l2)-exp(-imagg*k*l2));
zlocalCR=(zCR-zCmax);
VCR=V0CR*(exp(-imagg*k.*zlocalCR)-exp(imagg*k.*zlocalCR));

V0R=VCC(length(VCC));
zlocalR=(zR-zRmax);
VR=V0R*exp(-imagg*k*zlocalR);

ztot=[zLmin:delz:zRmax];

ztot1=[zCL,zCC,zCR];
Vtot1=[VCL,VCC,VCR];


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


figure(1)
hold off

subplot(2,1,1)
plot(ztot1,abs(Vtot1),'b','linewidth',2)
title('VSWP (resonator)','fontsize',18)
grid on
axis([ztot(1) ztot(length(ztot)) 0 20])


subplot(2,1,2)
plot(zL+l1,abs(VL),'linewidth',2)
hold on
plot(zR-l2,abs(VR),'linewidth',2)
title('VSWP (incident and transmitted)','fontsize',18)
grid on
axis([ztot(1) ztot(length(ztot)) 0 3])


%subplot(2,1,2)
%plot(z,real(Etot),'linewidth',2)
%title('Real(V)','fontsize',18)
%axis([zmin zmax -2 2])
%grid on


xlabel(['5% tap point(low Q), L/\lambda=' ,num2str(l/(c/f))],'Color','k','fontsize', 18)


M(:,n) = getframe(gcf);

end

clf reset
set(gcf,'Position',[100 100 800 600])
axis off
movie(M,1,2)
