Basics

Main signal object

class pyPCG.pcg_signal(data: ndarray[tuple[int, ...], dtype[int64 | float64]], fs: int = 1, log: list[str] | None = None)[source]

PCG signal object. This is used to store the signal data, as well as its sampling rate. The object also includes a processing log to track the processing steps and settings done to the signal.

When using the plot function the last step is used as a default figure title.

All processing steps require an object like this as input, and their output is also a signal object.

data

signal data

Type:

np.ndarray

fs

sampling rate in Hz

Type:

int

processing_log

processing steps and parameters on the signal

Type:

list[str]

Example

Creating a signal from numpy array:

>>> import pyPCG
>>> import numpy as np
>>> sig = np.arange(10)
>>> signal = pyPCG.pcg_signal(sig,100,["Example signal"])
>>> print(signal)
PCG signal [0.1s 100Hz] ['Example signal']

Using pyPCG.io.read_signal_file():

>>> import pyPCG
>>> import pyPCG.io
>>> # reading in a 60 second long wav file with 333 Hz sampling rate
>>> sig, fs = pyPCG.io.read_signal_file("example.wav","wav")
>>> signal = pyPCG.pcg_signal(sig,fs)
>>> # or optionally using the splat operator
>>> signal = pyPCG.pcg_signal(*pyPCG.io.read_signal_file("example.wav","wav"))
>>> print(signal)
PCG signal [60s 333Hz] ['File read in']

Basic processing

pyPCG.zero_center(sig: pcg_signal) pcg_signal[source]

Center signal to zero

Parameters:

sig (pcg_signal) – Input signal

Returns:

Centered signal

Return type:

pcg_signal

pyPCG.unit_scale(sig: pcg_signal) pcg_signal[source]

Scale signal to [-1,1] interval

Parameters:

sig (pcg_signal) – Input signal

Returns:

Scaled signal

Return type:

pcg_signal

pyPCG.std_scale(sig: pcg_signal) pcg_signal[source]

Scale signal to 1 std

Parameters:

sig (pcg_signal) – Input signal

Returns:

Scaled signal

Return type:

pcg_signal

pyPCG.normalize(sig: pcg_signal) pcg_signal[source]

Center to zero and scale signal to [-1,1] interval

Parameters:

sig (pcg_signal) – Input signal

Returns:

Normalized signal

Return type:

pcg_signal

Visualization

pyPCG.plot(sig: pcg_signal, zeroline: bool = False, xlim: tuple | None = None) None[source]

Plot pcg signal with appropriate dimensions

Parameters:
  • sig (pcg_signal) – signal to plot

  • zeroline (bool, optional) – plot a dashed line at zero. Defaults to False.

  • xlim (tuple, optional) – set horizontal limits on the plot. Where time is the horizontal axis and it is measured in seconds.