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

Usage

# From the root of the repository
pip install .
# Generate LUTs with cubic splines fit for every configuration toml in the given paths.
clutgen -s -i ./examples/calibration/*.toml ./examples/temperature_copy.toml

YAML 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.
interpolation = "polynomial" # Optional, forces a given interpolation method to 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.1.tar.gz (11.6 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.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clutgen-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 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.1.tar.gz
Algorithm Hash digest
SHA256 013b90f30ccc6a6836277cf67fda0174d97f8f723da767ed0aee306d1ea8a9d3
MD5 8b68f184ab514407b7a876f64273e628
BLAKE2b-256 2fead57b677c079ad50e7dad1c4316425e029b31087067fac4248bdfd25217b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clutgen-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b406b25f44a22e2f5548f8c01f1fb94ce0a189c2d7569b1249801f3dc7863925
MD5 e287c6e2d100230849abf38ad0066183
BLAKE2b-256 86b1d2921977d25d120e8b7efbd94aaaa93c002da0c079ca46d2a847435e11b5

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