限幅濾波算法(程序判斷濾波算法) 方法解析: 根據經驗判斷,確定兩次采樣允許的最大偏差值(設定為A),每次檢測到新值時判斷: 如果本次值與上次值之差<=A,則本次值有效, 如果本次值與上次值只差>A,則本次值無效,放棄本次值,用上次值代替本次值。 優點: 能有效克服因偶然因素引起的脈沖干擾 缺點: 無法抑制那種周期性的干擾,平滑度差
#define A 10 char value; char filter() { char new_value; new_value = get_ad(); if ( ( new_value - value > A ) || ( value - new_value > A ) return value; return new_value; }
|