Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- close all;
- %Czesc pierwsza
- t=1:1:10000;
- z=(randn(size(t)))/10;
- a = 0.8;
- b = 2.4;
- u = ones(size(t));
- y = zeros(size(t));
- for i = 2:length(t)
- if i>length(t)/3
- y(i) = a*y(i-1) + b*u(i) + z(i);
- end
- end
- figure(1);
- plot(t,y);
- hold on;
- grid minor;
- %Czesc druga
- P = 1000*eye(2,2); %Warunek poczatkowy
- theta = [0;0]; %Wektor u, y
- tmp = 0;
- a_wy = [];
- b_wy = [];
- u2 = rand(size(t)); %Generowanie szumu na wejscie
- z2 = randn((size(t))); %Generowanie szumu zaklocajacego
- a_wart = [];
- b_wart = [];
- blad = [];
- y_wy = [];
- lambda=1;
- for i = 1:length(t)
- if i>length(t)/4
- %if i==length(t)/2
- % a=a+0.2;
- % end
- Vec = a*tmp+b*u2(i);
- Y = Vec+z2(i);
- phi = [tmp;u2(i)]; % Wartość poprzedniego wyjścia i aktualnego wejścia
- P_poprzednie = P; % Wartość porzpednigo P
- P = (1/lambda)*(P_poprzednie - ((P_poprzednie*(phi*phi') * P_poprzednie) / (lambda + (phi'*P_poprzednie*phi))));
- theta = theta + P * phi * (Y - (phi' * theta));
- tmp = Y;
- end
- a_wy = [a_wy, theta(1)];
- b_wy = [b_wy, theta(2)];
- y_wy = [y_wy, theta(2)];
- end
- figure(2);
- plot(t, a_wy);
- hold on;
- yline(0.8,'-.b');
- yline(1,'-.r');
- hold off;
- grid on;
- xlabel ('Numer iteracji');
- ylabel ('estymacja parametru a');
- figure(3);
- plot(t, b_wy);
- hold on;
- yline(2.4,'-.b');
- %yline(2.6,'-.r');
- hold off;
- grid on;
- xlabel ('Numer iteracji');
- ylabel ('estymacja parametru b');
- %%figure(4);
- %plot(t, y_wy);
- %hold on;
- %grid on;
- %xlabel ('Numer iteracji');
- %ylabel ('Wyjście');
- %
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement