Skip to content

Commit 80869f6

Browse files
Add resample_signal to signals.tools module (#67)
* Add resample_signal to signals.tools module * Add decimation to resample_signal It applies a low-pass filter before downsampling a signal to avoid aliasing. Filter type and order can be passed to the function. * Revert "Add decimation to resample_signal" This reverts commit 94a93b6.
1 parent 0bec4ab commit 80869f6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

biosppy/signals/tools.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,3 +2266,31 @@ def detrend_smoothness_priors(signal, smoothing_factor=10):
22662266
z_detrended = np.array(signal) - z_trend
22672267

22682268
return utils.ReturnTuple((z_detrended.T, z_trend.T), ('detrended', 'trend'))
2269+
2270+
2271+
def resample_signal(signal, sampling_rate, resampling_rate):
2272+
"""
2273+
Resample a signal to a new sampling frequency. It assumes that the input signal is uniformly sampled.
2274+
2275+
Parameters
2276+
----------
2277+
signal : array-like
2278+
The signal to resample.
2279+
sampling_rate : float
2280+
The original sampling frequency of the signal.
2281+
resampling_rate : float
2282+
The new sampling frequency.
2283+
2284+
Returns
2285+
-------
2286+
resampled_signal : array-like
2287+
The resampled signal.
2288+
"""
2289+
2290+
# check inputs
2291+
if signal is None:
2292+
raise TypeError("Please specify a signal to resample.")
2293+
2294+
resampled_signal = ss.resample(signal, int(len(signal) * resampling_rate / sampling_rate))
2295+
2296+
return utils.ReturnTuple((resampled_signal,), ('signal',))

0 commit comments

Comments
 (0)