找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3358|回复: 1
收起左侧

MATLAB联合ccs做数字滤波器程序设计,适合纯小白

[复制链接]
ID:788395 发表于 2020-6-24 09:34 | 显示全部楼层 |阅读模式
之前学习的内容,因为没有开发板,所以只能ccs联合MATLAB一起做数字滤波器的设计。这个对于刚刚接触的新手还是非常有难度的,像我就熬了一个通宵才做出来,当然还是有点菜。详细的程序都在安装包里。可以参考。而且ccs这个软件有点迷,有时候没有图或者一些错误,可能重启一下软件就好了。
51hei.png

源程序如下:
  1. /*
  2. * main.c
  3. */

  4. #include "math.h"
  5. #include "stdio.h"
  6. #include <stdint.h>
  7. #include "stdlib.h"
  8. #include "string.h"
  9. #include "limits.h"
  10. //#include"fdacoefsiir900.h"
  11. //#include "fdacoefsiir600.h"
  12. //#include "fdacoefsiir50+900.h"
  13. //#include "fdacoefsiir50.h"
  14. #include "fdacoefs50001.h"

  15. #define length 2048
  16. #define pi 3.1415926

  17. long fs=10000;
  18. int f1=50;
  19. int f2=200;
  20. int f3=600;
  21. int f4=900;

  22. #define w1 2*pi*f1/fs
  23. #define w2 2*pi*f2/fs
  24. #define w3 2*pi*f3/fs
  25. #define w4 2*pi*f4/fs

  26. double input[length];
  27. double output[length];

  28. static double xlast[2];
  29. static double mlast[2];

  30. static double IIR_DR2(double x,double *plast,const double (*A)[3],const double (*B)[3])
  31. {
  32.         double tmp,last;

  33.         tmp = x*B[0][0];

  34.         last = tmp - (A[1][1]*plast[0] + A[1][2]*plast[1]);
  35.         tmp = last + (B[1][1] * plast[0] + B[1][2]*plast[1]);

  36.         plast[1] = plast[0];
  37.         plast[0] = last;

  38.         return tmp;
  39. }
  40. double IIR_Filter(double x)
  41. {
  42.         double mid,y;

  43.         mid = IIR_DR2(x,xlast,DEN,NUM);

  44.         y   = IIR_DR2(mid,mlast,&DEN[2],&NUM[2]);//二阶滤波器组合成更高阶数的滤波器

  45.         //更多阶数...

  46.         return y;
  47. }
  48. void Init_Filter(void)//初始化中间数值
  49. {
  50.         xlast[0] = 0;
  51.         xlast[1] = 0;
  52.         mlast[0] = 0;
  53.         mlast[1] = 0;
  54. }

  55. int main(void)
  56. {
  57. unsigned int i,n;

  58. Init_Filter();

  59. for(i=0;i<length;i++)
  60. {

  61.         input[i]=2048*sin(w1*i)+2048*sin(w2*i)+2048*sin(w3*i)+2048*sin(w4*i);
  62. }


  63. for(n=0;n<length;n++)
  64. {
  65.         output[n]=IIR_Filter(input[n]);


  66. }


  67. for(;;);
  68. }

复制代码

所有资料51hei提供下载:
7.zip (101.16 KB, 下载次数: 48)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:943095 发表于 2023-9-19 10:35 | 显示全部楼层
你好加个好友交流一下可以吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表