diff options
author | Jon Nordby <jononor@gmail.com> | 2025-05-14 20:21:50 +0200 |
---|---|---|
committer | Jon Nordby <jononor@gmail.com> | 2025-05-14 20:21:50 +0200 |
commit | 1da46af71f9f192d534886325d5ea530c78bee38 (patch) | |
tree | f65bdb730ce60451a23d1a208dd1d3f232614003 /bindings/test_galearn_pdm.py | |
parent | c86294b1f07624eee3c3749fb877aff96413f17b (diff) |
bindings: Improve test for PDM to PCM
Diffstat (limited to 'bindings/test_galearn_pdm.py')
-rw-r--r-- | bindings/test_galearn_pdm.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/bindings/test_galearn_pdm.py b/bindings/test_galearn_pdm.py index 43cb58e..b0fda96 100644 --- a/bindings/test_galearn_pdm.py +++ b/bindings/test_galearn_pdm.py @@ -1,16 +1,42 @@ -import galearn_pdm import numpy +from pcm2pdm import convert +from testsignal import generate_test_tone +from test_pdm import plot_reconstruct +import galearn_pdm + +sr = 16000 +decimation = 64 + def test_one(): - inp = numpy.ones(shape=10, dtype=numpy.uint8) - out = numpy.zeros(shape=10, dtype=numpy.int16) + sig = generate_test_tone(duration_sec=0.004, + freqs=[1000.0], noise_level=0.0, sample_rate=sr, amplitude=0.9, + ) + + pdm_data = convert(sig) + + inp = pdm_data # numpy.ones(shape=10, dtype=numpy.uint8) + print(inp.shape, inp.dtype) + print(inp) - galearn_pdm.process(inp, out) + out = numpy.zeros(shape=len(inp)//decimation, dtype=numpy.int16) + + n_samples = galearn_pdm.process(inp, out) + out = out / 1024 + + print(numpy.mean(out)) print(out) - assert out[0] == 2 - assert out[-1] == 2 + + + fig = plot_reconstruct(sig, pdm_data, out, sr=sr, aspect=6.0) + plot_path = 'pdm_verilated_1khz.png' + fig.savefig(plot_path) + + #assert out[0] == 2 + #assert out[-1] == 2 + if __name__ == '__main__': test_one() |