MATLAB导出滤波器参数至ADSP中使用

一、matlab设计滤波器

使用filterDesigner命令打开滤波器设计模块

二、运行matlab脚本转换出C可以直接使用的系数

Matlab 复制代码
clc;
BIQUADS = 5; %对应ADI biquad SECTION数量
fp = fopen("lowpass.txt","w");
for i = 1:BIQUADS
    fprintf(fp, '%2.20e,\n', -SOS(i,6));
    fprintf(fp, '%2.20e,\n', -SOS(i,5));
    fprintf(fp, '%2.20e,\n', SOS(i,3)*G(i));
    fprintf(fp, '%2.20e,\n', SOS(i,2)*G(i));
    fprintf(fp, '%2.20e,\n', SOS(i,1)*G(i));
end

三、在C中使用

cpp 复制代码
/*****************************************************************************
 * biquad_test.c
 *****************************************************************************/

#include "adi_initialize.h"
#include "biquad_test.h"

#include <sys/platform.h>

/** 
 * If you want to use command program arguments, then place them in the following string. 
 */
char __argv_string[] = "";


#include <filter.h> //vector_version
#define NSECTIONS  5  //5个biquad级联使用
#define NSAMPLES  7 //数据长度64
#define NSTATE    (2*NSECTIONS) //state数组的长度 2的倍数

float input[NSAMPLES]={1,2,3,4,5,6,7};
float output[NSAMPLES];

float state[NSTATE];

//共25个系数 在数组中的顺序为
//[A2, A1, B2, B1, B0     A2, A1, B2, B1, B0   A2, A1, B2, B1, B0   A2, A1, B2, B1, B0 ...]
//第一个biquad            第二个biquad          第三个biquad          第四个biquad...
float pm coeffs[5*NSECTIONS]={
#include "lowpass.txt"
};

int main(int argc, char *argv[])
{
	int i;

	for (i = 0; i < NSTATE; i++){
		state[i] = 0;     /* initialize state array */
	}

	biquad(input, output, coeffs, state, NSAMPLES, NSECTIONS);  //调用完biquad后state数组不为0


	return 0;
}

四、验证

Matlab 复制代码
x = [1,2,3,4,5,6,7]';

%% 先用sos2tf转换为传递函数,再滤波

[b, a] = sos2tf(SOS, G); % b为分子系数, a为分母系数

y2 = filter(b, a, x);

相关推荐
罗西的思考3 小时前
【轻量化复刻大模型 / KIMI K3】KDA 模块交互式演示
人工智能·算法·机器学习
nm_zfyjt5 小时前
信息流广告投放优化实践:线索成本评估模型与转化链路重构(家装建材案例)
算法·重构·内蒙古朋友圈广告服务商·内蒙古朋友圈获客
w_zero_one6 小时前
算法--构造
java·数据结构·算法
其实防守也摸鱼7 小时前
信创安全竞赛知识总结与题库
大数据·网络·人工智能·算法·安全·php
小超人诞生日记8 小时前
C++ 智能指针的使用及其原理详解
c++·算法
分享资料9 小时前
MATLAB 中分号 (;)的作用
matlab
AiNightVision11 小时前
无人机夜视模块如何选择?——从参数指标到系统集成的完整选型指南
人工智能·算法·计算机视觉·车载系统·无人机·视频·智能硬件
牧羊人.33312 小时前
卷积神经网络之VGG
人工智能·深度学习·神经网络·算法·cnn
小郎君65812 小时前
Vue 多标签页的加载态设计:为什么我没有用 Suspense 实现 PageLoading
vue.js·算法