⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filter.c

📁 * CONSTRAINTS * This module does not handle data which is considered out of range by the * appli
💻 C
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *  Copyright (c) 2007 by Qu chun lei watt@vip.163.com
 *
 *  File name: FILTER.C
 *  Module:    0602C
 *  Language:  ANSI C
 *  $Revision: 11 $
 *
 *  Source code for a digital filter module described in filter.h.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef FILTER_C
#define FILTER_C

#include "filter.h"


/*----------------*
 |  Private data
 *----------------*/

TFilterDataInternal filterData[FILTER_COUNT]; /* filtered data */

#if FILTER_COUNT > 1
#define filterData_ filterData[instance]
#else
#define filterData_ filterData[0]
#endif

#if FILTER_WEIGHT_DYNAMIC
static UINT8 filterWeight[FILTER_COUNT];          /* filter weight */

#if FILTER_COUNT > 1
#define filterWeight_   filterWeight[instance]
#else
#define filterWeight_   filterWeight[0]
#endif

#else
#if !FILTER_WEIGHT_FIXED
static const UINT8 FILTER_WEIGHT[FILTER_COUNT] = FILTER_WEIGHT_DATA;

#if FILTER_COUNT > 1
#define FILTER_WEIGHT_   FILTER_WEIGHT[instance]
#else
#define FILTER_WEIGHT_   FILTER_WEIGHT[0]
#endif
#endif

#endif


/*--------------------*
 |  Public functions
 *--------------------*/

/*---------------------------------------------------------------------------*
 |  FilterData
 |
 |  Report the filtered value.  For details see FILTER.H
 *---------------------------------------------------------------------------*/

#if FILTER_COUNT > 1
TFilterData FilterData(UINT8 instance)
#else
TFilterData FilterData(void)
#endif
{
    return ((TFilterData)((filterData_ + 128) >> 8));
}


/*---------------------------------------------------------------------------*
 |  FilterDataSet
 |
 |  Force filtered data to a given value.  Typically used for initialization.
 |  For details see FILTER.H
 *---------------------------------------------------------------------------*/

#if FILTER_COUNT > 1
void FilterDataSet(UINT8 instance, TFilterData newValue)
#else
void FilterDataSet(TFilterData newValue)
#endif
{
    filterData_ = ((TFilterDataInternal)(newValue)) << 8;
}


/*---------------------------------------------------------------------------*
 |  FilterDataUpdate
 |
 |  Calculate new filtered data.  For details see FILTER.H
 *---------------------------------------------------------------------------*/

#if FILTER_COUNT > 1
void FilterDataUpdate(UINT8 instance, TFilterData rawData)
#else
void FilterDataUpdate(TFilterData rawData)
#endif
{
#if FILTER_WEIGHT_DYNAMIC
    filterData_ = ((TFilterDataInternal)(filterWeight_ - 1) * filterData_ 
        + (((TFilterDataInternal)(rawData)) << 8))/((TFilterDataInternal)(filterWeight_));
#else
#if FILTER_WEIGHT_FIXED
    filterData_ = (((filterData_ << FILTER_WEIGHT_SHIFT) - filterData_ )
        + ((TFilterDataInternal)(rawData) << 8)) >> FILTER_WEIGHT_SHIFT;
#else
    filterData_ = ((TFilterDataInternal)(FILTER_WEIGHT_  - 1)*filterData_ 
        + ((TFilterDataInternal)(rawData) << 8))/((TFilterDataInternal)(FILTER_WEIGHT_));
#endif
#endif
}


#if FILTER_WEIGHT_DYNAMIC

/*---------------------------------------------------------------------------*
 |  FilterWeightSet
 |
 |  Set the weighting factor of the digital filter.  For details see FILTER.H
 *---------------------------------------------------------------------------*/

#if FILTER_COUNT > 1
void FilterWeightSet(UINT8 instance, UINT8 newWeight)
#else
void FilterWeightSet(UINT8 newWeight)
#endif
{
    filterWeight_ = newWeight;
}


/*---------------------------------------------------------------------------*
 |  FilterWeight
 |
 |  Report the weighting factor of the filter  For details see FILTER.H
 *---------------------------------------------------------------------------*/

#if FILTER_COUNT > 1
UINT8 FilterWeight(UINT8 instance)
#else
UINT8 FilterWeight(void)
#endif
{
    return filterWeight_;
}

#endif

#endif

⌨️ 快捷键说明

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