7.一階滯後濾波法

/*

A、名稱:一階滯後濾波法

B、方法:

取a=0-1,本次濾波結果=(1-a)*本次采樣值+a*上次濾波結果。

C、優點:

對周期性干擾具有良好的抑制作用;

適用於波動頻率較高的場合。

D、缺點:

相位滯後,靈敏度低;

滯後程度取決於a值大小;

不能消除濾波頻率高於采樣頻率1/2的干擾信號。

E、整理:shenhaiyu 2013-11-01

*/

int Filter_Value;

int Value;

void setup() {

Serial.begin(9600); // 初始化串口通信

randomSeed(analogRead(0)); // 產生隨機種子

Value = 300;

}

void loop() {

Filter_Value = Filter(); // 獲得濾波器輸出值

Serial.println(Filter_Value); // 串口輸出

delay(50);

}

// 用於隨機產生一個300左右的當前值

int Get_AD() {

return random(295, 305);

}

// 一階滯後濾波法

#define FILTER_A 0.01

int Filter() {

int NewValue;

NewValue = Get_AD();

Value = (int)((float)NewValue * FILTER_A + (1.0 - FILTER_A) * (float)Value);

return Value;

}