Zephyr API Documentation
4.2.0-rc3
A Scalable Open Source RTOS
4.2.0-rc3
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
$
a
b
c
d
f
g
h
i
k
l
m
n
o
p
r
s
t
u
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
interpolation.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 Embeint Inc
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_ZEPHYR_MATH_INTERPOLATION_H_
8
#define ZEPHYR_INCLUDE_ZEPHYR_MATH_INTERPOLATION_H_
9
10
#include <
stdint.h
>
11
#include <
math.h
>
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
16
21
28
44
static
inline
int32_t
linear_interpolate
(
const
int32_t
*x_axis,
const
int32_t
*y_axis,
uint8_t
len,
45
int32_t
x)
46
{
47
float
rise, run, slope;
48
int32_t
x_shifted;
49
uint8_t
idx_low = 0;
50
51
/* Handle out of bounds values */
52
if
(x <= x_axis[0]) {
53
return
y_axis[0];
54
}
else
if
(x >= x_axis[len - 1]) {
55
return
y_axis[len - 1];
56
}
57
58
/* Find the lower x axis bucket */
59
while
(x >= x_axis[idx_low + 1]) {
60
idx_low++;
61
}
62
63
/* Shift input to origin */
64
x_shifted = x - x_axis[idx_low];
65
if
(x_shifted == 0) {
66
return
y_axis[idx_low];
67
}
68
69
/* Local slope */
70
rise = y_axis[idx_low + 1] - y_axis[idx_low];
71
run = x_axis[idx_low + 1] - x_axis[idx_low];
72
slope = rise / run;
73
74
/* Apply slope, undo origin shift and round */
75
return
roundf(y_axis[idx_low] + (slope * x_shifted));
76
}
44
static
inline
int32_t
linear_interpolate
(
const
int32_t
*x_axis,
const
int32_t
*y_axis,
uint8_t
len, {
…
}
77
81
82
#ifdef __cplusplus
83
}
84
#endif
85
86
#endif
/* ZEPHYR_INCLUDE_ZEPHYR_MATH_INTERPOLATION_H_ */
linear_interpolate
static int32_t linear_interpolate(const int32_t *x_axis, const int32_t *y_axis, uint8_t len, int32_t x)
Perform a linear interpolation across an arbitrary curve.
Definition
interpolation.h:44
math.h
stdint.h
int32_t
__INT32_TYPE__ int32_t
Definition
stdint.h:74
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:88
zephyr
math
interpolation.h
Generated on
for Zephyr API Documentation by
1.14.0