Skip to content

Commit d129686

Browse files
committed
data_selection_window: don't use downsampled data for coherence
1 parent 8d623c0 commit d129686

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

autotune/data_selection_window.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,20 @@ def plotCoherence(self):
247247
if len(self.t) == 0 or len(self.u) == 0 or len(self.y) == 0:
248248
return
249249

250-
# Use selected range if available
250+
# Use getInputOutputData with selected range
251251
if self.t_start is not None and self.t_stop is not None and self.t_stop > self.t_start:
252-
# Get indices within selected range
253-
ind_start = np.searchsorted(self.t, self.t_start)
254-
ind_stop = np.searchsorted(self.t, self.t_stop)
255-
256-
t_sel = self.t[ind_start:ind_stop]
257-
u_sel = self.u[ind_start:ind_stop]
258-
y_sel = self.y[ind_start:ind_stop]
252+
t_sel, u_sel, y_sel, _ = self.data_extractor.getInputOutputData(
253+
self.topics[self.index_u], self.topics[self.index_y],
254+
self.t_start, self.t_stop
255+
)
259256
else:
260-
# Fall back to full signal if no range selected
261-
t_sel = self.t
262-
u_sel = self.u
263-
y_sel = self.y
257+
# If no range selected, just use full duration
258+
t_sel, u_sel, y_sel, _ = self.data_extractor.getInputOutputData(
259+
self.topics[self.index_u], self.topics[self.index_y]
260+
)
264261

265262
num_samples = len(t_sel)
266-
if num_samples < 64: # I kind of made up this number -> maybe requires some research
263+
if num_samples < 256: # I kind of made up this number -> maybe requires some research
267264
self.ax_coherence.clear()
268265
self.ax_coherence.set_title("Coherence (Selection too short)")
269266
self.ax_coherence.text(0.5, 0.5, f"Not enough data ({num_samples} samples).\nSelect a larger window.",
@@ -280,7 +277,7 @@ def plotCoherence(self):
280277
fs = 1 / avg_time_diff
281278

282279
# Choose segment size
283-
nperseg = min(256, num_samples // 4) # Also needs to be verified
280+
nperseg = min(1024, max(256, num_samples // 8))
284281

285282
# Compute coherence
286283
freq, Cuy = signal.coherence(u_sel, y_sel, fs, nperseg=nperseg)

0 commit comments

Comments
 (0)