-
Notifications
You must be signed in to change notification settings - Fork 3
/
homog_gau.py
63 lines (49 loc) · 1.66 KB
/
homog_gau.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#------------------ Gaussian pulse propagation in a homogeneous medium
import numpy as np
import matplotlib.pyplot as plt
#----- Medium ----------
length = 2
eps0 = 8.854e-12
meu0 = 4*np.pi*1e-7
epsr = 1
meur = 1
eps = eps0*epsr
meu = meu0*meur
#---- Signal -----------
c = 3e8
v = c/np.sqrt(epsr*meur)
freq = 3e9
lamda = v/freq
#------ Cell length and time step---------
dz = lamda/10
dt = dz/v
N_cells = int(length/dz)
Mid_cell = int(N_cells/2)
#------ Multiplying constants --------
const_e = dt/(eps*dz)
const_h = dt/(meu*dz)
#------- Initialise E and H arrays ------------
ex = np.zeros(N_cells)
hy = np.zeros(N_cells)
#------ Gaussian pulse ------------
Ts = 10*dt # pulse width
t0 = 3*Ts # delay
N_steps = 200 # maximum iteration steps
#************** Iteration loop ****************
for n in range (N_steps):
time = n*dt
#------- Gaussian pulse launched in the middle cell ---------
pulse = (np.exp(-np.power(((time-t0)/Ts),2)))/dz
ex[Mid_cell-1] = pulse
#------------------------ compute H -------------------------
k = np.linspace(0, N_cells-2, N_cells-1, dtype = int)
hy[k] = hy[k]-const_h*(ex[k+1]-ex[k])
#------------------------ compute E -------------------------
k = np.linspace(1, N_cells-2, N_cells-2, dtype = int)
ex[k] = ex[k]-const_e*(hy[k]-hy[k-1])
#------------------------ plot ------------------------------
plt.plot(np.linspace(1, N_cells, N_cells, dtype = int),ex)
plt.xlim(0,200)
plt.ylim((-150,150))
plt.grid()
plt.show()