当前位置:网站首页>matlab 实现中值滤波
matlab 实现中值滤波
2022-06-22 07:00:00 【胡刚2016】
平均滤波器不能滤除信号中的脉冲噪声,而中值滤波器可以消除部分脉冲噪声
中值滤波器的原理:
按照样本的幅值排序,然后选择其中的中值,作为滤波器的输出
代码实现如下:
clear all; clf
N=200;
n=0:N-1;
%产生200个脉冲噪声,生成脉冲噪声数组
for m=1:N,
d=randn(1, 1);
if d >= 0.95,
noise(m)=-1.5;
else
noise(m)=0;
end
end
%画噪声信号
subplot(511);
t=0:1:N-1;
plot(t, noise);
title('噪声信号');
%画原信号
x=[2*cos(pi*n(1:100)/256) zeros(1, 100)];
subplot(512);
t=0:1:N-1;
plot(t, x);
title('原信号');
%画噪声信号+原信号
y1=x+noise;
subplot(513);
t=0:1:N-1;
plot(t, y1);
title('噪声信号+原信号');
%画均值滤波后的信号
z2=average(15, y1);
subplot(514);
t=0:1:N-1;
plot(t, z2);
title('均值滤波后的信号');
%对y1(-2) 到 y1(3) 进行中值滤波,得到z1(1)
z1(1)=median([0 0 y1(1) y1(2) y1(3)]);
%对y1(-1) 到 y1(4) 进行中值滤波,得到z1(2)
z1(2)=median([0 y1(1) y1(2) y1(3) y1(4)]);
%对y1(197) 到 y1(201) 进行中值滤波,得到z1(199)
z1(N-1)=median([y1(N-3) y1(N-2) y1(N-1) y1(N) 0]);
%对y1(198) 到 y1(202) 进行中值滤波,得到z1(200)
z1(N)=median([y1(N-2) y1(N-1) y1(N) 0 0]);
%对y1(1) 到 y1(200) 进行中值滤波,得到其他值z1(3)到z1(198)
for k=3:N-2,
z1(k)=median([y1(k-2) y1(k-1) y1(k) y1(k+1) y1(k+2)]);
end
%画中值滤波后的信号
subplot(515);
t=0:1:N-1;
plot(t, z1);
title('中值滤波后的信号');
function y=average(M, x)
b=1/M*ones(1, M);
y=filter(b, 1, x);
end

可以看出中值滤波比平均滤波效果好一些
这里不得不补充说明:中值滤波的好坏取决于脉冲噪声的宽度,如果生成的脉冲宽度很窄,那么中值滤波的效果就会很好。(因为脉冲噪声信号的生成是随机的,所以中值滤波的效果也不能保证。)
运行多此后总会生成一个比较适合中值滤波处理的脉冲噪声

边栏推荐
- 自定义实现JS中的bind方法
- Introduction to 51 Single Chip Microcomputer -- the use of Proteus 8 professional
- 【实习】跨域问题
- [distributed external detection] Odin ICLR '18
- Quelles industries les diplômés recherchent - ils en 2022?
- OpenGL - Textures
- [out of distribution detection] deep analog detection with outlier exposure ICLR '19
- 自然语言处理理论和应用
- 代码的巨大进步
- 生成字符串方式
猜你喜欢

CNN model collection | RESNET variants -wideresnet interpretation

Vue failed to connect to MySQL database

自然语言处理理论和应用

6. install the SSH connection tool (used to connect the server of our lab)
![[fundamentals of machine learning 02] decision tree and random forest](/img/24/28964279ea479476e1a232aec9c599.jpg)
[fundamentals of machine learning 02] decision tree and random forest

实训渗透靶场02|3星vh-lll靶机|vulnhub靶场Node1

首次用DBeaver连接mysql报错

MySQL Niuke brush questions

Rebuild binary tree

Training penetration range 02 | 3-star VH LLL target | vulnhub range node1
随机推荐
JS中对数组进行去重的几种方法
buuctf部分题目wp
EMC solutions
Blog add mailbox private message shortcut
C language - deep understanding of arrays
Wildfire stm32f407zgt6 learning notes beginner level chapter basic knowledge points
Don't throw away the electric kettle. It's easy to fix!
Fundamentals of neural network (notes, for personal use)
Literature record (part106) -- graph auto-encoder via neighborhood Wasserstein reconstruction
Cesium加载3D Tiles模型
C语言——深入理解数组
Shengxin literature learning (Part1) -- precision: a approach to transfer predictors of drug response from pre-clinical ...
Yolov1 (prediction process)
Cesium loading 3D tiles model
Rebuild binary tree
CNN模型合集 | Resnet变种-WideResnet解读
sessionStorage 和 localStorage 的使用
Qt development simple Bluetooth debugging assistant (low power Bluetooth)
关于solidity的delegatecall的坑
The journey of an operator in the framework of deep learning