@@ -247,23 +247,20 @@ def plotCoherence(self):
247
247
if len (self .t ) == 0 or len (self .u ) == 0 or len (self .y ) == 0 :
248
248
return
249
249
250
- # Use selected range if available
250
+ # Use getInputOutputData with selected range
251
251
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
+ )
259
256
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
+ )
264
261
265
262
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
267
264
self .ax_coherence .clear ()
268
265
self .ax_coherence .set_title ("Coherence (Selection too short)" )
269
266
self .ax_coherence .text (0.5 , 0.5 , f"Not enough data ({ num_samples } samples).\n Select a larger window." ,
@@ -280,7 +277,7 @@ def plotCoherence(self):
280
277
fs = 1 / avg_time_diff
281
278
282
279
# Choose segment size
283
- nperseg = min (256 , num_samples // 4 ) # Also needs to be verified
280
+ nperseg = min (1024 , max ( 256 , num_samples // 8 ))
284
281
285
282
# Compute coherence
286
283
freq , Cuy = signal .coherence (u_sel , y_sel , fs , nperseg = nperseg )
0 commit comments