Skip to main content

CLUTGen, a flexible ADC LUT generator for embedded systems.

Project description

CLUTGen

CLUTGen automates the creation of Look-Up Tables for embedded systems, converting raw ADC readings into calibrated physical units such as temperature, pressure, or distance.

Given a set of calibration samples, CLUTGen fits an interpolation curve and generates a production-ready .c/.h pair with the full LUT precomputed for every possible ADC reading.

For Zephyr west module usage, see the zephyr branch.


Requirements

  • Python 3.10+
  • numpy, matplotlib

Installation

From PyPI:

pip install clutgen

From source:

pip install .

Usage

clutgen [OPTIONS] input_files...
Argument Description
input_files One or more .toml configuration files
-o, --output-dir Output directory for generated files (default: ./clutgenerated)
-n, --name Base name for the generated .c/.h files (default: lookup_tables)
--preview Open an interactive matplotlib plot after generation

Interpolation method (mutually exclusive, default: --linear):

Flag Method
-l, --linear Linear interpolation
-s, --splines Cubic spline interpolation
-p, --polynomial Best-fit polynomial up to degree 7
-w, --piecewise Zero-order hold (step-like)
-d, --idw Inverse Distance Weighting

Examples:

# Generate with default linear interpolation
clutgen ./calibration/temperature.toml

# Generate with splines and open preview
clutgen --splines --preview ./calibration/temperature.toml ./calibration/pressure.toml

# Custom output directory and file name
clutgen -o ./src/generated -n sensor_luts ./calibration/temperature.toml

TOML Configuration

Each sensor requires a TOML configuration file and a CSV with its calibration samples.

CSV schema:

raw,calibration

Where raw is the ADC reading and calibration is the expected output value at that reading.

TOML schema:

name = "temp_sensor"                # C identifier — used as <n>_lut in generated code
description = "ambient temperature" # Used in Doxygen comments and plot titles
table_resolution_bits = 12          # ADC resolution in bits (e.g., 12 → 4096 entries)
lut_type = "int16_t"                # C type for the generated array

samples_csv = "./data/temperature_samples.csv"  # Relative to this file, or absolute

# Optional
interpolation = "polynomial"        # Overrides the CLI interpolation method for this LUT
preview = true                      # Overrides the CLI --preview flag for this LUT

Interpolation Methods

Value Description
linear Linear interpolation between calibration points. Default.
splines Cubic spline interpolation; smooth transitions between points.
polynomial Best-fit polynomial up to degree 7; prone to oscillation with sparse data.
piecewise Zero-order hold; constant value between points, step-like output.
idw Inverse Distance Weighting; weighted average of all known points.

Output

For each run, CLUTGen produces two files:

  • <name>.h — extern declarations with Doxygen comments, safe to include anywhere in the project
  • <name>.c — full LUT definitions, compiled once and linked

Each configured sensor produces an array named <n>_lut, where n is the name field from the TOML:

#include "lookup_tables.h"

int val = temp_sensor_lut[adc_reading];

If --preview is set (or preview = true in a TOML), an additional preview/ subdirectory is created inside the output directory containing a .png plot for each sensor.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clutgen-0.1.5.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clutgen-0.1.5-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file clutgen-0.1.5.tar.gz.

File metadata

  • Download URL: clutgen-0.1.5.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for clutgen-0.1.5.tar.gz
Algorithm Hash digest
SHA256 41654ba1392127f7896768daff3c3c14b6c97a00b530e859ce69f692e5579c2d
MD5 cc451c39f736fa414924d4ee410b86ee
BLAKE2b-256 78ad9429e424c3f26cb21d15e51f371fbb3972b71db68e59bd4f193330033aa4

See more details on using hashes here.

File details

Details for the file clutgen-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: clutgen-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for clutgen-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 966298062bc7f95f8eab737175ff01a86d1d19c5b2296898094cd61012f076b7
MD5 e10fcb303aaac0d9e4dc1344f0685e54
BLAKE2b-256 0f93224331fe88ea7c3f1d34dfb6bdfb5000bcb219197950bbeb8bdbd57d72d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page