%% impulse_example.m 
% Script to show the effect of an impulse on a first order system
% BJ Furman
% 29AUG2015
%% Plotting the impulse response for a time duration of $\delta t
clear all
close all
tau = 1;
% Excite with an impulse input keeping area under impulse constant
tend = tau*[5 3 1 0.5 0.1 0.01];
num_plots = length(tend);
figure
hold
h = zeros(1,num_plots);
% Alternate Color Scheme colors = colormap(hsv(num_plots));
for n = 1:num_plots
    t1 = linspace(0,tend(n),500);
    Vnorm_forced = (1/tend(n))*(1-exp(-t1/tau));
    t2 = linspace(t1(end),(t1(end)+5*tau),500);
    Vnorm_free = Vnorm_forced(end)*exp(-(t2-t1(end))/tau);
   h(n)= plot([t1,t2],[Vnorm_forced,Vnorm_free],'DisplayName',sprintf('tau=%g',tend(n)));
end
grid
legend(h)
title('Constant Magnitude Impulse Response')
xlabel('t/\tau')
ylabel('V/V1')
plot([0,0, 0,tend(1),tend(1)],[0,1/tend(1),1/tend(1),1/tend(1),0],'Color','k','LineWidth',1)
plot([0,0, 0,tend(2),tend(2)],[0,1/tend(2),1/tend(2),1/tend(2),0],'Color','k','LineWidth',1)
plot([0,0, 0,tend(3),tend(3)],[0,1/tend(3),1/tend(3),1/tend(3),0],'Color','k','LineWidth',1)
plot([0,0, 0,tend(4),tend(4)],[0,1/tend(4),1/tend(4),1/tend(4),0],'Color','k','LineWidth',1)

%%
