Exercises for system-id.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

G = tf([0.0565 0.1013], [1 -1.4183 1.5894 -1.3161 0.8864], 1.0);
%% a) Generate sets of identification data
N = 200;
u_idin = idinput(N);
u_unif = 2 * rand(N, 1) - 1;
% for 3c)
N = 5 * N;
u_idin = repmat(u_idin, 5, 1);
u_unif = repmat(u_unif, 5, 1);
e = 0.1 * randn(N, 1);
y_idin = lsim(G, u_idin) + e;
y_unif = lsim(G, u_unif) + e;
%% b) Estimate G(z) by EFTE
U_idin = abs(fft(u_idin));
U_unif = abs(fft(u_unif));
Y_idin = abs(fft(y_idin));
Y_unif = abs(fft(y_unif));
G_idin = Y_idin ./ U_idin;
G_unif = Y_unif ./ U_unif;
omega = (2*pi/N)*[0:N-1];
pos_idx = find(omega >= 0.0 & omega <= pi);
H = abs(squeeze(freqresp(G, omega(pos_idx))));
err_idin = abs(H - G_idin(pos_idx));
err_unif = abs(H - G_unif(pos_idx));
subplot(2, 1, 1)
loglog(omega(pos_idx), H, 'green');
hold on
loglog(omega(pos_idx), G_idin(pos_idx), '--b');
loglog(omega(pos_idx), G_unif(pos_idx), '-.r');
hold off
legend('True plant', 'EFTE random binary', 'EFTE uniform distribution')
subplot(2, 1, 2)
loglog(omega(pos_idx), err_idin, '--b')
hold on
loglog(omega(pos_idx), err_unif, '-.r')
hold off
legend('EFTE random binary error', 'EFTE uniform distribution error')
fprintf('err_idin total: %f\n', mean(err_idin))
fprintf('err_unif total: %f\n', mean(err_unif))
%% c)
% 1) Obvious. Slightly better results
% 2)
% 3) Best solution. Discard first period. Average the rest and apply fft after
% y5 = mean(reshape(yp(N+1:end), N, []), 2)
% Y5_N = fft(y5)