From 031b5098d5dc680afab96cc1e9c95a6033b5200b Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Mon, 30 Sep 2024 12:09:39 +0200 Subject: [PATCH] [plotting calibration] fixing power spectrum --- pyrelacs/ui/mainwindow.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pyrelacs/ui/mainwindow.py b/pyrelacs/ui/mainwindow.py index 51f014a..0317c56 100644 --- a/pyrelacs/ui/mainwindow.py +++ b/pyrelacs/ui/mainwindow.py @@ -44,6 +44,7 @@ class PyRelacs(QMainWindow): self.power_plot.addLegend() self.beat_plot.setBackground("w") self.power_plot.setBackground("w") + self.power_plot.setLogMode(x=False, y=True) self.threadpool = QThreadPool() self.repros = Repro() @@ -80,17 +81,23 @@ class PyRelacs(QMainWindow): self._rlx_aboutaction.setEnabled(True) self._rlx_aboutaction.triggered.connect(self.on_about) - self._daq_connectaction = QAction(QIcon(":icons/connect.png"), "Connect DAQ", self) + self._daq_connectaction = QAction( + QIcon(":icons/connect.png"), "Connect DAQ", self + ) self._daq_connectaction.setStatusTip("Connect to daq device") # self._daq_connectaction.setShortcut(QKeySequence("Alt+d")) self._daq_connectaction.triggered.connect(self.connect_dac) - self._daq_disconnectaction = QAction(QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self) + self._daq_disconnectaction = QAction( + QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self + ) self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device") # self._daq_connectaction.setShortcut(QKeySequence("Alt+d")) self._daq_disconnectaction.triggered.connect(self.disconnect_dac) - self._daq_calibaction = QAction(QIcon(":/icons/calibration.png"), "Plot calibration", self) + self._daq_calibaction = QAction( + QIcon(":/icons/calibration.png"), "Plot calibration", self + ) self._daq_calibaction.setStatusTip("Calibrate the attenuator device") # self._daq_calibaction.setShortcut(QKeySequence("Alt+d")) self._daq_calibaction.triggered.connect(self.plot_calibration) @@ -205,21 +212,24 @@ class PyRelacs(QMainWindow): beat = stim[:] + fish[:] beat_squared = beat**2 - f, powerspec = welch(beat, fs=40_000.0) - powerspec = decibel(powerspec) + f, powerspec = welch( + beat_squared, + window="flattop", + fs=40_000.0, + nperseg=100_000, + ) - f_sq, powerspec_sq = welch(beat_squared, fs=40_000.0) - powerspec_sq = decibel(powerspec_sq) - peaks = find_peaks(powerspec_sq, prominence=10)[0] + peaks = find_peaks(powerspec, prominence=0.001)[0] pen = pg.mkPen(colors[i]) + self.beat_plot.plot( np.arange(0, len(beat)) / 40_000.0, - beat_squared, + beat, pen=pen, name=stim.name, ) - self.power_plot.plot(f_sq, powerspec_sq, pen=pen, name=stim.name) - self.power_plot.plot(f[peaks], powerspec_sq[peaks], pen=None, symbol="x") + self.power_plot.plot(f, powerspec, pen=pen, name=stim.name) + self.power_plot.plot(f[peaks], powerspec[peaks], pen=None, symbol="x") def connect_dac(self): devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)