Untitled
unknown
plain_text
a month ago
1.8 kB
3
Indexable
Never
%Q1 load('SysIdenData_StudentVersion.mat'); t = LogData.time; y_act = LogData.signals(1).values(:,2); y_actm = LogData.signals(1).values(:,1); u_act = LogData.signals(2).values; Ts = 0.75; figure; subplot(2,1,1); plot(t,y_act,'b','DisplayName','Noise-Reduced Output'); hold on; plot(t,y_actm,'r','DisplayName', 'Measured Output'); hold off; xlim([0 700]); ylim([1 4]); title('Actual Output Signal'); xlabel('Time (sec)'); ylabel('Water Level (V)'); legend; grid on; subplot(2,1,2); plot(t,u_act,'b','DisplayName','Actual Input'); xlim([0 700]); ylim([1 3]); title('Actual Input Signal'); xlabel('Time (sec)'); ylabel('Pump Voltage (V)'); legend; grid on; %% %offset (Q1) i = 1; while u_act(i) == u_act(1) i = i+1; end y_offset = mean(y_act(1:i-1)); y = y_act - y_offset; u_offset = mean(u_act(1:i-1)); u = u_act - u_offset; figure subplot(2,1,1); plot(t,y,'r','DisplayName','Actual Output'); title('Actual Offset-Free Output Signal'); xlim([0 700]); ylim([-2 1]); xlabel('Time (sec)'); ylabel('Water Level (V)'); legend; grid on; subplot(2,1,2); plot(t,u,'b','DisplayName','Actual Input'); title('Actual Offset-Free Input Signal'); xlim([0 700]); ylim([-0.5 0.5]); xlabel('Time (sec)'); ylabel('Pump Voltage (V)'); legend; grid on; %% %Q2 a) k = 3; Halfsize = floor(length(t)/2); phi(1,:) = [0 0 0 0]; %initial value phi(2,:) = [y(1) 0 u(1) 0]; while k <= Halfsize phi(k,:) = [y(k-1) y(k-2) u(k-1) u(k-2)]; k = k+1; end %Q2 b) Y = y(1:Halfsize); theta_hat = (transpose(phi)*phi)^-1*transpose(phi)*Y; a1 = -theta_hat(1); a2 = -theta_hat(2); b1 = theta_hat(3); b2 = theta_hat(4); %Q2 c) z = tf('z',Ts); GZ = (b1*z+b2)/(z^2+a1*z+a2); G = [0 1; -a2 -a1]; H = [0;1]; C = [b2 b1]; D = 0; equ2 = ss(G,H,C,D,Ts);
Leave a Comment