|
之前學(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ò)誤,可能重啟一下軟件就好了。
源程序如下:
- /*
- * main.c
- */
- #include "math.h"
- #include "stdio.h"
- #include <stdint.h>
- #include "stdlib.h"
- #include "string.h"
- #include "limits.h"
- //#include"fdacoefsiir900.h"
- //#include "fdacoefsiir600.h"
- //#include "fdacoefsiir50+900.h"
- //#include "fdacoefsiir50.h"
- #include "fdacoefs50001.h"
- #define length 2048
- #define pi 3.1415926
- long fs=10000;
- int f1=50;
- int f2=200;
- int f3=600;
- int f4=900;
- #define w1 2*pi*f1/fs
- #define w2 2*pi*f2/fs
- #define w3 2*pi*f3/fs
- #define w4 2*pi*f4/fs
- double input[length];
- double output[length];
- static double xlast[2];
- static double mlast[2];
- static double IIR_DR2(double x,double *plast,const double (*A)[3],const double (*B)[3])
- {
- double tmp,last;
- tmp = x*B[0][0];
- last = tmp - (A[1][1]*plast[0] + A[1][2]*plast[1]);
- tmp = last + (B[1][1] * plast[0] + B[1][2]*plast[1]);
- plast[1] = plast[0];
- plast[0] = last;
- return tmp;
- }
- double IIR_Filter(double x)
- {
- double mid,y;
- mid = IIR_DR2(x,xlast,DEN,NUM);
- y = IIR_DR2(mid,mlast,&DEN[2],&NUM[2]);//二階濾波器組合成更高階數(shù)的濾波器
- //更多階數(shù)...
- return y;
- }
- void Init_Filter(void)//初始化中間數(shù)值
- {
- xlast[0] = 0;
- xlast[1] = 0;
- mlast[0] = 0;
- mlast[1] = 0;
- }
- int main(void)
- {
- unsigned int i,n;
- Init_Filter();
- for(i=0;i<length;i++)
- {
- input[i]=2048*sin(w1*i)+2048*sin(w2*i)+2048*sin(w3*i)+2048*sin(w4*i);
- }
- for(n=0;n<length;n++)
- {
- output[n]=IIR_Filter(input[n]);
- }
- for(;;);
- }
復(fù)制代碼
所有資料51hei提供下載:
7.zip
(101.16 KB, 下載次數(shù): 50)
2020-6-24 09:34 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|