% mademo.m % fitting a time series into a ma model using spectral factorization % S(z) = B(z)B(1/z*) = R(0) + sum_k=1 R(k)(z^k + z^-k) % 1. Estimate R(k) from time series, then % 2. find the roots of S(z) that should be z and 1/z* pairs % 3. assume B(z) has all zeros within unit circle, find zeros of B(z) % 4. form B(z) from its roots % clear all b=[1 0.5] M=length(b); L=1000; u=randn(L,1); u=u-mean(u); % input, zero mean y=filter(b,1,u); y=y(M-1:L); % rlen=min(L, 10*M); ry=autocorr(y,rlen); figure(1),clf,stem([0:rlen-1],ry), title('autocorrelation lags of y') Mhat=input('MA model order = '); bhat=mafun(y,Mhat)