More accurate resampling

pull/14/head
Ewald de Wit 2022-09-13 11:46:18 +02:00
rodzic be610c17e7
commit bf36fc9dcb
1 zmienionych plików z 6 dodań i 3 usunięć

Wyświetl plik

@ -267,12 +267,15 @@ def linear_chirp(f0: float, f1: float, secs: float, rate: int):
def resample(a: np.ndarray, size: int) -> np.ndarray:
"""
Re-sample the array ``a`` to the given new ``size``.
Re-sample the array ``a`` to the given new ``size`` in a way that
preserves the overall density.
"""
xp = np.linspace(0, 1, a.size)
yp = np.cumsum(a)
x = np.linspace(0, 1, size)
y = np.interp(x, xp, a)
return y
y = np.interp(x, xp, yp)
r = size / a.size * np.diff(y, prepend=0)
return r
@njit