clear all;
t=0:0.01:1;
f2=5;
%生成一个正弦信号y;
y1=1*sin(2*pi*f2*t);
%y1=square(2*pi*f2*t);
%向y中加入噪声信号生成x;
x1=y1+0.1*randn(1,101);
figure(1)
subplot(2,1,1);
plot(t,y1,'r');title('生成一个正弦信号y');grid;legend y;
subplot(2,1,2);
plot(t, x1,'r');title('向y中加入噪声信号生成x');grid; legend x;
X=1:length(x1)
for X=1:length(x1)
z1=smooth(x1,3);%M=3时的均值滤波
end
for X=1:length(x1)
z2=smooth(x1,5);%M=5时的均值滤波
end
for X=1:length(x1)
z3=smooth(x1,7);%M=3时的均值滤波
end
figure(2)
subplot(3,1,1);
plot(t,z1,'r');title('M=3时的均值滤波处理后的信号');grid; legend y;
subplot(3,1,2);
plot(t,z1,'r');title('M=5时的均值滤波处理后的信号');grid; legend y;
subplot(3,1,3);
plot(t,z1,'r');title('M=7时的均值滤波处理后的信号');grid; legend y;
for X=1:length(x1)
L1= median(x1,3);
end
for X=1:length(x1)
L2= median(x1,5);
end
for X=1:length(x1)
L3= median(x1,7);
end
figure(3)
subplot(3,1,1);
plot(t,L1,'r');title('M=3时的中值值滤波处理后的信号');grid; legend y;
subplot(3,1,2);
plot(t,L2,'r');title('M=5时的中值值滤波处理后的信号');grid; legend y;
subplot(3,1,3);
plot(t,L2,'r');title('M=7时的中值值滤波处理后的信号');grid; legend y;
%Y1=x1;
%n = length(Y1);
%K=(n-1)/2;
%for t=0:n
%for i = 1:n-1
% for j = i+1:n
% if( Y1(i)>Y1(j))
% tmp = Y1(j);
% Y1(j) = Y1(i);
% Y1(i) = tmp;
%end
%end
%end
%x1(K)=Y1(i);
%end
%subplot(3,1,3);
%plot(t,x1,'g');title('用中值滤波处理后提取出原始信号');grid; legend y;
评论4
最新资源