-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinitializeSimulation.py
171 lines (134 loc) · 7.79 KB
/
initializeSimulation.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
###########################################################################
#
# StatOpt Simulator
# by Jeremy Cosson-Martin, Jhoan Salinas of
# Ali Sheikholeslami's group
# Ported to Python 3 by Savo Bajic
# Department of Electrical and Computer Engineering
# University of Toronto
# Copyright Material
# For personal use only
#
###########################################################################
# Initalizes the simulation by preparing the results object as well as
# adding the values used in simulation derived from user input to the
# settings object.
#
# Inputs:
# simSettings: structure containing simulation settings
#
# Outputs:
# simResults: structure containing simulation results
#
###########################################################################
from userSettingsObjects import simulationSettings
from numpy import linspace, arange, array
from dataclasses import dataclass
@dataclass
class simulationResults:
successful: bool = True
class channelInfluence:
transferFunction: array
frequencies: array
impulseResponse: array
def __init__(self, tf = array((1), dtype='complex128'), freq = array(1,), impResp = array(1,)):
self.transferFunction = tf
self.frequencies = freq
self.impulseResponse = impResp
class channelsThatInfluence:
thru: channelInfluence
def __init__(self):
self.thru = channelInfluence()
class influenceSourcesClass:
channel: channelsThatInfluence
def __init__(self):
self.channel = channelsThatInfluence()
class simulationStatus:
def __init__(self):
self.finished: bool = False
self.results: simulationResults = simulationResults()
self.influenceSources: influenceSourcesClass = influenceSourcesClass()
self.channelData = channelsThatInfluence() # will have a 'thru' channel but I think that's fine
def initializeSimulation(simSettings: simulationSettings) -> simulationResults:
# Initialize result structure
simResults = simulationStatus()
# General settings
addGeneralSettings(simSettings)
# Transmitter settings
addTransmitterSettings(simSettings)
# Adaption settings
addAdaptionSettings(simSettings)
return simResults
###########################################################################
# This function adds fixed general settings.
###########################################################################
def addGeneralSettings(simSettings: simulationSettings):
# Determine number of data levels
if simSettings.general.signalingMode == '1+D':
simSettings.general.levelNumb.value = 2*simSettings.general.modulation.value-1
elif simSettings.general.signalingMode == '1+0.5D':
simSettings.general.levelNumb.value = 3*simSettings.general.modulation.value-2
elif simSettings.general.signalingMode == 'clock':
simSettings.general.modulation.value = 2
simSettings.general.levelNumb.value = simSettings.general.modulation.value
else:
simSettings.general.levelNumb.value = simSettings.general.modulation.value
simSettings.general.samplerNumb.value = simSettings.general.levelNumb.value-1
# Set additional rates
simSettings.general.symbolPeriod.value = 1/simSettings.general.symbolRate.value
simSettings.general.sampleRate.value = simSettings.general.symbolRate.value*simSettings.general.samplesPerSymb.value
simSettings.general.samplePeriod.value = 1/simSettings.general.sampleRate.value
# Define axis
simSettings.general.yIncrement.value = 2*simSettings.receiver.signalAmplitude.value/(simSettings.general.yAxisLength.value-1)
simSettings.general.yAxisLength.value = 1 + 2 * int(simSettings.receiver.signalAmplitude.value / simSettings.general.yIncrement.value) # Determine length from increment and add one for zero
simSettings.general.yAxis.value = linspace(-simSettings.receiver.signalAmplitude.value, simSettings.receiver.signalAmplitude.value, simSettings.general.yAxisLength.value)
samplesPerSymbol = simSettings.general.samplesPerSymb.value
simSettings.general.xAxisCenter.value = linspace(-0.5*samplesPerSymbol, 0.5*samplesPerSymbol, samplesPerSymbol + 1)*simSettings.general.samplePeriod.value
simSettings.general.xAxisLong.value = arange(samplesPerSymbol * simSettings.general.numbSymb.value) * simSettings.general.samplePeriod.value
###########################################################################
# This function adds fixed transmitter settings.
###########################################################################
def addTransmitterSettings(simSettings: simulationSettings):
simSettings.transmitter.EQ.taps.main.value = 1; # will be adjusted later
simSettings.transmitter.cursorCount.value = simSettings.transmitter.preCursorCount.value+simSettings.transmitter.postCursorCount.value+1 # pre+post+main
###########################################################################
# This function adds fixed adaption settings.
###########################################################################
def addAdaptionSettings(simSettings: simulationSettings):
# Add dependent settings
simSettings.adaption.totalPopulation.value = simSettings.adaption.totalParents.value+simSettings.adaption.childrenPerParent.value*\
simSettings.adaption.totalParents.value+simSettings.adaption.totalMutations.value
simSettings.adaption.totalSimulations.value = simSettings.adaption.totalPopulation.value +\
(simSettings.adaption.totalPopulation.value-simSettings.adaption.totalParents.value)*\
(simSettings.adaption.mode1Generations.value+simSettings.adaption.mode2Generations.value-1)
simSettings.adaption.speedUpSim = False
# Configure for adaption
if(simSettings.adaption.adapt):
# Save original settings
simSettings.adaption.savedSettings.modulation = simSettings.general.modulation
simSettings.adaption.savedSettings.samplerNumb = simSettings.general.samplerNumb
simSettings.adaption.savedSettings.levelNumb = simSettings.general.levelNumb
simSettings.adaption.savedSettings.preCursorCount = simSettings.transmitter.preCursorCount
simSettings.adaption.savedSettings.postCursorCount = simSettings.transmitter.postCursorCount
simSettings.adaption.savedSettings.cursorCount = simSettings.transmitter.cursorCount
# Set adaption defaults
if simSettings.general.signalingMode == '1+D':
simSettings.general.modulation.value = 2
simSettings.general.levelNumb.value = 2*simSettings.general.modulation.value-1
elif simSettings.general.signalingMode == '1+0.5D':
simSettings.general.modulation.value = 2
simSettings.general.levelNumb.value = 3*simSettings.general.modulation.value-2
elif simSettings.general.signalingMode == 'clock':
simSettings.general.modulation.value = 2
simSettings.general.levelNumb.value = simSettings.general.modulation.value
else:
simSettings.general.modulation.value = 2
simSettings.general.levelNumb.value = simSettings.general.modulation.value
simSettings.general.samplerNumb.value = simSettings.general.levelNumb.value-1
simSettings.transmitter.preCursorCount.value = 2
simSettings.transmitter.postCursorCount.value = 4
simSettings.transmitter.cursorCount.value = simSettings.transmitter.preCursorCount.value+simSettings.transmitter.postCursorCount.value+1 # pre+main+post
# Add a knob for the main EQ tap if there isn't one already specified
if not 'transmitter.EQ.taps.main' in simSettings.adaption.knobs:
simSettings.adaption.knobs.append('transmitter.EQ.taps.main') # add tap to ensure it is updated correctly
simSettings.channel.approximate = True