How to smooth a vector of noisy data?

Very confused on how to smooth a vector of noisy data, without using MATLABS built in smooth function. Any help much appreciated

4 Comments

You could write your own routine to mimic what one of the built-in routines does. Why do you not want to use one of the built-in smoothing functions, such as smoothdata() which offers several different types of smoothing algorithms? Why re-invent the wheel?
We are asked not to use the built-in sadly, here's what we are asked and can't find how to do it anywhere in the notes
The filter should take a vector of noisy data (x) and smooth it by doing a symmetric moving average with a window of the specified width. For points near the beginning and the end of the data set, use a smaller number of samples on either side of the samples in the average calculation, but be sure to keep an equal number of samples on either side of the sample under test.
Oh, it's homework. I've added the homework tag for you. Just use a for loop.
windowWidth = 3;
halfWidth = floor(windowWidth/2);
for k = halfWidth + 1 : length(x) - halfWidth
thisWindow = x(k-halfWidth:k+halfWidth);
newValue = mean(.....
....
end
I assume you can figure out how to complete the code.

Sign in to comment.

Answers (0)

Asked:

on 5 Sep 2017

Commented:

on 5 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!