@@ -90,7 +90,7 @@ def check_filter_definition(pass_type, f_range):
9090
9191
9292def check_filter_properties (filter_coefs , a_vals , fs , pass_type , f_range ,
93- transitions = (- 20 , - 3 ), verbose = True ):
93+ transitions = (- 20 , - 3 ), filt_type = None , verbose = True ):
9494 """Check a filters properties, including pass band and transition band.
9595
9696 Parameters
@@ -164,7 +164,8 @@ def check_filter_properties(filter_coefs, a_vals, fs, pass_type, f_range,
164164
165165 # Compute pass & transition bandwidth
166166 pass_bw = compute_pass_band (fs , pass_type , f_range )
167- transition_bw = compute_transition_band (f_db , db , transitions [0 ], transitions [1 ])
167+ transition_bw , f_range_trans = compute_transition_band (f_db , db , transitions [0 ], transitions [1 ],
168+ return_freqs = True )
168169
169170 # Raise warning if transition bandwidth is too high
170171 if transition_bw > pass_bw :
@@ -174,8 +175,50 @@ def check_filter_properties(filter_coefs, a_vals, fs, pass_type, f_range,
174175
175176 # Print out transition bandwidth and pass bandwidth to the user
176177 if verbose :
177- print ('Transition bandwidth is {:.1f} Hz.' .format (transition_bw ))
178- print ('Pass/stop bandwidth is {:.1f} Hz.' .format (pass_bw ))
178+
179+ # Filter type (high-pass, low-pass, band-pass, band-stop, FIR, IIR)
180+ print ('Pass Type: {pass_type}' .format (pass_type = pass_type ))
181+
182+ # Cutoff frequency (including definition)
183+ cutoff = round (np .min (f_range ) + (0.5 * transition_bw ), 3 )
184+ print ('Cutoff (half-amplitude): {cutoff} Hz' .format (cutoff = cutoff ))
185+
186+ # Filter order (or length)
187+ print ('Filter order: {order}' .format (order = len (f_db )- 1 ))
188+
189+ # Roll-off or transition bandwidth
190+ print ('Transition bandwidth: {:.1f} Hz' .format (transition_bw ))
191+ print ('Pass/stop bandwidth: {:.1f} Hz' .format (pass_bw ))
192+
193+ # Passband ripple and stopband attenuation
194+ pb_ripple = np .max (db [:np .where (f_db < f_range_trans [0 ])[0 ][- 1 ]])
195+ sb_atten = np .max (db [np .where (f_db > f_range_trans [1 ])[0 ][0 ]:])
196+ print ('Passband Ripple: {pb_ripple} db' .format (pb_ripple = pb_ripple ))
197+ print ('Stopband Attenuation: {sb_atten} db' .format (sb_atten = sb_atten ))
198+
199+ # Filter delay (zero-phase, linear-phase, non-linear phase)
200+ if filt_type == 'FIR' and pass_type in ['bandstop' , 'lowpass' ]:
201+ filt_class = 'linear-phase'
202+ elif filt_type == 'FIR' and pass_type in ['bandpass' , 'highpass' ]:
203+ filt_class = 'zero-phase'
204+ elif filt_type == 'IIR' :
205+ filt_class = 'non-linear-phase'
206+ else :
207+ filt_class = None
208+
209+ if filt_type is not None :
210+ print ('Filter Class: {filt_class}' .format (filt_class = filt_class ))
211+
212+ if filt_class == 'linear-phase' :
213+ print ('Group Delay: {delay}s' .format (delay = (len (f_db )- 1 ) / 2 * fs ))
214+ elif filt_class == 'zero-phase' :
215+ print ('Group Delay: 0s' )
216+
217+ # Direction of computation (one-pass forward/reverse, or two-pass forward and reverse)
218+ if filt_type == 'FIR' :
219+ print ('Direction: one-pass reverse.' )
220+ else :
221+ print ('Direction: two-pass forward and reverse' )
179222
180223 return passes
181224
0 commit comments