%program for 1D FDTD Simulation
%ROLL NO:
clear all;
close all;
clc;
ke=50;
%position of the source
ks=ke/2;
%number of time step
nsteps=100;
%cell size and time stepping
c0=3.e8;
dx=0.01;
dt=dx/(2.*c0);
%constant
cc=c0*dt/dx;
%initialise vectors
ex=zeros(1,ke);
hy=zeros(1,ke);
%gaussian pulse
t0=20;
spread=8;
%srart loop
m=moviein(nsteps);
for t=1:nsteps
%E feild loop
for k=2:ke-1
ex(k)=ex(k)+cc*(hy(k-1)-hy(k));
end
%source
ex(ks)=exp(-.5*((t-t0)/spread)^2);
%H field loop
for k=1:ke-1
hy(k)=hy(k)+cc*(ex(k)-ex(k+1));
end
end
plot(ex);
axis([1 ke -2 2]);
m(:,t)=getframe;