%Electric field distribution around a current sheet
%sinusoidal excitation
clear
ke=50;
ks = ke/2;
nsteps=180;
c0=3e8;
dx=0.01;
xvec = -ke*dx/2+dx:dx:ke*dx/2;
dt=dx/(8*c0);
cc = c0*dt/dx;
xmax = dx*ke/2;
xmin = -xmax;
lambda = xmax/2;
f0 = c0/lambda;

ex = zeros(1,ke);
hy=ex;

t0=20;
spread=8;
figure(1)
%start loop
%M=moviein(nsteps)
for tn=1:nsteps
    %Ex
    for k=2:ke-1
        ex(k) = ex(k)+cc*(hy(k-1)-hy(k));
    end
    
    %source
    %ex(ks)=exp(-0.5*((tn-t0)/spread)^2);
    ex(ks)=sin(2*pi*tn*dt*f0);
    
    %Hy
    for k=1:ke-1
        hy(k) = hy(k)+cc*(ex(k)-ex(k+1));
    end
    plot(xvec,ex);
    axis([xmin xmax -2 2])
    xlabel('distance (m)')
    ylabel('Ex (V/m)')
    pause(0.5)
    %M(:,tn) = getframe;
end
%movie(M,1);

    