cardinal_pythonlib.dsp


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Digital signal processing functions.

cardinal_pythonlib.dsp.bandpass_filter(data: List[float] | ndarray, sampling_freq_hz: float, lower_freq_hz: float, upper_freq_hz: float, numtaps: int) List[float] | ndarray[source]

Apply a band-pass filter to the data.

Parameters:
  • data – time series of the data

  • sampling_freq_hz – sampling frequency f_s, in Hz (or other consistent units)

  • lower_freq_hz – filter cutoff lower frequency in Hz (or other consistent units)

  • upper_freq_hz – filter cutoff upper frequency in Hz (or other consistent units)

  • numtaps – number of filter taps

Returns:

filtered data

Note: number of filter taps = filter order + 1

cardinal_pythonlib.dsp.highpass_filter(data: List[float] | ndarray, sampling_freq_hz: float, cutoff_freq_hz: float, numtaps: int) List[float] | ndarray[source]

Apply a high-pass filter to the data.

Parameters:
  • data – time series of the data

  • sampling_freq_hz – sampling frequency f_s, in Hz (or other consistent units)

  • cutoff_freq_hz – filter cutoff frequency in Hz (or other consistent units)

  • numtaps – number of filter taps

Returns:

filtered data

Note: number of filter taps = filter order + 1

cardinal_pythonlib.dsp.lowpass_filter(data: List[float] | ndarray, sampling_freq_hz: float, cutoff_freq_hz: float, numtaps: int) List[float] | ndarray[source]

Apply a low-pass filter to the data.

Parameters:
  • data – time series of the data

  • sampling_freq_hz – sampling frequency f_s, in Hz (or other consistent units)

  • cutoff_freq_hz – filter cutoff frequency in Hz (or other consistent units)

  • numtaps – number of filter taps

Returns:

filtered data

Note: number of filter taps = filter order + 1

cardinal_pythonlib.dsp.normalized_frequency(f: float, sampling_freq: float) float[source]

Returns a normalized frequency:

Parameters:
  • f – frequency f

  • sampling_freq – sampling frequency f_s

Returns:

normalized frequency

f_n = f / (f_s / 2)

Principles:

cardinal_pythonlib.dsp.notch_filter(data: List[float] | ndarray, sampling_freq_hz: float, notch_freq_hz: float, quality_factor: float) List[float] | ndarray[source]

Design and use a notch (band reject) filter to filter the data.

Parameters:
  • data – time series of the data

  • sampling_freq_hz – sampling frequency f_s, in Hz (or other consistent units)

  • notch_freq_hz – notch frequency, in Hz (or other consistent units)

  • quality_factor – notch filter quality factor, Q

Returns:

filtered data