I am trying to smooth a given data set (y) with multiple passes of a moving average. I have the code to simply do one pass (I am aware of the smooth function)however, this is for an assignment and the instructor wants us to create our own smoothing code.
What I would like to do is supply a vector of different spans, and have the moving average act on the previous moving average. This way I will be able to find a span set that best smoothes the data.
% Creates a moving average with a defined set of spans.
span = [9,11,21];y_smooth = y; for i = 1:length(span) d = [(span(i)-1)/2]; y_smooth = conv(y_smooth,ones(1,d)/d,'same'); end%
Does this appear to work?
Best Answer