feat: add overlay plot showing A and B waveforms together
This commit is contained in:
1 parent
eaa23604a5
commit
46f8998f21
1 file changed
+16
-7
+16
-7
@@ -166,24 +166,34 @@ class SyncWindow(QtWidgets.QMainWindow):
|
|||||||
self.gw = pg.GraphicsLayoutWidget()
|
self.gw = pg.GraphicsLayoutWidget()
|
||||||
lay.addWidget(self.gw, stretch=1)
|
lay.addWidget(self.gw, stretch=1)
|
||||||
|
|
||||||
|
# overlay: A and B on same axes
|
||||||
|
self.p0 = self.gw.addPlot(row=0, col=0, title="Overlay A (teal) + B (red)")
|
||||||
|
self.p0.showGrid(x=True, y=True)
|
||||||
|
self.p0.setLabel("bottom", "Time", "s")
|
||||||
|
self.curve_a_ov = self.p0.plot(self.t_a, self.a_plot, pen=pg.mkPen("#4cc9f0", width=1), name="A")
|
||||||
|
self.curve_b_ov = self.p0.plot(self.t_b, self.b_plot, pen=pg.mkPen("#f72585", width=1, style=QtCore.Qt.PenStyle.DashLine), name="B")
|
||||||
|
self.p0.addLegend(offset=(60, 10))
|
||||||
|
self.p0.setMouseEnabled(x=True, y=False)
|
||||||
|
|
||||||
# waveform A
|
# waveform A
|
||||||
self.p1 = self.gw.addPlot(row=0, col=0, title="Waveform A (reference)")
|
self.p1 = self.gw.addPlot(row=1, col=0, title="Waveform A (reference)")
|
||||||
self.p1.showGrid(x=True, y=True)
|
self.p1.showGrid(x=True, y=True)
|
||||||
self.p1.setLabel("bottom", "Time", "s")
|
self.p1.setLabel("bottom", "Time", "s")
|
||||||
self.curve_a = self.p1.plot(self.t_a, self.a_plot, pen=pg.mkPen("#4cc9f0", width=1))
|
self.curve_a = self.p1.plot(self.t_a, self.a_plot, pen=pg.mkPen("#4cc9f0", width=1))
|
||||||
self.p1.setMouseEnabled(x=True, y=False)
|
self.p1.setMouseEnabled(x=True, y=False)
|
||||||
|
|
||||||
# waveform B with lag
|
# waveform B with lag
|
||||||
self.p2 = self.gw.addPlot(row=1, col=0, title=f"Waveform B (shifted by lag)")
|
self.p2 = self.gw.addPlot(row=2, col=0, title=f"Waveform B (shifted by lag)")
|
||||||
self.p2.showGrid(x=True, y=True)
|
self.p2.showGrid(x=True, y=True)
|
||||||
self.p2.setLabel("bottom", "Time", "s")
|
self.p2.setLabel("bottom", "Time", "s")
|
||||||
self.curve_b = self.p2.plot(self.t_b, self.b_plot, pen=pg.mkPen("#f72585", width=1))
|
self.curve_b = self.p2.plot(self.t_b, self.b_plot, pen=pg.mkPen("#f72585", width=1))
|
||||||
self.p2.setMouseEnabled(x=True, y=False)
|
self.p2.setMouseEnabled(x=True, y=False)
|
||||||
# link x
|
# link x
|
||||||
self.p2.setXLink(self.p1)
|
self.p1.setXLink(self.p0)
|
||||||
|
self.p2.setXLink(self.p0)
|
||||||
|
|
||||||
# xcorr
|
# xcorr
|
||||||
self.p3 = self.gw.addPlot(row=2, col=0, title="Cross-correlation (GCC-PHAT)" if method=="phat" else "Cross-correlation")
|
self.p3 = self.gw.addPlot(row=3, col=0, title="Cross-correlation (GCC-PHAT)" if method=="phat" else "Cross-correlation")
|
||||||
self.p3.showGrid(x=True, y=True)
|
self.p3.showGrid(x=True, y=True)
|
||||||
self.p3.setLabel("bottom", "Lag", "s")
|
self.p3.setLabel("bottom", "Lag", "s")
|
||||||
# decimate corr with peak awareness
|
# decimate corr with peak awareness
|
||||||
@@ -316,11 +326,9 @@ class SyncWindow(QtWidgets.QMainWindow):
|
|||||||
self.spin_samp.blockSignals(True); self.spin_samp.setValue(lag_samp); self.spin_samp.blockSignals(False)
|
self.spin_samp.blockSignals(True); self.spin_samp.setValue(lag_samp); self.spin_samp.blockSignals(False)
|
||||||
self.peak_line.setPos(lag_sec)
|
self.peak_line.setPos(lag_sec)
|
||||||
# shift B curve visually by lag (pad with silence not needed for visualize, just shift x)
|
# shift B curve visually by lag (pad with silence not needed for visualize, just shift x)
|
||||||
# we keep t_b but offset x
|
|
||||||
shift = lag_sec
|
shift = lag_sec
|
||||||
# pyqtgraph setPos shifts items; we recreate x
|
|
||||||
# Instead shift data: plot t_b + lag
|
|
||||||
self.curve_b.setData(self.t_b + shift, self.b_plot)
|
self.curve_b.setData(self.t_b + shift, self.b_plot)
|
||||||
|
self.curve_b_ov.setData(self.t_b + shift, self.b_plot)
|
||||||
self._update_xcorr_label()
|
self._update_xcorr_label()
|
||||||
self.update_labels()
|
self.update_labels()
|
||||||
self._updating = False
|
self._updating = False
|
||||||
@@ -375,6 +383,7 @@ class SyncWindow(QtWidgets.QMainWindow):
|
|||||||
self.a_plot, _ = decimate_for_plot(self.a)
|
self.a_plot, _ = decimate_for_plot(self.a)
|
||||||
self.b_plot, _ = decimate_for_plot(self.b)
|
self.b_plot, _ = decimate_for_plot(self.b)
|
||||||
self.curve_a.setData(self.t_a, self.a_plot)
|
self.curve_a.setData(self.t_a, self.a_plot)
|
||||||
|
self.curve_a_ov.setData(self.t_a, self.a_plot)
|
||||||
# recalc
|
# recalc
|
||||||
lag, _, corr = correlate(self.a, self.b, sr=self.sr, method=self.method, device=self.device_pref)
|
lag, _, corr = correlate(self.a, self.b, sr=self.sr, method=self.method, device=self.device_pref)
|
||||||
self.corr = corr
|
self.corr = corr
|
||||||
|
|||||||
Reference in new issue
Block a user