@@ -108,6 +108,40 @@ class Synchronization:
108108 """
109109
110110 def __init__ (self , sensitivity = 100 , output_phase = False , filter_params = None , phase_threshold = 0.7 ):
111+ # Validate sensitivity
112+ if not isinstance (sensitivity , int ):
113+ raise TypeError (f"sensitivity must be an integer, got { type (sensitivity ).__name__ } " )
114+ if sensitivity <= 0 :
115+ raise ValueError (f"sensitivity must be positive, got { sensitivity } " )
116+ if sensitivity > 10000 : # Reasonable upper limit
117+ raise ValueError (f"sensitivity too large ({ sensitivity } ), maximum is 10,000" )
118+
119+ # Validate output_phase
120+ if not isinstance (output_phase , bool ):
121+ raise TypeError (f"output_phase must be boolean, got { type (output_phase ).__name__ } " )
122+
123+ # Validate phase_threshold
124+ if not isinstance (phase_threshold , (int , float )):
125+ raise TypeError (f"phase_threshold must be a number, got { type (phase_threshold ).__name__ } " )
126+ if not 0 <= phase_threshold <= 1 :
127+ raise ValueError (f"phase_threshold must be between 0 and 1, got { phase_threshold } " )
128+
129+ # Validate filter_params if provided
130+ if filter_params is not None :
131+ if not isinstance (filter_params , (tuple , list )):
132+ raise TypeError (f"filter_params must be a tuple or list, got { type (filter_params ).__name__ } " )
133+ if len (filter_params ) != 3 :
134+ raise ValueError (f"filter_params must have 3 elements (lowcut, highcut, fs), got { len (filter_params )} " )
135+ lowcut , highcut , fs = filter_params
136+ if not all (isinstance (x , (int , float )) for x in filter_params ):
137+ raise TypeError ("filter_params must contain only numbers" )
138+ if lowcut <= 0 or highcut <= 0 or fs <= 0 :
139+ raise ValueError ("filter_params frequencies must be positive" )
140+ if lowcut >= highcut :
141+ raise ValueError (f"lowcut ({ lowcut } ) must be less than highcut ({ highcut } )" )
142+ if highcut >= fs / 2 :
143+ raise ValueError (f"highcut ({ highcut } ) must be less than Nyquist frequency ({ fs / 2 } )" )
144+
111145 self .plv_history = deque (maxlen = sensitivity )
112146 self .output_phase = output_phase
113147 self .filter_params = filter_params
0 commit comments