找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4340|回復(fù): 1
收起左側(cè)

MATLAB聯(lián)合ccs做數(shù)字濾波器程序設(shè)計(jì),適合純小白

[復(fù)制鏈接]
ID:788395 發(fā)表于 2020-6-24 09:34 | 顯示全部樓層 |閱讀模式
之前學(xué)習(xí)的內(nèi)容,因?yàn)闆](méi)有開(kāi)發(fā)板,所以只能ccs聯(lián)合MATLAB一起做數(shù)字濾波器的設(shè)計(jì)。這個(gè)對(duì)于剛剛接觸的新手還是非常有難度的,像我就熬了一個(gè)通宵才做出來(lái),當(dāng)然還是有點(diǎn)菜。詳細(xì)的程序都在安裝包里?梢詤⒖。而且ccs這個(gè)軟件有點(diǎn)迷,有時(shí)候沒(méi)有圖或者一些錯(cuò)誤,可能重啟一下軟件就好了。
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]);//二階濾波器組合成更高階數(shù)的濾波器

  45.         //更多階數(shù)...

  46.         return y;
  47. }
  48. void Init_Filter(void)//初始化中間數(shù)值
  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. }

復(fù)制代碼

所有資料51hei提供下載:
7.zip (101.16 KB, 下載次數(shù): 50)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

ID:943095 發(fā)表于 2023-9-19 10:35 | 顯示全部樓層
你好加個(gè)好友交流一下可以嗎?
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表