Skip to content

Commit 8bb9ef5

Browse files
committed
✨ feat(interpolation): 增加插值算法
未通过测试
1 parent ac5e973 commit 8bb9ef5

File tree

6 files changed

+672
-1
lines changed

6 files changed

+672
-1
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# clang-format -style=llvm -dump-config > .clang-format
66
#
77
---
8-
Language: C
98
BasedOnStyle: LLVM
109
AccessModifierOffset: -1
1110
AlignAfterOpenBracket: Align

docs/interpolation.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
## 插值算法介绍
2+
3+
### 1. **线性插值(Linear Interpolation)**
4+
- **原理**:在两个已知数据点之间用直线连接,估算中间点的值。
5+
- **公式**
6+
\[
7+
y = y_1 + \frac{(x - x_1)}{(x_2 - x_1)} \cdot (y_2 - y_1)
8+
\]
9+
- **优点**:计算简单,适合资源受限的嵌入式系统。
10+
- **缺点**:精度较低,尤其是在非线性数据中。
11+
- **应用场景**
12+
- 传感器数据平滑处理。
13+
- 简单的信号处理。
14+
15+
---
16+
17+
### 2. **双线性插值(Bilinear Interpolation)**
18+
- **原理**:在两个方向上进行线性插值,常用于二维数据(如图像处理)。
19+
- **优点**:比线性插值精度更高。
20+
- **缺点**:计算量较大。
21+
- **应用场景**
22+
- 图像缩放。
23+
- 二维传感器数据处理。
24+
25+
---
26+
27+
### 3. **多项式插值(Polynomial Interpolation)**
28+
- **原理**:通过已知数据点构造一个多项式函数,估算未知点。
29+
- **常见方法**:拉格朗日插值、牛顿插值。
30+
- **优点**:精度较高。
31+
- **缺点**:计算复杂度高,可能产生“龙格现象”(Runge's phenomenon)。
32+
- **应用场景**
33+
- 高精度传感器数据处理。
34+
- 复杂信号处理。
35+
36+
---
37+
38+
### 4. **样条插值(Spline Interpolation)**
39+
- **原理**:用分段多项式(通常是三次样条)拟合数据点,保证插值函数的光滑性。
40+
- **优点**:精度高,曲线平滑。
41+
- **缺点**:计算复杂度较高。
42+
- **应用场景**
43+
- 高精度运动控制。
44+
- 复杂信号处理。
45+
46+
---
47+
48+
### 5. **查表法(Look-Up Table, LUT)**
49+
- **原理**:预先计算并存储插值结果,运行时通过查表获取近似值。
50+
- **优点**:速度快,适合实时性要求高的场景。
51+
- **缺点**:需要额外的存储空间,精度受表大小限制。
52+
- **应用场景**
53+
- 实时信号处理。
54+
- 传感器校准。
55+
56+
---
57+
58+
### 6. **分段插值(Piecewise Interpolation)**
59+
- **原理**:将数据分成多个区间,每个区间使用简单的插值方法(如线性插值)。
60+
- **优点**:平衡了计算复杂度和精度。
61+
- **缺点**:需要合理划分区间。
62+
- **应用场景**
63+
- 实时数据处理。
64+
- 资源受限的嵌入式系统。
65+
66+
---
67+
68+
### 7. **最近邻插值(Nearest Neighbor Interpolation)**
69+
- **原理**:直接使用最近的已知数据点作为估算值。
70+
- **优点**:计算简单,速度快。
71+
- **缺点**:精度低,可能产生锯齿现象。
72+
- **应用场景**
73+
- 实时性要求高但精度要求低的场景。
74+
- 简单的图像处理。
75+
76+
---
77+
78+
### 选择插值算法的考虑因素:
79+
1. **精度要求**:高精度场景选择样条插值或多项式插值,低精度场景选择线性插值或查表法。
80+
2. **计算资源**:资源受限的系统选择简单的插值方法(如线性插值或查表法)。
81+
3. **实时性**:实时性要求高的场景选择查表法或最近邻插值。
82+
4. **数据特性**:线性数据适合线性插值,非线性数据适合多项式插值或样条插值。
83+
84+
---
85+
86+
通过合理选择插值算法,可以在嵌入式系统中实现高效、精确的数据处理。

src/algorithm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
#include "algorithms/search.h"
99
#include "algorithms/array_utils.h"
1010
#include "algorithms/kalman_filter.h"
11+
#include "algorithms/interpolation.h"
1112
#endif // ALGORITHM_MODULE_H

0 commit comments

Comments
 (0)