嵌入式算法:STM32 F4xx 使用DSP实现cubic spline插值算法

参考官方文档:

Linear Interpolate Example

Cubic Spline Interpolation

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);
}

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KPer_Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值