[数字信号处理] FIR滤波器基础

  对于一个滤波器而言,其单位冲击响应是有限区间的数列的话,这个滤波器是FIR滤波器。反之,其单位冲击响应是无限区间的数列的话,这个滤波器是IIR滤波器。

   下面使用线性差分方程式,在时域内,解释一下FIR与IIR数字滤波器。使用单位脉冲响应和其输入信号进行卷积运算,可得到下式


   将其改写为递归的方式,则

 

    上式是1次差分方程式,而对于N次数字滤波器的输入输出关系,表示为N次差分方程式,如下所示。

        

     由上式看,输出 y(n) 需要自己的历史值,也就是,含有反馈。

     的时候,反馈有作用,其系统框图如下。


     此时,输入单位脉冲,由于反馈的作用,系统的单位冲击响应是无限的。

     的时候,无反馈作用,其单位冲击响应是有限的,其单位框图如下。

     输入单位脉冲,由于没有反馈的作用,系统的单位冲击响应是有限的。也就是Finite Impulse Response,字面意思。

 接下来,用C实现一个FIR滤波器,这里,系数是随意设置的。

 

#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;
}

到此,一个FIR滤波器就实现了,只需要不停的输入输入信号就好了,ESC键可以停止程序。

其单位冲击响应用Matlab表示如下。

                                                                      

原文地址:https://www.cnblogs.com/javawebsoa/p/3095723.html