@@ -225,6 +225,7 @@ def initPlots(self):
225225 self .ax_coherence .set_title ("Coherence" )
226226 self .ax_coherence .set_xlabel ("Frequency (Hz)" )
227227 self .ax_coherence .set_ylabel ("Coherence" )
228+ self .ax_coherence .set_xscale ('log' )
228229
229230 self .canvas .mpl_connect ('scroll_event' , self .zoom_fun )
230231 self .canvas .draw ()
@@ -278,9 +279,13 @@ def plotCoherence(self):
278279 )
279280
280281 num_samples = len (t_sel )
282+ duration = t_sel [- 1 ] - t_sel [0 ]
281283
282- if num_samples < 256 :
283- self .label_warning .setText (f"Not enough data ({ num_samples } samples). Select a larger window." )
284+ if num_samples < 256 or duration < 5 :
285+ self .label_warning .setText (
286+ f"Increase the window size to at least 5 seconds and 256 samples. "
287+ f"Currently selected: { duration :.2f} seconds, { num_samples } samples."
288+ )
284289 self .label_warning .show ()
285290
286291 self .coherence_ref .set_xdata ([])
@@ -305,15 +310,14 @@ def plotCoherence(self):
305310 # Update coherence plot
306311 self .coherence_ref .set_xdata (freq )
307312 self .coherence_ref .set_ydata (Cuy )
308- self .ax_coherence .set_xlim ([min ( freq ), max ( freq ) ])
313+ self .ax_coherence .set_xlim ([0 , 20 ])
309314 self .ax_coherence .set_ylim ([0 , 1 ])
310315
311316 # Remove previous annotation if it exists
312317 if self .coherence_info_text is not None :
313318 self .coherence_info_text .remove ()
314319 self .coherence_info_text = None
315320
316- duration = t_sel [- 1 ] - t_sel [0 ]
317321 freq_res = fs / nperseg
318322 info_text = (f"Samples: { num_samples } , Duration: { duration :.2f} s, "
319323 f"fs: { fs :.1f} Hz, nperseg: { nperseg } , Δf: { freq_res :.2f} Hz" )
0 commit comments