Function Description#

This module provides a collection of reusable singal processing functions.

Available Functions:

  • MovingFilter : moving filter with different properties

  • Digitalize_Data : extracts binary data from measured signals (e.g. SPI or I2C)

chrispytools.signalprocessing.Digitalize_Data(data, clock, chipselect=[], edge_trigger='rising', high_val=1, low_val=0, trigger_val=0.5, threshold_high=2, threshold_low=0.8, onlyDigi=False, debug=False, muteWarnings=True)#

Convert analog data streams into a digital bit stream using clock edge sampling.

The function applies a Schmitt-trigger based digitization to the input signals and samples the digital data at specified clock edges. Optionally, sampling can be restricted to active chip-select windows.

Parameters:
  • data (array_like) – Analog data signal to be digitized and sampled.

  • clock (array_like) – Analog clock signal used for edge-triggered sampling.

  • chipselect (array_like, optional) – Optional analog chip-select signal. If provided, sampling is only performed while chip-select is active. Must have the same length as data.

  • edge_trigger ({'rising', 'falling'}, optional) – Selects whether rising or falling edges of the clock are used for sampling.

  • high_val (int or float, optional) – Digital value assigned to samples above threshold_high.

  • low_val (int or float, optional) – Digital value assigned to samples below or equal to threshold_low.

  • trigger_val (float, optional) – Threshold used for edge detection of clock and chip-select signals.

  • threshold_high (float, optional) – Upper Schmitt-trigger threshold for digitization.

  • threshold_low (float, optional) – Lower Schmitt-trigger threshold for digitization.

  • onlyDigi (bool, optional) – If True, returns only the digitized data stream and conversion error indices without performing clocked sampling.

  • debug (bool, optional) – If True, returns dictionary with additional details for debugging.

  • muteWarnings (bool, optional) – If False, prints warnings for values that cannot be digitized.

Returns:

binary_data – If chipselect is not provided, returns a one-dimensional array containing the sampled digital data. If chipselect is provided, returns a list of arrays, one per chip-select active window.

Return type:

ndarray or list of ndarray

Notes

  • Digitization is performed using a Schmitt trigger to avoid noise-induced oscillations near the switching threshold.

  • Samples that cannot be uniquely digitized are removed from all signals before edge detection.

  • Clock and chip-select edges are detected using trigger_val.

chrispytools.signalprocessing.MovingFilter(Xdata, Ydata, FilterType='MovingAvg', **kwargs)#

Applies a simple moving filter to one dimensional data. The filter behavior is selected via the FilterType argument, while filter-specific parameters are passed through **kwargs.

Moving average based on Moving average or running mean. Envelope extraction based on How to get high and low envelope of a signal.

Parameters:
  • Xdata (array-like) – X-axis data corresponding to the input signal.

  • Ydata (array-like) – Y-axis signal data to be filtered.

  • FilterType (str, optional) –

    Selects the filter algorithm to apply.

    Supported values are:

    • "MovingAvg" : Simple moving average filter.

    • "Envelope" : Upper and lower envelope extraction.

  • **kwargs (dict) –

    Additional keyword arguments forwarded to the selected filter.

    MovingAvg
    Nint, optional

    Window size of the moving average (default: 3).

    Envelope
    dminint, optional

    Chunk size used to determine local minima (default: 1).

    dmaxint, optional

    Chunk size used to determine local maxima (default: 1).

    splitbool, optional

    If True, splits the signal by its mean before envelope extraction (default: False).

Returns:

Dictionary containing the filtered data as NumPy arrays.

MovingAvg
  • "XData" : Filtered X-axis data

  • "YData" : Smoothed Y-axis data

Envelope
  • "XData_min", "YData_min" : Lower envelope

  • "XData_max", "YData_max" : Upper envelope

Return type:

dict