低通滤波2

//---------------------------------------------------------------------------
//  Name     :        FILT_lLowPass
//                  ======================================
//
//  Function : Low-pass filter with two filter constants
//
//            Output = (FiltConst1 * (NewInput + LastInput)) + (FiltConst2 * LastOutput) 
//
//  Inputs    : As function arguments:
//             - FLOAT32 lNewInput              : Filter new input
//             - S_LOW_PASS_FILTER_TYPE* psFilt  : Pointer to filter parameters
// 
//  Output   : As return value:
//             - FLOAT32 lOutput                : Filtered output
//
//---------------------------------------------------------------------------

FLOAT32 FILT_lLowPass(S_LOW_PASS_FILTER_TYPE* psFilt, FLOAT32 fNewInput)
{
   FLOAT32 fOut1, fOut2, fOutput;   

   // Calculate filter output
   fOut1 = fNewInput+ psFilt->fLastInput;
   fOut1 = fOut1* psFilt->fFiltConst1;
   fOut2 = psFilt->fLastOutput* psFilt->fFiltConst2;
   fOutput = fOut1 + fOut2;
   
   // Update filter parameters
   psFilt->fLastInput = fNewInput;
   psFilt->fLastOutput = fOutput;

   return fOutput;
}

const1和const2

/*
Tcon单位:s , example 2k = 0.0005
fFlterTime单位:ms , example 100ms = 100
*/
const1 = Tcon/(Tcon + 2.0f * fFltrTime *0.001f);// filter单位和Tcon单位需要统一

const2 = FLOAT_1_P_0 - FLOAT_2_P_0 *const1;

 const1和const2

K = 2*PI*f*Tcon; // Tcon 单位为秒
const1 = K/(K=2.0);
const2 = (2.0 - K) / (K + 2.0)

//

UNSIGNED8 byI;
FLOAT32 fTemp;
for( byI=0;byI<FSW_NUM_MAX;byI++)
{
   fTemp = TWO_PI * fWr * FSWMUX_fGetTimeTsw(byI);    
   fFWCVolPIfilterC1[byI] = fTemp / (fTemp + FLOAT_2_P_0);
   fFWCVolPIfilterC2[byI] = (FLOAT_2_P_0 - fTemp) / (fTemp + FLOAT_2_P_0);        
}
       

 


使用:

filterData = FILT_lLowPass(FILTER , newData);

 

 

 

 

posted @ 2023-05-24 10:56  Kconfig  阅读(45)  评论(0编辑  收藏  举报