Add test data and working manchester decoder

This commit is contained in:
jaseg 2024-06-23 23:13:34 +02:00
parent 8c5c8aee51
commit 66e0f462d3
19 changed files with 2692 additions and 4 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.wfm
__pycache__
.ipynb_checkpoints

View file

@ -53,6 +53,12 @@
"\n",
"downsampling = 500\n",
"data = scipy.signal.decimate(data, downsampling, ftype='fir')\n",
"off = 6000#wf = rigol.Wfm.from_file('barcode_test_varspeed.wfm', 'DS1054Z')\n",
"wf = rigol.Wfm.from_file('barcode_test8.wfm', 'DS1054Z')\n",
"data = wf.channels[0].volts\n",
"\n",
"downsampling = 500\n",
"data = scipy.signal.decimate(data, downsampling, ftype='fir')\n",
"off = 6000\n",
"data = data[off:off+16384]\n",
"td = wf.channels[0].seconds_per_point * downsampling\n",
@ -61,6 +67,14 @@
"fig, ax = plt.subplots(figsize=(28, 6))\n",
"ax.plot(times, data)\n",
"ax.set_xlim([times[0], times[-1]])\n",
"len(data)\n",
"data = data[off:off+16384]\n",
"td = wf.channels[0].seconds_per_point * downsampling\n",
"times = np.linspace(0, len(data)*td, len(data))\n",
"\n",
"fig, ax = plt.subplots(figsize=(28, 6))\n",
"ax.plot(times, data)\n",
"ax.set_xlim([times[0], times[-1]])\n",
"len(data)"
]
},
@ -729,7 +743,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.12.3"
}
},
"nbformat": 4,

917
barcode4.ipynb Normal file

File diff suppressed because one or more lines are too long

686
barcode5.ipynb Normal file

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@ import itertools
import textwrap
import click
from reedmuller import reedmuller
from reedmuller.reedmuller import ReedMuller
class Tag:
@ -81,15 +81,19 @@ class Tag:
@click.argument('outfile', type=click.File('w'), default='-')
def cli(data, outfile, height, text, font, font_size, bar_width, margin, color, text_color, dpi):
data = int(data, 16)
data &= 0x3ffffff
text_color = text_color or color
NUM_BITS = 26
rm = ReedMuller(3, 5)
data_bits = [bool(data & (1<<i)) for i in range(NUM_BITS)]
data_bits = [bool(data & (1<<i)) for i in range(rm.message_length())]
data_bits = rm.encode(data_bits)
print('Payload bits:', ''.join([str(int(x)) for x in data_bits]))
data_encoded = itertools.chain(*[
(a, not a) for a in data_bits
])
data_encoded = [True, False, True, False, *data_encoded, False, True, True, False, True]
print('Encoded data:', ''.join([str(int(x)) for x in data_encoded]))
width = len(data_encoded) * bar_width
# 1 px = 0.75 pt

29
downsample_rigol_wfm.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import json
from pathlib import Path
import lzma
import click
import RigolWFM.wfm as rigol
import scipy
@click.command()
@click.argument('infile', type=click.Path(dir_okay=False, exists=True))
@click.argument('outfile', type=click.Path(dir_okay=False, path_type=Path), required=False)
@click.option('-f', '--factor', type=int, default=500, help='Downsampling factor')
def cli(infile, outfile, factor):
if outfile is None:
outfile = Path(infile).with_suffix('.lzjson')
wf = rigol.Wfm.from_file(infile, 'DS1054Z')
data = wf.channels[0].volts
data = scipy.signal.decimate(data, factor, ftype='fir')[::-1]
td = wf.channels[0].seconds_per_point * factor
outfile.write_bytes(lzma.compress(json.dumps({'sample_interval_s': td, 'samples': list(data)}).encode()))
if __name__ == '__main__':
cli()

File diff suppressed because it is too large Load diff

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.