Skip to content

Commit 77b4ac7

Browse files
committed
copy ricker wavelet from scipy which removed it from version 1.15.0, fixing issue #525
1 parent c6d4fd9 commit 77b4ac7

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

wfdb/processing/qrs.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def _mwi(self):
215215
N/A
216216
217217
"""
218-
wavelet_filter = signal.ricker(self.qrs_width, 4)
218+
wavelet_filter = ricker(self.qrs_width, 4)
219219

220220
self.sig_i = (
221221
signal.filtfilt(wavelet_filter, [1], self.sig_f, axis=0) ** 2
@@ -277,7 +277,7 @@ def _learn_init_params(self, n_calib_beats=8):
277277
qrs_amps = []
278278
noise_amps = []
279279

280-
ricker_wavelet = signal.ricker(self.qrs_radius * 2, 4).reshape(-1, 1)
280+
ricker_wavelet = ricker(self.qrs_radius * 2, 4).reshape(-1, 1)
281281

282282
# Find the local peaks of the signal.
283283
peak_inds_f = find_local_peaks(self.sig_f, self.qrs_radius)
@@ -1776,3 +1776,52 @@ def gqrs_detect(
17761776
annotations = gqrs.detect(x=d_sig, conf=conf, adc_zero=adc_zero)
17771777

17781778
return np.array([a.time for a in annotations])
1779+
1780+
1781+
def ricker(points, a):
1782+
"""
1783+
Return a Ricker wavelet, also known as the "Mexican hat wavelet".
1784+
1785+
It models the function:
1786+
1787+
``A * (1 - (x/a)**2) * exp(-0.5*(x/a)**2)``,
1788+
1789+
where ``A = 2/(sqrt(3*a)*(pi**0.25))``.
1790+
1791+
This function is copied from the `scipy` library which
1792+
removed it from version 1.15.0.
1793+
1794+
Parameters
1795+
----------
1796+
points : int
1797+
Number of points in `vector`.
1798+
Will be centered around 0.
1799+
a : scalar
1800+
Width parameter of the wavelet.
1801+
1802+
Returns
1803+
-------
1804+
vector : (N,) ndarray
1805+
Array of length `points` in shape of ricker curve.
1806+
1807+
Examples
1808+
--------
1809+
>>> import matplotlib.pyplot as plt
1810+
1811+
>>> points = 100
1812+
>>> a = 4.0
1813+
>>> vec2 = ricker(points, a)
1814+
>>> print(len(vec2))
1815+
100
1816+
>>> plt.plot(vec2)
1817+
>>> plt.show()
1818+
1819+
"""
1820+
A = 2 / (np.sqrt(3 * a) * (np.pi**0.25))
1821+
wsq = a**2
1822+
vec = np.arange(0, points) - (points - 1.0) / 2
1823+
xsq = vec**2
1824+
mod = (1 - xsq / wsq)
1825+
gauss = np.exp(-xsq / (2 * wsq))
1826+
total = A * mod * gauss
1827+
return total

0 commit comments

Comments
 (0)