滤波算法 | 限幅滤波法

        对于随机干扰 , 限幅滤波是一种有效的方法;
        基本方法:比较相邻n 和 n - 1时刻的两个采样值y(n)和 y(n – 1),根据经验确定两次采样允许的最大偏差。如果两次   采样值的差值超过最大偏差范围 ,认为发生可随机干扰 ,并认为后一次采样值y(n)为非法值 ,应予删除 ,删除y(n)后 ,可用y(n – 1) 代替y(n);若未超过所允许的最大偏差范围 ,则认为本次采样值有效。

下面是限幅滤波程序:(DELAT_MAX值可根据实际情况调整,effective_value为有效值 , new_value 为当前采样值滤波程序返回有效的实际值 )

#include <stdio.h>

// 声明最大误差
#define DELAT_MAX 10
// 定义滤波数据类型
typedef	int filter_type;
// 函数声明
filter_type filter(filter_type effective_value, filter_type new_value, filter_type delat_max);
// 限幅滤波函数
filter_type filter(filter_type effective_value, filter_type new_value, filter_type delat_max)
{
	if ( ( new_value - effective_value > delat_max ) || ( effective_value - new_value > delat_max ))
		return effective_value;
	return new_value;
}
// 打印测试
void main()
{
	filter_type a = 8;
	filter_type b = -3;
	filter_type c;

	c = filter(a, b, DELAT_MAX);
	printf("%d", c);
}

输出结果:

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式逍遥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值