嵌入式算法:STM32 F4xx 使用DSP实现cubic spline插值算法
嵌入式算法:STM32 F4xx 使用DSP实现cubic spline插值
参考官方文档:
cubic spline的基本概念:
定义:Spline interpolation is a method of interpolation where the interpolant is a piecewise-defined polynomial called "spline"
计算过程:A is a tridiagonal matrix (a band matrix of bandwidth 3) of size N=n+1. The factorization algorithms (A=LU) can be simplified considerably because a large number of zeros appear in regular patterns. The Crout method has been used: 1) Solve LZ=B
计算已知点两端范围外的点:It is possible to compute the interpolated vector for x values outside the input range (xq<x(1); xq>x(n)). The coefficients used to compute the y values for xq<x(1) are going to be the ones used for the first interval, while for xq>x(n) the coefficients used for the last interval.
接口说明(Version 1.10.0):
1、使用接口一定要注意数组的大小;
2、x 输入数组必须严格按升序排序,并且不能包含两次相同的值: (x(i)<x(i+1))。
//初始化实例函数
void arm_spline_init_f32(
arm_spline_instance_f32 *S,
arm_spline_type type,
const float32_t *x,
const float32_t *y,
uint32_t n,
float32_t *coeffs,
float32_t *tempBuffer )
/*
[in,out] S 指向浮点样条结构的一个实例。
[in] type 三次样条插值类型(边界条件)
[in] x 指向已知数据点的 x 值。
[in] y 指向已知数据点的 y 值。
[in] n 个已知数据点。
[in] coeffs b、c 和 d 的系数数组:注意大小是3*(n-1),其中的n是已知的点数
[in] tempBuffer 用于内部计算的 tempBuffer 缓冲区数组,注意大小是n+n-1,其中的n是已知的点数
*/
//运行cubic spline函数
void arm_spline_f32 (
arm_spline_instance_f32 *S,
const float32_t *xq,
float32_t *pDst,
uint32_t blockSize )
/*
[in] S 指向浮点样条结构的一个实例。
[in] xq 指向插值数据点的x值。
[out] pDst 指向输出数据块。
[in] blockSize 输出数据的样本数。
*/
cubic spline 的DSP代码实现(Version 1.10.0):
#include "arm_math.h"
#include "math_helper.h"
#define DATA_LEN 1024 //数据长度
int main(void)
{
arm_spline_instance_f32 spline_instance;
arm_spline_type type = 0;
float data[512];
float data_out[1024];
uint32_t n = 512;
float coeffs[3*(n-1)];
float temp_buffer[n+n-1];
arm_spline_init_f32(&spline_instance, type , data, data_out, n, coeffs, temp_buffer);
arm_spline_f32(&spline_instance, t, data, data_out, DATA_LEN);
}
更多推荐
所有评论(0)