%Visualize waves on a TL
%Forward wave: Re(exp(j(wt-kx))), Backward: Re(exp(j(wt+kx)))
TP = 1; %time period
w = 2*pi*1/TP; %angular freq
lambda = 0.5; %wavelength
k = 2*pi/lambda; %propagation constant (same as beta)
%create grid in time
t = 0:0.1:3*TP;
%create grid in space
x = 0:0.05:4*lambda;
%create space-time grid
[X,T] = meshgrid(x,t);
%forward wave
fwd = exp(1j*(w*T - k*X));
mesh(X,T,real(fwd));
xlabel('x'); ylabel('t');
%backward wave
bkw = exp(1j*(w*T + k*X));
figure;
mesh(X,T,real(bkw));
xlabel('x'); ylabel('t'); title('Backward Wave');
%Reflection coeff
Gamma = 1;
intf1 = fwd + Gamma * bkw;
figure;
mesh(X,T,real(intf1));
xlabel('x'); ylabel('t'); title('Interference 1');
%Imperfect reflection
Gamma = 0.5*1j;
intf2 = fwd + Gamma * bkw;
%can be seen as: (1-Gamma + Gamma) * fwd + Gamma * bkw 
figure;
mesh(X,T,real(intf2));
xlabel('x'); ylabel('t'); title('Interference 2');
