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.

33 lines
792 B

%% 1. Generate e(k), random noise
N = 1024;
e = randn(N, 1);
%% 2. Calculate and plot the periodogram of e
% Fourier transform
E = fft(e);
omega = (2*pi/N)*[0:N-1]';
% Positive frequencies
pos_idx = find(omega >= 0.0 & omega <= pi);
% Plot
E_periodogram = abs(E(pos_idx)).^2/N;
loglog(omega(pos_idx), E_periodogram)
%% 3. Given plant P, calculate the response (w)
num = [1 0.5];
den = [1 0 0.25];
P = tf(num, den, 1.0);
w = lsim(P, e);
%% 4. Calculate the periodogram of w(k)
W = fft(w);
W_periodogram = abs(W(pos_idx)).^2/N;
loglog(omega(pos_idx), W_periodogram)
hold on
%% 5. Compare periodogram w to square of Bode Plot
[mag, phase, wout] = bode(P, omega(pos_idx));
mag = squeeze(mag);
loglog(omega(pos_idx), abs(mag).^2)
diff = abs(W_periodogram - mag);
loglog(omega(pos_idx), diff)