function ident_example0(L,std_e) n = 2; N = L - n; theta = [-0.34 0.6 0.3369 0.4800]'; t = [1:1:L]'; u = idinput(L,'PRBS',[0 1],[-1 1]); % std(u) % deviazione standard ingresso Bz = [0 theta(4) theta(3)]; Az = [1 -theta(2) -theta(1)]; ys = dlsim(Bz,Az,u); randn('state',0) e = std_e * randn(L,1); % std(e) % deviazione standard errore d'equazione ef = dlsim([0 0 1],Az,e); % filtraggio dell'errore d'equazione y = ys + ef; figure, subplot(211), plot(t,u,'-'), xlabel('Campioni'), title('Ingresso u') subplot(212), plot(t,y,'-'), xlabel('Campioni'), title('Uscita y') % roots(Az) % verifica la stabilita' del polinomio Phi_u = my_hank(u,N,n,0); Phi_y = my_hank(y,N,n,0); Phi = [Phi_y Phi_u]; Y = y(n+1:N+n); theta disp(sprintf('\n')) theta_hat = inv(Phi' * Phi) * Phi' * Y disp(sprintf('\n')) Yhat = Phi * theta_hat; eps_err = Y - Yhat; sigma_e_hat = (1/(N - length(theta)))*(eps_err' * eps_err); % std_e_hat = sqrt(sigma_e_hat) % stima dell'errore d'equazione cov_theta_hat = sigma_e_hat * inv(Phi' * Phi); disp(sprintf('\n')) std_err_theta = sqrt(diag(cov_theta_hat)) figure, subplot(221), plot(theta(1),'b*'), hold on, plot(theta_hat(1),'ro'), hold on, plot(theta_hat(1) + std_err_theta(1),'g^'), hold on, plot(theta_hat(1) - std_err_theta(1),'gv'), title('a_2') subplot(222), plot(theta(2),'b*'), hold on, plot(theta_hat(2),'ro'), hold on, plot(theta_hat(2) + std_err_theta(2),'g^'), hold on, plot(theta_hat(2) - std_err_theta(2),'gv'), title('a_1') subplot(223), plot(theta(3),'b*'), hold on, plot(theta_hat(3),'ro'), hold on, plot(theta_hat(3) + std_err_theta(3),'g^'), hold on, plot(theta_hat(3) - std_err_theta(3),'gv'), title('b_2') subplot(224), plot(theta(4),'b*'), hold on, plot(theta_hat(4),'ro'), hold on, plot(theta_hat(4) + std_err_theta(4),'g^'), hold on, plot(theta_hat(4) - std_err_theta(4),'gv'), title('b_1') return %%%%%%%%%%%%%%%%%%%%%%% Funzioni Locali %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function Hn = my_hank(Yvet,Nseq,Ord,Off) for i=1:Ord, Hn(:,i) = Yvet( Off+i: Nseq+Off+i-1 ); end; return