Would like help on smoothing data a noisy data would using a central moving average by also using iteration and scalar operations.
Show older comments
I'm not quite able to understand what the assignment is asking for. When it comes to "except k = 1 and k = N where x(1) = y(1).
The assignment explains this .. "Write a MATLAB program that will smooth a 1D array of noisy data using an averaging filter. The noisy data is stored in the MATLAB workspace file noisydata.mat. The data is stored in a 1D row array named x. The smoothing filter should process the 1 by N array of noisy data x and produce a 1 by N array of smoothed data y using a central moving average, y(k) = x(k-1) + x(k+1)/2 , except for k = 1 and k = N, where y(1) = x(1) and y(N) = x(N).
Your program
should plot the original noisy data versus the sample number (index) and the smoothed
data versus the sample number on separate axes in separate figure windows.
The program should perform all the operations using Iteration (for loops) and scalar
operations. Do not use element by element comparisons, element by element
mathematical operations, or MATLAB’s built in sum function.
clear; clc;
% load data
load('noisydata.mat','x');
k = 1;
avg = zeros(1,length(x));
% create smoothing filter using a central moving average
for vecVal = x
if k > 1
avg(k) = (x(k-1) + x(k+1))/2;
k = k + 1;
disp(avg)
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!