torch_ecg.utils.resample_irregular_timeseries

torch_ecg.utils.resample_irregular_timeseries(sig: ndarray, output_fs: Real | None = None, method: str = 'spline', return_with_time: bool = False, tnew: ndarray | None = None, interp_kw: dict = {}, verbose: int = 0) ndarray[source]

Resample the 2d irregular timeseries sig into a 1d or 2d regular time series with frequency output_fs, elements of sig are in the form [time, value], where the unit of time is ms.

Parameters:
  • sig (numpy.ndarray) – The 2d irregular timeseries. Each row is [time, value].

  • output_fs (numbers.Real, optional) – the frequency of the output 1d regular timeseries, one and only one of output_fs and tnew should be specified

  • method (str, default "spline") – interpolation method, can be “spline” or “interp1d”

  • return_with_time (bool, default False) – return a 2d array, with the 0-th coordinate being time

  • tnew (array_like, optional) – the array of time of the output array, one and only one of output_fs and tnew should be specified

  • interp_kw (dict, optional) – additional options for the corresponding methods in scipy.interpolate

Returns:

A 1d or 2d regular time series with frequency output_freq.

Return type:

numpy.ndarray

Examples

fs = 100
t_irr = np.sort(np.random.rand(fs)) * 1000
vals = np.random.randn(fs)
sig = np.stack([t_irr, vals], axis=1)
sig_reg = resample_irregular_timeseries(sig, output_fs=fs * 2, return_with_time=True)
sig_reg = resample_irregular_timeseries(sig, output_fs=fs, method="interp1d")
t_irr_2 = np.sort(np.random.rand(2 * fs)) * 1000
sig_reg = resample_irregular_timeseries(sig, tnew=t_irr_2, return_with_time=True)

Note

pandas also has the function to regularly resample irregular timeseries.