二维FDTD仿真
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
%%%%%%%% Simulation in free space %%%%%%%%
%%%%%%%% FDTD in Two Dimensions 3_1 %%%%%%%%
%%%%%%%% Initialize Parameters %%%%%%%%
KE=200;
dz=zeros(KE+1,KE+1);
ez=zeros(KE+1,KE+1);
iz=zeros(KE+1,KE+1);
hx=zeros(KE+1,KE+1);
hy=zeros(KE+1,KE+1);
ga=zeros(KE+1,KE+1);
gb=zeros(KE+1,KE+1);
kc=KE/2;
T=0;
NSTEP=300;
%%%%%%%% sigal source %%%%%%%%
t0=40;
spread=12;
%%%%%%%% grid %%%%%%%%
ddx=0.1; %%%%%%%% set the cell size to 1cm %%%%%%%%
dt=ddx/(2*3e8); %%%%%%%% calculate the time step %%%%%%%%
%%%%%%%% material parameter %%%%%%%%
epsilon=4; %%%%%%%% relative dielectric constant %%%%%%%%
kstart=100; %%%%%%%% position of the dielectric medium %%%%%%%% epsz=8.85419e-12; %%%%%%%% absolute dielectric constant %%%%%%%% sigma=0.04; %%%%%%%% conductivity %%%%%%%%
%%%%%%%% initialize to free space %%%%%%%%
for i=1:KE+1
for j=1:KE+1
ga(i,j)=1;
end
end
for n=1:NSTEP
T=T+1;
%%%%%%%% calculate dx field %%%%%%%%
for i=2:KE+1
for j=2:KE+1
dz(i,j)=dz(i,j)+0.5*(hy(i,j)-hy(i-1,j)-hx(i,j)+hx(i,j-1));
end
end
%%%%%%%% insert source %%%%%%%%
pulse=exp(-0.5*(t0-T)^2/spread^2); %%%%%%%% sin(2*pi*freq_in*dt*T); %%%%%%%%
dz(kc,kc)=dz(kc,kc)+pulse; %%%%%%%%%%ex(50)=ex(50)+pulse 与ex(50)=pulse的区别??
%%%%%%%% calculate E from dx %%%%%%%%
for i=2:KE+1
for j=2:KE+1
ez(i,j)=ga(i,j)*(dz(i,j)-iz(i,j));
end
end
%%%%%%%% calculate iz %%%%%%%%
for i=2:KE+1
for j=2:KE+1
iz(i,j)=iz(i,j)+gb(i,j)*ez(i,j);
end
end
%%%%%%%% calculate hx and hy %%%%%%%%
for i=1:KE
for j=1:KE
hx(i,j)=hx(i,j)+0.5*(ez(i,j)-ez(i,j+1));
hy(i,j)=hy(i,j)+0.5*(ez(i+1,j)-ez(i,j));
end
end
%%%%%%%% diaplay in the picture %%%%%%%%
m=moviein(300);
x=1:KE+1;
y=1:KE+1;
contour(x,y,ez,100)
pcolor(x,y,ez),colorbar
set(gcf,'Color', 'white', 'Number', 'off', 'Name', sprintf('Simulation FDTD 2D, Iteration = %i', n));
title(sprintf('t = %.3f nsec',n*dt*1e9),'Color',[1 0 0],'FontSize', 14);
m(n)=getframe(gcf);
%pause(0.005)
end。