G=10
tau=1
Te=0.1
N=50

v_time=0:Te:(N-1)*Te;

% Analog Output
plot(v_time,G*(1-exp(-v_time/tau)));
hold on;

%-------------------------------------------------------------------------------
%         FIRST METHOD : Zero Order Blocker
%-------------------------------------------------------------------------------
% Output
for n=0:N-1
y(n+1)=G*(1-exp(-n*Te));
end 

stem(v_time,y)
hold on

% recurrence relation
yn_1=0
yn(1)=0
for n=1:N-1
yn(n+1)=yn_1*exp(-Te/tau)+G*(1-exp(-Te/tau));
yn_1=yn(n+1);
end

# stem(v_time,yn)
# hold on

%-------------------------------------------------------------------------------
%         SECOND METHOD : Euler Approx
%-------------------------------------------------------------------------------

K1=Te/(tau+Te)
K2=1-K1

for n=0:N-1
y2(n+1)=G*(1-K2^(n));
end 

stem(v_time,y2)
hold on

%-------------------------------------------------------------------------------
%         THIRD METHOD : Bilinear Approx
%-------------------------------------------------------------------------------
K1=1+2*tau/Te
K2=2*tau/Te-1

% recurrence relation
yn_1=0
ybn(1)=0
for n=1:N-1
ybn(n+1)=yn_1*(K2/K1)+G/K1+G/K1;
yn_1=ybn(n+1);
end

stem(v_time,ybn)
hold on


%-------------------------------------------------------------------------------

legend('analog','zero order blocker','euler approx','bilinear transform')


# print -dsvg ../illustrations/temp_fo.svg


