First, the output formula of the FIR filter is:
(If you can see the digital signal processing books, it's almost forgotten ...) )
Assumption: The input signal is x (n) = sin (2*pi*f1*n/fs) + sin (2*pi*f2*n/fs)
The filter designed is a low-pass FIR filter using the Hamming window with a order of 10
You can use the Filter design tool in MATLAB to design the filter:
You can then create a C header file to obtain the desired value by designing the filter:
The C program of the FIR filter is as follows:
#include <stdio.h> #include <math.h> #define PI 3.1415#define N //n is the order of the filter +1#define LEN 512int Inputdata[len]; Assume that the length of the data is 512int outputdata[len];long int yn; Yn is int, the data in the operation may overflow, thus filtering fails const int B[n] = {166, 0, -1374, 0, 9453, 16279, 9453, 0, -1374, 0, 166} //fir filter parameters, Generated by Matlab
void Main () {int f1,f2,fs,i,j; int *a; f1=100; Frequency component 1 (Hz) f2=300; Frequency component 2 (Hz) fs=800; Sampling frequency (Hz) for (i=0;n<len;n++) { Inputdata[n]=sin (2*pi*f1*n/fs) + sin (2*pi*f2*n/fs); Generate Signal }for (j=0;j<len;j++) //Filter by Formula {a=&inputdata[j];yn=0; for (i=0;i<n;i++) { yn=yn+b[i]* (*a++); }outputdata[j]=yn>>16; Signal}while after filtering (1);}
Run in a CCS environment and see the time and frequency domain graphs of inputdata and outputdata by graph (not here, tested in the school's experimental class ...) )
Its cmd file is:
-e startmemory { page 0: PARAM: org = 3000h len = 4000h PAGE 1: daram: org = 100h len=4000h } sections{ . Text : > PARAM PAGE 0 stack : > daram Page 1 filter_vars: > daram page 1 . BSS : > daram page 1 . Data : > Daram PAGE 1 }
Realization of FIR filter based on DSP C language