mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 01:18:02 +08:00
26 lines
655 B
Python
26 lines
655 B
Python
from amodem import sampling
|
|
from amodem import common
|
|
|
|
import numpy as np
|
|
from io import BytesIO
|
|
|
|
|
|
def test_resample():
|
|
x = np.sin(2*np.pi * 10 * np.linspace(0, 1, 1001))
|
|
src = BytesIO(common.dumps(x))
|
|
dst = BytesIO()
|
|
sampling.resample(src=src, dst=dst, df=0.0)
|
|
y = common.loads(dst.getvalue())
|
|
err = x[1:len(y)+1] - y
|
|
assert np.max(np.abs(err)) < 1e-4
|
|
|
|
dst = BytesIO()
|
|
sampling.resample(src=BytesIO(b'\x00\x00'), dst=dst, df=0.0)
|
|
assert dst.tell() == 0
|
|
|
|
|
|
def test_coeffs():
|
|
I = sampling.Interpolator(width=4, resolution=16)
|
|
err = I.filt[0] - [0, 0, 0, 1, 0, 0, 0, 0]
|
|
assert np.max(np.abs(err)) < 1e-10
|