Implementation of DSP filter program C language

Source: Internet
Author: User

After the design of digital signal Filter by MATLAB, we should put the designed parameters into the embedded system for filtering.

IIR Filter

FIR Filter

#include <stdio.h> #include <malloc.h>//z transform into difference equation and iterate//talen @UESTC 2015.6.5//print array void print (float *x,int len);//Take the first 1-n float* aminusone (float* a,int ar);//differential Intermediate value float Gtcet (float *t,float *x,int xr,int s,int D);//main filter function float* Gfilter (float *b,int br,float *a,int ar,float *x,int xr), void print (float *x,int len) {for (int i=0;i<len;i++) {printf (" %9.3f ", x[i]); if ((i%7) ==6) printf (" \ n ");} printf ("\ n");} float* aminusone (float* a,int ar) {float* am = (float *) malloc ((ar-1) * sizeof (float)); for (int i=0;i<ar-1;i++) am[i]=a[ I+1];return am;} Float Gtcet (float *t,float *x,int xr,int s,int D)//x[] Data source R data source length s start point (0 start) d data length//t can be a[] b[] length as D {float sum=0;float* W = (float *) malloc (d * sizeof (float)); for (int i=0;i<d;i++) {int temp=s-i;if (TEMP&GT;=0&AMP;&AMP;TEMP&LT;XR) w[i]=x[ temp];elsew[i]=0;//Core statement sum=sum+w[i]*t[i];} return sum;} float* gfilter (float *b,int br,float *a,int ar,float *x,int XR)//b A x br b length of ar a length XR data length//use This program defines GTCET () and Aminusone ( )//input data, b,a,x to obtain the filtered y{float* y = (float *) malloc (xr* sizeof (float)), for (int ti=0;ti<xr;ti++) y[ti]=0;for (int i=0;i<xr;i++) {//core statement, here iterate Y[i]=gtcet (b,x , XR,I,BR)-gtcet (Aminusone (A,ar), y,xr,i-1,ar-1);} return y;} int main () {//input source data can be modified////////////////////////////////////////////////////////////////float x[120]={-4, 2, 0, 4  ,-6,-4,-2,-4,-6,-6,-4, -4,-6,-6,-2, 6, 12, 8, 0,-16,-38,-60, -84,-90,-66,-32, 4, 2, 4, 6, 4, 0, 0, 0, 0, 0,-2,-4, 0, 0, 0, -2,-2, 0, 0,-2,-2,-2,-2, 0,-2,-4,-2, 0,-2,-4,-4, 2, 0, 0, 2, 4, 2  , -2,-4,-2, 0, 0,-4,-4,-2,-2,-4,-6, -6,-4, 4, 8,-10,-8,-6,-6, -10,-8,-8,-12, 8,-10, 12, -10,-8,-6,-6,-8,-8,-4,-2,-4,-4, -4,0, 0,-2,-4,-2,-2, 0, -4};//parameter float b[7]={0.0007,0.0044,0.0111,0.0148,0.01 11,0.0044,0.0007};float a[7]={1.0000,-3.1836,4.6222,-3.7795,1.8136,-0.4800,0.0544};//////////////////////////// Do not modify int xr=sizeof (x)/sizeof (float), int br=sizeof (b)/sizeof (float); int ar=sizeof (a)/sizeof (float),//output filtered data float *y;printf ("parameter b:\n");p rint (B,BR);p rintf ("parameter a:\n");p rint (a,ar);p rintf ("Original data: \ n");p rint (X,XR), Y=gfilter (B,BR,A,AR,X,XR);p rintf ("Filtered data: \ n");p rint (Y,XR); GetChar (); return 0;}

  

Implementation of DSP filter program C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.