%
%Esercizio 1
%
A=[0.5,0.5;-0.5,0.5];
B=[0.5;0.5];
C=[1,1];
D=1;

sist1=ss(A,B,C,D,-1);
pzmap(sist1),zgrid,pause

dcgain(sist1)
C*inv(eye(2)-A)*B+D
pause

step(sist1)
pause

%
%Esercizio 2
%
p=0.3;G21=tf(1-p,[1 -p],-1);
p=0.6;G22=tf(1-p,[1 -p],-1);
p=0.9;G23=tf(1-p,[1 -p],-1);
p=-0.3;G24=tf(1-p,[1 -p],-1);

step(G21,G22,G23,G24)
pause

p=0.3;
G21_1=freqresp(G21,1)
%verifica
(1-p)/(exp(j)-p)
pause

k=(0:20)';
u=sin(k);
y=lsim(G21,u,k);
yappr=abs(G21_1)*sin(k+angle(G21_1));
stairs(k,[u y yappr])
pause

%
%Esercizio 3
%

k=-50:50; 
vstar=sin(k)+sin(2*k);
addendi=vstar.*sin(pi*0.3-k*pi)./(pi*0.3-k*pi);
sum(addendi)

sin(0.3)+sin(2*0.3)
pause

plot(k,addendi)



