mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 09:28:02 +08:00
Add test for sampling
This commit is contained in:
@@ -25,10 +25,10 @@ class Interpolator(object):
|
||||
return coeffs, k - self.width
|
||||
|
||||
class Sampler(object):
|
||||
def __init__(self, src, interp):
|
||||
def __init__(self, src, interp=None):
|
||||
self.src = iter(src)
|
||||
self.freq = 1.0
|
||||
self.interp = interp
|
||||
self.interp = interp if (interp is not None) else Interpolator()
|
||||
coeffs, begin = self.interp.get(0)
|
||||
self.offset = -begin # should fill samples buffer
|
||||
self.buff = np.zeros(len(coeffs))
|
||||
|
||||
12
test_sampling.py
Normal file
12
test_sampling.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sampling
|
||||
import numpy as np
|
||||
|
||||
def test_resample():
|
||||
x = np.arange(300)
|
||||
s = sampling.Sampler(x)
|
||||
y = np.array(list(s))
|
||||
|
||||
k = s.interp.width - 1
|
||||
x = x[k:-k-1]
|
||||
err = np.max(np.abs(x - y))
|
||||
assert err < 1e-10
|
||||
Reference in New Issue
Block a user