sw: add normalization
This commit is contained in:
@ -31,7 +31,7 @@ class ReflectometerConfig:
|
||||
pulse_height: int
|
||||
pulse_num: int
|
||||
|
||||
dac_adc_ratio: float = 0.52
|
||||
adc_dac_ratio: float = 0.52
|
||||
socket_timeout_sec: float = 2.0
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ class ReflectometerWorker(QObject):
|
||||
output += 0b10001000.to_bytes(1, "little")
|
||||
|
||||
pulse_period_adc = (
|
||||
int(self.config.pulse_period * self.config.dac_adc_ratio)
|
||||
int(self.config.pulse_period * self.config.adc_dac_ratio)
|
||||
// self.config.window_size
|
||||
) * self.config.window_size
|
||||
|
||||
@ -126,7 +126,7 @@ class ReflectometerWorker(QObject):
|
||||
def _recv_data(self) -> list[int]:
|
||||
packet_count = math.ceil(
|
||||
(
|
||||
self.config.dac_adc_ratio
|
||||
self.config.adc_dac_ratio
|
||||
* self.config.pulse_period
|
||||
/ self.config.window_size
|
||||
* self.config.data_width
|
||||
@ -135,7 +135,7 @@ class ReflectometerWorker(QObject):
|
||||
)
|
||||
|
||||
expected_length = math.ceil(
|
||||
self.config.dac_adc_ratio
|
||||
self.config.adc_dac_ratio
|
||||
* self.config.pulse_period
|
||||
/ self.config.window_size
|
||||
)
|
||||
@ -227,7 +227,7 @@ class MainWindow(QMainWindow):
|
||||
self.nmax = 4096
|
||||
self.packet_size = 1024
|
||||
self.window_size = 65
|
||||
self.dac_adc_ration = 0.52
|
||||
self.adc_dac_ration = 0.52
|
||||
self.accum_width = 32
|
||||
|
||||
# setup
|
||||
@ -239,7 +239,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.data = []
|
||||
|
||||
self.dac_adc_ratio = 0.52
|
||||
self.adc_dac_ratio = 0.52
|
||||
|
||||
self.measurement_thread = None
|
||||
self.measurement_worker = None
|
||||
@ -455,8 +455,8 @@ class MainWindow(QMainWindow):
|
||||
)
|
||||
|
||||
self._bind_spinbox_setting(
|
||||
name="dac_adc_ratio",
|
||||
box=self.box_dac_adc_ratio,
|
||||
name="adc_dac_ratio",
|
||||
box=self.box_adc_dac_ratio,
|
||||
)
|
||||
|
||||
self._bind_spinbox_setting(
|
||||
@ -578,6 +578,7 @@ class MainWindow(QMainWindow):
|
||||
self.reference_curve = self.graph_widget.plot(
|
||||
[],
|
||||
name="Reference",
|
||||
color="b"
|
||||
)
|
||||
|
||||
self.graph_layout.addWidget(self.graph_widget)
|
||||
@ -654,7 +655,7 @@ class MainWindow(QMainWindow):
|
||||
pulse_height=self.pulse_height,
|
||||
pulse_num=self.pulse_num,
|
||||
|
||||
dac_adc_ratio=self.dac_adc_ratio,
|
||||
adc_dac_ratio=self.adc_dac_ratio,
|
||||
)
|
||||
|
||||
def on_data_received(self, data: list[int]):
|
||||
@ -670,6 +671,11 @@ class MainWindow(QMainWindow):
|
||||
else:
|
||||
self.set_measurement_status("Готово, но данные пустые")
|
||||
|
||||
# normalize
|
||||
for i in range(len(data)):
|
||||
self.data[i] -= 2 ** (self.adc_dw - 1)
|
||||
self.data[i] /= (self.window_size * self.pulse_num)
|
||||
|
||||
def on_measurement_error(self, message: str):
|
||||
self.set_measurement_status(f"Ошибка: {message}")
|
||||
|
||||
@ -721,19 +727,10 @@ class MainWindow(QMainWindow):
|
||||
self.reference_curve.setData(x, reference_data)
|
||||
|
||||
def build_reference_data(self, length: int) -> list[int]:
|
||||
"""
|
||||
Тут потом опишешь свою логику построения эталонного сигнала.
|
||||
|
||||
Главное: вернуть массив такой же или нужной тебе длины.
|
||||
Например:
|
||||
reference = [0] * length
|
||||
reference[10:100] = ...
|
||||
return reference
|
||||
"""
|
||||
|
||||
# TODO: сюда вставить свою логику эталонного графика
|
||||
|
||||
reference = [0] * length
|
||||
reference[0:(self.pulse_width // self.window_size + 1)
|
||||
] = [self.pulse_height, ] * (self.pulse_width // self.window_size)
|
||||
|
||||
return reference
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@ -59,6 +59,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="box_dac_dw">
|
||||
<property name="suffix">
|
||||
<string> bits</string>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string>DAC data width: </string>
|
||||
</property>
|
||||
@ -75,6 +78,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="box_adc_dw">
|
||||
<property name="suffix">
|
||||
<string> bits</string>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string>ADC data width: </string>
|
||||
</property>
|
||||
@ -91,6 +97,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="box_accum_width">
|
||||
<property name="suffix">
|
||||
<string> bits</string>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string>Accum width: </string>
|
||||
</property>
|
||||
@ -100,15 +109,18 @@
|
||||
<property name="maximum">
|
||||
<number>64</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>32</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="box_dac_adc_ratio">
|
||||
<widget class="QDoubleSpinBox" name="box_adc_dac_ratio">
|
||||
<property name="prefix">
|
||||
<string>DAC:ADC clk ratio: </string>
|
||||
<string>ADC:DAC clk ratio: </string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.200000000000000</double>
|
||||
@ -116,6 +128,9 @@
|
||||
<property name="maximum">
|
||||
<double>3.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.520000000000000</double>
|
||||
</property>
|
||||
@ -155,6 +170,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="box_packet_size">
|
||||
<property name="suffix">
|
||||
<string> bytes</string>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string>Packet size: </string>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user