clear all; clc;

% Systemparametere for dx/dt=-ay+bu
a = 1;
b = 1;
% Innganssignal A*sin(w*t)
A = 1;
w = 1;
% Forventet ut signalparametere for A*A_r*sin(w*t+phi); 
A_r = b/sqrt(a^2+w^2); % Amplituderatio
phi = atan2(-w,a);     % Faseforskyving
thtea =-phi/w;         % Forsinkelse grunnet faseforskving
% Simuler system
simTime = 20;
simOut=sim("FrekAnFoSysSinusInnSinusUt");
t=simOut.tout;
y =simOut.y.signals.values;
ys=simOut.ys.signals.values;
u =simOut.u.signals.values;

% Lag plott
figure(1);clf(1);
hold on;
plot(t,y,'r','LineWidth',2);
plot(t,ys,'b--','LineWidth',2);
plot(t,u,'g:','LineWidth',2);

plot([0,simTime],[0,0],'--')
legend({'Inngangssignal: $A\sin(\omega t)$','Stasjonaerrespon: $AA_r\sin(\omega t+\phi)$','Utgangssignal: $e^{-at}\frac{b A \omega}{a^2+\omega^2}+AA_r(\omega)\sin(\omega t+\phi\big(\omega)\big)$'},'FontSize',24,'Interpreter','latex')

