function bhat=mafun(y,m); % Usage: bhat=mafun(y,m); % fitting a time sequence y into a MA(m) time series model % bhat: a vector estimated MA coefficients [b(0) ... b(M-1)]; % call mfiles: autocorr.m % (C) 2001 by Yu Hen Hu % created: 10/28/2001 ry=autocorr(y,m); % autocorrelation lags sz=ry/max(ry); % autocorrelation coefficients rt=roots(sz); % rt: a column vector idx=find(abs(rt)<1); % roots inside unit circle idx1=find(abs(rt)==1); % roots on unit circle will be duplicates if isempty(idx1), % if no roots on unit circle broot=rt(idx); else % if there is root on the unit circle, eliminte duplicates broot=[rt(idx) unique(rt(idx1))]; end bhat=poly(broot); % estimated polynomial