For a filter whose unit impact response is a series of finite intervals, this filter is a FIR filter. If the unit impact response is a series of infinite intervals, this filter is an IIR filter.
The linear difference equation is used below. In the time domain, we will explain the relationship between the FIR and the iir digital filter. The Unit pulse response and its input signal are used for convolution. The following formula is obtained:
If it is rewritten as a recursive method
The formula above is a difference equation, and the input and output relations of N digital filters are represented as n difference equations, as shown below.
From the above perspective, output y (n) requires its own historical value, that is, containing feedback.
The system diagram is as follows.
In this case, the Unit impact response of the system is infinite due to the feedback of the input unit pulse.
When there is no feedback, the Unit impact response is limited. The unit diagram is as follows.
The Unit impact response of the system is limited because there is no feedback for the input unit pulse. That is, finite impulse response.
Next, use C to implement an FIR filter. Here, the coefficients are set at will.
#include <stdio.h>#include <math.h>#include <malloc.h>#include <string.h>double Real_Time_FIR_Filter(double *b, int b_Lenth, double *Input_Data){ int Count; double Output_Data = 0; Input_Data += b_Lenth - 1; for(Count = 0; Count < b_Lenth ;Count++) { Output_Data += (*(b + Count)) * (*(Input_Data - Count)); } return (double)Output_Data;}void Save_Input_Date (double Scand, int Depth, double *Input_Data){ int Count; for(Count = 0 ; Count < Depth-1 ; Count++) { *(Input_Data + Count) = *(Input_Data + Count + 1); } *(Input_Data + Depth-1) = Scand;}int main(void){ double b[] = {0.5 , -0.5 , 1}; double Scand_Data = 0; char Command = 0; int b_Lenth = (sizeof(b)/sizeof(double)); int Count = 0; double Input_Data[sizeof(b)/sizeof(double)] = {0}; double Output_Data = 0; /*--------------------display----------------------------*/ printf(" b(k) : "); for(Count = 0; Count < b_Lenth ;Count++) { printf("%f " , b[Count]); } printf("\n"); /*-----------------------------------------------------*/ Count = 0; while(1) { if(Count == 0) printf("The Input : "); else printf("The Next Input : "); scanf("%lf",&Scand_Data); printf("Input x(%d) : %lf ",Count,Scand_Data); Save_Input_Date (Scand_Data, b_Lenth, Input_Data); Output_Data = Real_Time_FIR_Filter(b, b_Lenth, Input_Data); printf("Output y(%d) : %lf \n",Count,Output_Data); scanf("%c",&Command); if(Command == 27) break; //ESC Count++; } printf("\n"); return (int)0;}
At this point, a FIR filter is implemented. You only need to enter the input signal continuously. The ESC key can stop the program.
The unit of impact response is shown in Matlab as follows.