summaryrefslogtreecommitdiff
path: root/bindings/test_galearn_pdm.py
blob: b0fda964a394d2ff08c5b17109942b98c8332235 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

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():
    
    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)

    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)


    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()