function [S_n,et,MSE] = simple_exp_smoothing(Z,w,S_0) % SIMPLE_EXP_SMOOTHING - Performs simple exponential smoothing % % Inputs: % Z : the original sequence % w : the relaxation factor % S_0 : the initial smooth value % % Outputs: % S_n : the smoothed sequence % et : the one step-ahead residuals % MSE : the mean square error % % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- if( nargin<3 ) S_0 = median(Z); end n = length(Z); S_n = zeros(n,1); et = zeros(n,1); alpha = 1 - w; et(1) = Z(1) - S_0; S_n(1) = alpha * Z(1) + w * S_0; % do the first point by hand ... for ii=2:length(Z), % do the rest ... et(ii) = Z(ii) - S_n(ii-1); S_n(ii) = alpha * Z(ii) + w * S_n(ii-1); end MSE = mean( et.^2 );