-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathexample_radar.py
More file actions
96 lines (72 loc) · 2.08 KB
/
example_radar.py
File metadata and controls
96 lines (72 loc) · 2.08 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#########################################################################################
##
## PathSim Example for Simple FMCW Radar System
##
#########################################################################################
# IMPORTS ===============================================================================
import matplotlib.pyplot as plt
import numpy as np
#the core functionalities can now be imported directly
from pathsim import Simulation, Connection
#the standard blocks are imported like this
from pathsim.blocks import (
Multiplier,
Scope,
Adder,
Spectrum,
Delay,
RealtimeScope,
ChirpPhaseNoiseSource,
ButterworthLowpassFilter
)
# FMCW RADAR SYSTEM =====================================================================
#natural constants
c0 = 3e8
#chirp parameters
B = 4e9
T = 5e-7
f_min = 1e9
#simulation timestep
dt = 1e-11
#delay for target emulation
tau = 2e-9
#target distances
R = c0 * tau / 2
#frequencies for targets
f_trg = 4 * R * B / (T * c0)
#initialize blocks
Src = ChirpPhaseNoiseSource(f0=f_min, BW=B, T=T)
Add = Adder()
Dly = Delay(tau)
Mul = Multiplier()
Lpf = ButterworthLowpassFilter(f_trg*3, 2)
Spc = Spectrum(
freq=np.logspace(6, 10.5, 500),
labels=["chirp", "delay", "mixer", "lpf"]
)
Sco = Scope(
labels=["chirp", "delay", "mixer", "lpf"]
)
blocks = [Src, Add, Dly, Mul, Lpf, Spc, Sco]
#initialize connections
connections = [
Connection(Src, Add[0]),
Connection(Add, Dly, Mul, Sco, Spc),
Connection(Dly, Mul[1], Sco[1], Spc[1]),
Connection(Mul, Lpf, Sco[2], Spc[2]),
Connection(Lpf, Sco[3], Spc[3])
]
#initialize simulation
Sim = Simulation(blocks, connections, dt=dt, log=True)
# Run Example ===========================================================================
if __name__ == "__main__":
#run simulation for one chirp period
Sim.run(T)
#plot the recording of the scope
Sco.plot()
#plot the spectrum
Spc.plot()
Spc.ax.set_xscale("log")
Spc.ax.set_yscale("log")
Spc.ax.axvline(f_trg, ls="--", c="k")
plt.show()