中值滤波的代码:
x=0:2047;
a=load('data.txt'); %运行时data.txt文件要放到当前目录(current directory)中
n=5; % n为模板长度,值可以改变
y = medfilt1(a,n);
figure;
subplot(1,2,1);plot(x,a);
xlabel('中值滤波前的序列');
subplot(1,2,2);plot(x,y);
xlabel('中值滤波后的序列');
均值滤波的代码:
x=0:2047;
a=load('data.txt'); %运行时data.txt文件要放到当前目录(current directory)中
n=5; % n为模板长度,值可以改变
mean = ones(1,n)./n; %mean为1×n的模板,各数组元素的值均为1/n
y = conv(a,mean);
y=y(1:length(y)-length(mean)+1);
figure;
subplot(1,2,1);plot(x,a);
xlabel('均值滤波前的序列');
subplot(1,2,2);plot(x,y);
xlabel('均值滤波后的序列');
高斯滤波的代码:
x=0:2047;
a=load('data.txt'); %运行时data.txt文件要放到当前目录(current directory)中
gau=[0.0009 0.0175 0.1295 0.3521 0.3521 0.1295 0.0175 0.0009];%标准差为1时的高斯函数