emeter_filters.c

来自「TI三相电能表源程序」· C语言 代码 · 共 47 行

C
47
字号
//**************************************************************************
//    The FIR filter is used here for phase lag/lead compensation.
//    The phase lag/lead compensation FIR do not have unity gain factor so an
//    extra gain compensation stage is added.
//    The FIR is implement in fractional binary arithmatic. Sign the gain correction 
//      can be >1. This needs to be taken into account 
//
//    Vincent Chan 
//    Texas Instruments Hong Kong Ltd
//    Date        Comments
//    =====================
//    01/09/19    Code Starts
//    01/10/07    First cut test done
//**************************************************************************
#include "emeter_3phase.h"
#include <stdio.h>

//#include "math.h"
//--------------------------------------------------------------------------


//  This routine provides a one TAP FIR which gives a fractional delay. The gain is compensated

int FIR(int int_params[],int input)
{
int i,j;
              // I(n) = ( I(n-1)*beta + I(n) ) * gain;
              // int_params[FIR_TAP] : I(n-1)
              // int_params[FIR_GAIN]: gain
              // int_params[FIR_BETA]: beta
if(int_params[FIR_GAIN]<0)        
  {                             //In this case gain >1
  i=FRACTIONAL_SIGNED_MUL(int_params[FIR_TAP],int_params[FIR_BETA])+input;
  j=int_params[FIR_GAIN]-32768;
  j=FRACTIONAL_SIGNED_MUL(j,i)+i;
  i=j;
  }
else
  {  
  i=FRACTIONAL_SIGNED_MUL(int_params[FIR_TAP],int_params[FIR_BETA])+input;
  i=FRACTIONAL_SIGNED_MUL(int_params[FIR_GAIN],i);
  }

int_params[FIR_TAP]=input;
return(i);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?