Skip to content

Commit

Permalink
Use all kwargs in scipy filtering functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanielloNTIA committed Jul 17, 2024
1 parent 8608b77 commit e053e55
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions scos_actions/signal_processing/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def generate_elliptic_iir_low_pass_filter(
+ f"edge frequency {pb_edge_Hz} Hz."
)
ord, wn = ellipord(
pb_edge_Hz, sb_edge_Hz, gpass_dB, gstop_dB, False, sample_rate_Hz
wp=pb_edge_Hz,
ws=sb_edge_Hz,
gpass=gpass_dB,
gstop=gstop_dB,
analog=False,
fs=sample_rate_Hz,
)
sos = ellip(ord, gpass_dB, gstop_dB, wn, "lowpass", False, "sos", sample_rate_Hz)
return sos
Expand All @@ -62,14 +67,16 @@ def generate_fir_low_pass_filter(
:param sample_rate_Hz: Sampling rate, in Hz.
:return: Coeffiecients of the FIR low pass filter.
"""
ord, beta = kaiserord(attenuation_dB, width_Hz / (0.5 * sample_rate_Hz))
ord, beta = kaiserord(
ripple=attenuation_dB, width=width_Hz / (0.5 * sample_rate_Hz)
)
taps = firwin(
ord + 1,
cutoff_Hz,
width_Hz,
("kaiser", beta),
"lowpass",
True,
numtaps=ord + 1,
cutoff=cutoff_Hz,
width=width_Hz,
window=("kaiser", beta),
pass_zero="lowpass",
scale=True,
fs=sample_rate_Hz,
)
return taps
Expand All @@ -91,7 +98,7 @@ def get_iir_frequency_response(
The second is the array containing the frequency response values, which
are complex values in linear units.
"""
w, h = sosfreqz(sos, worN, whole=True, fs=sample_rate_Hz)
w, h = sosfreqz(sos=sos, worN=worN, whole=True, fs=sample_rate_Hz)
return w, h


Expand All @@ -110,7 +117,7 @@ def get_iir_phase_response(
frequencies, in Hz, for which the phase response was calculated.
The second is the array containing the phase response values, in radians.
"""
w, h = sosfreqz(sos, worN, whole=False, fs=sample_rate_Hz)
w, h = sosfreqz(sos=sos, worN=worN, whole=False, fs=sample_rate_Hz)
angles = np.unwrap(np.angle(h))
return w, angles

Expand Down Expand Up @@ -156,6 +163,6 @@ def is_stable(sos: np.ndarray) -> bool:
:param sos: Second-order sections representation of the IIR filter.
:return: True if the filter is stable, False if not.
"""
_, poles, _ = sos2zpk(sos)
_, poles, _ = sos2zpk(sos=sos)
stable = all([p < 1 for p in np.square(np.abs(poles))])
return stable

0 comments on commit e053e55

Please sign in to comment.