torch_ecg.utils.remove_spikes_naive#

torch_ecg.utils.remove_spikes_naive(sig: ndarray, threshold: Real = 20, inplace: bool = True) ndarray[source]#

Remove signal spikes using a naive method.

This is a method proposed in entry 0416 of CPSC2019. spikes here refers to abrupt large bumps with (abs) value larger than the given threshold, or nan values (read by wfdb). Do NOT confuse with spikes in paced rhythm.

Parameters:
  • sig (numpy.ndarray) – 1D, 2D or 3D signal with potential spikes. The last dimension is the time dimension. The signal can be single-lead, multi-lead, or batched signals.

  • threshold (numbers.Real, optional) – Values of sig that are larger than threshold will be removed.

  • inplace (bool, optional) – Whether to modify sig in place or not.

Returns:

Signal with spikes removed.

Return type:

numpy.ndarray

Examples

sig = np.random.randn(1000)
pos = np.random.randint(0, 1000, 10)
sig[pos] = 100
sig = remove_spikes_naive(sig)
pos = np.random.randint(0, 1000, 1)
sig[pos] = np.nan
sig = remove_spikes_naive(sig)