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