LUT_1D#
Description#
The uz_LUT_1D module provides a 1D look-up table with binary search, linear interpolation and value clamping.
It uses the uz_array_float_t type from Array for breakpoints and data storage.
The breakpoints array must be strictly increasing (no duplicates), have the same length as the data array,
and contain at least two entries.
The data array may take arbitrary values as long as it has the same length as the breakpoints array and at least two entries.
When the input is below the first breakpoint, the first data value is returned. When the input is above the last breakpoint, the last data value is returned. When the input is between two breakpoints, the output is linearly interpolated between the two nearest points.
//Arrays for LUTs
static float LUT_breakpoints_array[6] = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
static float LUT_data_array[6] = {0.0f, 5.0f, 10.0f, 15.0f, 20.0f, 25.0f};
//Create uz_arrays
uz_array_float_t LUT_breakpoints = {
.length = UZ_ARRAY_SIZE(LUT_breakpoints_array),
.data = &LUT_breakpoints_array[0]
};
uz_array_float_t LUT_data = {
.length = UZ_ARRAY_SIZE(LUT_data_array),
.data = &LUT_data_array[0]
};
uz_LUT_1D_t* lut_instance = uz_LUT_1D_init(&LUT_breakpoints, &LUT_data);
float input = 2.5f;
float output = uz_LUT_1D_get_value(lut_instance, input);
The following plot shows the example LUT defined by LUT_breakpoints_array and LUT_data_array.

Fig. 370 Example LUT defined by LUT_breakpoints_array and LUT_data_array approximating \(f(x)\) where \(x\) are the breakpoints. The input \(x=2.5\) is passed to uz_LUT_1D_get_value, which returns \(f(2.5)=12.5\).
Reference#
-
typedef struct uz_LUT_1D_t uz_LUT_1D_t#
-
uz_LUT_1D_t *uz_LUT_1D_init(uz_array_float_t *breakpoints, uz_array_float_t *data)#
Initializes a 1D Look-Up Table (LUT) instance with the provided breakpoints and data.
Preconditions:
breakpoints and data are not NULL
breakpoints and data have the same length
length is at least 2
breakpoints are strictly increasing (no duplicates)
- Parameters:
breakpoints – pointer to uz_array_float_t object for breakpoints for the LUT
data – pointer to uz_array_float_t object for data values corresponding to the breakpoints
- Returns:
uz_LUT_1D_t*
-
float uz_LUT_1D_get_value(uz_LUT_1D_t *self, float input)#
Returns the value from the LUT corresponding to the given input using linear interpolation. If the input is outside the bounds of the breakpoints, it returns the value of the nearest breakpoint.
- Parameters:
self – instance of the LUT_1D
input – value corresponding to the breakpoints
- Returns:
float