Skip to content

Trace cleanup#2518

Merged
iceman1001 merged 2 commits intoRfidResearchGroup:masterfrom
henrygab:TraceCleanup
Sep 17, 2024
Merged

Trace cleanup#2518
iceman1001 merged 2 commits intoRfidResearchGroup:masterfrom
henrygab:TraceCleanup

Conversation

@henrygab
Copy link
Contributor

Some of the .pm3 sample traces failed to cleanly convert to one-byte-per-sample binary files.

For five of the files, the values spanned 256 values, but were not in the range [-128 .. 127]. These files were read, and each sample was offset by the corresponding amount.

For the file lf_Keri.pm3, the samples were in the range [-508 .. 491] (1000 value range). For this file, each sample was divided by four and then adjusted by +1 (to center the values). The data plot in the pm3 client now shows discernible changes in amplitude.

With this PR, all the .pm3 files now store single-byte values for each sample in the range [-128,127]. This simplifies conversion to other formats (including binary).

All changes were done programmatically. The python function of note was:

Python function used

def scale_file_values_to_byte_range(infile: Path, outfile: Path, smallestValue: int, largestValue: int):

    range = largestValue - smallestValue + 1
    print(f"Adjusting file {infile} to byte range, was [{smallestValue}..{largestValue}] / {range}")

    # Probably could map the integer ranges, but only one file needed this,
    # and it was using a range of 1000 values, which is really close to 1024,
    # so ... good enough
    divisor = 1
    while range > 256:
        range /= 2
        divisor *= 2
        largestValue /= 2
        smallestValue /= 2

    offset = int(127 - largestValue)
    if range < 256:
        offset -= int((256-range)/2)

    print(f"Dividing by {divisor}, then offsetting by {offset} for file {infile} --> {outfile}")

    with outfile.open(mode="wt", encoding=None) as out:
        for line in infile.open():
            i = int(line.rstrip())
            i = int(i + offset)
            i = int(i / divisor)
            out.write(f"{i}\n")

This was done programmatically using python.
Files with a range that fell outside of [-128,127], but which would fit into that range, were offset by the noted amount to ensure the file woul now fit within range [-128,127].  This allows the trace files to be converted to one-byte-per-sample binary format, for example.

offset | filename
-----|-----
`-14` | `lf_Q5_mod-manchester.pm3`
`-14` | `lf_Q5_mod-nrz.pm3`
`-10` | `lf_Q5_mod-fsk1.pm3`
`-15` | `lf_Q5_mod-biphase.pm3`
`-9` | `lf_Q5_mod-fsk2.pm3`
This was done programmatically using python.

The `lf_Keri.pm3` was in range `[-508 .. 491]` (1000 value range).
Each value was divided by four, cast to integer, and then adjusted by +1 (to center the values).
The data plot in the pm3 client now shows discernible changes in amplitude.
The resulting samples are all within range [-128,127].

This final fix allows ALL sample `.pm3` traces to be converted to one-byte-per-sample binary format.
@github-actions
Copy link

You are welcome to add an entry to the CHANGELOG.md as well

@iceman1001 iceman1001 merged commit 1b2987c into RfidResearchGroup:master Sep 17, 2024
@henrygab henrygab deleted the TraceCleanup branch September 17, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants