clc;
clear;
close all;
%%
T0 = 0 ;
Ts = 0.001 ;
Tf = 20 ;
t = T0:Ts:Tf ; t = t' ;
system = tf(1,[1 1]) ;
g = impulse(system , t) ;  %% impulse response
w = 2*pi*0.5 ;
u = 2.*sin(w.*t) ;
y = zeros(size(t)) ;
for  i = 1:numel(t)
    y(i) = g(1:i-1)' * u(i-1:-1:1) * Ts ;
end
figure(1) ;
plot(t , u ,t , y , 'LineWidth' , 2) ;  hold on
grid on ; xlabel('Time') ; ylabel('Amp') ;legend('U','Y');
%% real response
T0 = 0 ;
Ts = 0.001 ;
Tf = 20 ;
tr = T0:Ts:Tf ; tr = tr' ;
u = 2.*sin(w.*tr) ;
yr = lsim(system , u , tr) ;
figure(1) ;
plot(tr , yr , 'LineWidth' , 2) ; 
grid on ; xlabel('Time') ; ylabel('Amp') ;legend('U','Y' , 'Y real');


