Matlab code for Signal smoothing by moving- average Filter

Code:


clc
clear all;
w=input('Enter window size:');
fs=input('Enter sampling freq:');
f=input('Enter freq:');
t=0:1/fs:1;

x=sin(2*pi*f*t);
e=0.5*randn(1,fs+1);
xe=x+e;

for n=1:fs-w
    xblk=xe(1,n:n+w-1);
    y(n)=(1/w)*sum(xblk);
end


subplot 211; plot(xe);title('Noisy signal');grid on;
subplot 212; plot(y);title('filtered signal');grid on;



Output:


Enter window size: 200
Enter sampling freq: 10000
Enter freq: 10
 




1 comments:

  1. nice code...
    can you help me for moving average filter for audio signal

    ReplyDelete