Skip to main content

CLUTGen, a flexible ADC LUT generator for embedded systems.

Project description


C Lookup Table (LUT) Generator

CLUTGen automates the creation of Look-Up Tables for embedded systems, specifically for converting raw ADC (Analog-to-Digital Converter) readings into calibrated physical units (like temperature, pressure, or distance).

Features

  • Curve Fitting: Automatically find your fit from many algorithms.
    • Linear Interpolation
    • Cubic Splines
    • Polynomial Interpolation (up to 7th degree)
    • Piecewise Interpolation
    • Inverse Distance Weighting
  • Visual Preview: Generates plots to compare calibration data against the calculated LUT.
  • C Code Generation: Outputs production-ready .c and .h files with Doxygen-style comments.

Requirements

  • Python 3.10+
  • numpy, matplotlib

Installation

CLUTGen is available on PyPI! To install it on your project, just run:

# On your virtual environment
pip install clutgen

Or, if you want to build it yourself, from the root of this repository:

# On your virtual environment
pip install .

Usage

# Generate preview and LUTs with cubic splines fit for every configuration TOML in the given paths.
clutgen -sv ./examples/calibration/temperature.toml ./examples/temperature_copy.toml

TOML Configuration Template

Create a CSV file mapping your POIs with the given schema, where raw is the measured ADC raw value, and calibration is the desired output for the LUT at that given raw value:

raw,calibration

With your table done, create a configuration TOML, e.g.:

# temperature.toml

name = "temp_sensor"                  # Used for variable names (e.g., temp_sensor_lut)
description = "ambient temperature"   # Used for documentation and plot titles
table_resolution_bits = 12            # Resolution (e.g., 12 bits = 4096 entries)
lut_type = "int16_t"                  # C type (int8_t, uint16_t, etc.)
 
samples_csv = "./data/temperature_samples.csv" # Path to CSV/Excel with 'raw' and 'calibration' columns. Path is global or relative to this file.

# Optionals
interpolation = "polynomial"  # Forces a given interpolation method for this LUT.
preview = true                # Enforce/stop preview generation for this LUT.

Currently available interpolation methods are:

Interpolation Argument Description
linear Connects points with straight lines; assumes a constant slope between data points.
splines Uses smooth, low-degree curves (like cubics) to join points without sharp transitions.
polynomial Fits a single high-degree equation to the data; good for global trends but prone to oscillations.
piecewise Functions as a zero-order hold (ZOH); it holds the value of a point constant until the next one is reached, resulting in a step-like sequence.
idw Inverse Distance Weighting; calculates unknown values based on the weighted average of nearby known points.

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.3.tar.gz (11.9 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.3-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clutgen-0.1.3.tar.gz
  • Upload date:
  • Size: 11.9 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.3.tar.gz
Algorithm Hash digest
SHA256 8ea64ee62253c115e6ed38acefb4083400d1ca9a229fb7b07b29d0d5a954815a
MD5 f7672576ab4901e8b27e2e89ec79afec
BLAKE2b-256 5bf6b77a29f53be4a4a579c436276a1943111cf4eb330c16ac0b1c9d863b7676

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clutgen-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f294e7cd290babbfad41d274e1d829a59fa25393d4ad94323cf6ae1d78fbeb96
MD5 ce8a5adb079927660e4383b63096827f
BLAKE2b-256 087b55f3aaff12a000ca12d26e75863eaa62246507bb0365668a2f073c0e68b4

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