I have a sinusoidal x(t) = sin(500πt) signal is corrupted by random noise. The corrupted signal is sampled with sampling frequency fs = 5 kHz and passed through a 5-point moving average filter to reduce the noise. I have written the following MATLAB Code for the same:-
fs=5e3; t=0:1/fs:0.02;
x=sin(2*pi*250*t); % uncorrupted signal
r=0.1*randn(1,length(x)); % random noise
XR=x+r; % signal + noise (filter input)
y=0;
% Implement the moving average filter in time domain
for n=5:length(XR), % M = 5
y(n) = % missing code using the command 'sum'
end
figure(12);
subplot(211); plot(t,XR,t,x,'r'); legend('Corrupted','Original');
xlabel('time (sec)'); ylabel('Amplitude'); grid;
subplot(212); plot(t,y,'k',t,x,'r'); legend('After filtering','Original');
xlabel('time (sec)'); ylabel('Amplitude');grid;
But, I am not sure how to implement the moving average filter in time domain using sum command to get the output (y[n]) in the for loop as mentioned above in the code. Any suggestions would be highly appreciated! Thanks a lot for the help🙏
subplot()
& co, but you don't have that particular line. $\endgroup$