%Class for CO907. %__________________________________________ %Author: Jiarui Cao %Date: 19 Nov 2013 %Purpose: Problem Sheet 2. Q2.5c close all; clear all; clc; clf; n=500; rng('default'); %% generate data sigma=0.5; y=normrnd(0,sigma,n,1); %noise x=zeros(n,1); % %% AR(1) % % c=1; % phi=0.99; % x(1)= 0; % for t =2 :n % x(t) = c + phi*x(t-1) + y(t); % end % % %hold on % % plot(x,'or'); % xlabel('t','fontsize',30); % ylabel('X(t)', 'fontsize', 30); % model = arima('Constant',c,'AR',phi,'Variance',sigma^2); % % s=simulate(model,n); % plot(s); %% AR(2) c = 0; phi = [1.5, -0.5]; x(1)=0; x(2)=0; for t=3:n x(t) = c + phi(1)*x(t-1) + phi(2)*x(t-2) + y(t); end plot(x, 's-'); xlabel('t','fontsize',30); ylabel('X(t)', 'fontsize', 30); %% sovle lambda syms lambda; vpasolve(lambda^2 - phi(1)*lambda - phi(2)==0,lambda) %compute %% use estimate to fit the parameters model =arima(2,0,0); %guess this is a AR(2) model. estimate(model,x) %estimate the data