Created
July 25, 2015 01:55
-
-
Save ksvbka/47b0befcfbdd3a8324e1 to your computer and use it in GitHub Desktop.
Implement some filter signal processing as mean filter, HPF, LPF, Kalman...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /******************************************************************************** | |
| Product: Filter signal processing | |
| Module: Filter | |
| Created: 7/24/2015, by KIENLTB | |
| Description: Implement filter sinal processing (mean filter, Kalman, HPF, LPF..) | |
| ********************************************************************************/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Header inclusions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| #include "filter.h" | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Local Constant definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Local Macro definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Local Data type definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Global variables */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Function prototypes */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Function implementations */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-------------------------------------------------------------------------------- | |
| Function : MeanFilter_Init | |
| Purpose : Inilization for mean filter | |
| Parameters : int16 data, int nSample | |
| Return : NULL | |
| --------------------------------------------------------------------------------*/ | |
| VOID MeanFilter_Init(PMEAN_FILTER meanFilter, int16 nSample) | |
| { | |
| BYTE i; | |
| for(i = 0; i <= nSample; i++) | |
| meanFilter->byDataBuff[i] = 0; | |
| meanFilter->count = 0; | |
| meanFilter->nSample = nSample; | |
| meanFilter->lDataSum = 0; | |
| } | |
| /*-------------------------------------------------------------------------------- | |
| Function: MeanFilter_Caculate | |
| Purpose: Caculate output value from raw value | |
| Parameters: PMEAN_FILTER, int16 rawdata | |
| Return: int16 output | |
| --------------------------------------------------------------------------------*/ | |
| int16 MeanFilter_Calculate(PMEAN_FILTER meanFilter, int16 rawData) | |
| { | |
| meanFilter->lDataSum += (long)rawData - (long)meanFilter->byDataBuff[meanFilter->count]; | |
| meanFilter->byDataBuff[meanFilter->count] = rawData; | |
| if(meanFilter->count >= meanFilter->nSample) | |
| meanFilter->count = 0; | |
| else | |
| meanFilter->count++; | |
| return (int16)(meanFilter->lDataSum / (meanFilter->nSample + 1)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /******************************************************************************** | |
| Product: Filter signal processing | |
| Module: Filter | |
| Author: 7/24/2015, by KIENLTB | |
| Description: Implement of some filter - mean, LPF, HPF, Kalman.. | |
| ********************************************************************************/ | |
| #ifndef __FILTER_H__ | |
| #define __FILTER_H__ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Header inclusions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Macro definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| #define MAX 20 | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Data type definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| typedef struct tagMEAN_FILTER | |
| { | |
| int16 nSample; | |
| int16 byDataBuff[MAX]; | |
| int16 count; | |
| long lDataSum; | |
| }MEAN_FILTER, *PMEAN_FILTER; | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Constant definitions */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Global variables */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-----------------------------------------------------------------------------*/ | |
| /* Function prototypes */ | |
| /*-----------------------------------------------------------------------------*/ | |
| /*-------------------------------------------------------------------------------- | |
| Function : MeanFilter_Init | |
| Purpose : Inilization for mean filter | |
| Parameters : int16 data, int nSample | |
| Return : NULL | |
| --------------------------------------------------------------------------------*/ | |
| VOID MeanFilter_Init(PMEAN_FILTER meanFilter, int16 nSample); | |
| int16 MeanFilter_Calculate(PMEAN_FILTER meanFilter, int16 rawData); | |
| #endif // __FILTER_H__ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment