This post list two MATLAB codes and their outputs that represent the ensemble and median filtering concepts in Signals & System.
Task 1: Ensemble
MATLAB Code
r=50
m=0:r-1;
s=2*m.*(0.9.^m);
d=rand(r,1)-0.5;
x1=s+d’;
stem(m,x1,’g’)
xlabel (‘Time’)
ylabel(‘Amplitude’)
title(‘Noisy Signal’)
pause
for n=1:50
d=rand(r,1)-0.5
x=s+d’;
x1=x1+x
end
x1=x1/50
stem(m,x1,’r’)
xlabel(‘Time’)
ylabel(‘Amplitude’)
title(‘Ensemble Average’)
Task 2: Median Filtering
MATLAB Code
n=input(‘Median Filter Input’)
r=50;
a=rand(1,r)-0.4;
b=round(a);
m=0:r-1;
s=2*m.*(0.9.^m);
x=s+b;
y=medfilt1(x,3)
subplot(211)
stem(m,x,’r’)
axis([0 50 -1 8])
xlabel(‘Time’)
ylabel(‘Amplitude’)
title(‘Impulse Noise Corrupt Signal’)
subplot(212)
stem(m,y,’b’)
xlabel(‘Time’)
ylabel(‘Amplitude’)
title(‘Output of Median Filter’)
Leave a Reply