MATLAB: How to plot an impulse response h(t) sampled with fs

impulse responseMATLABplotplottingsampling

Hi, I'm dealing with the desing of a digital filter using impulse invariance technique but i need help, I can't plot the impulse response which i derived theoretically and then implemented in matlab. What's wrong with my implementation? How can I solve this problem? further hints are welcome! Thanks in advance!
k1 = (s1*s2*s3*s4)/(s1-s2)/(s1-s3)/(s1-s4); %residues
k2 = (s1*s2*s3*s4)/(s2-s1)/(s2-s3)/(s2-s4);
k3 = (s1*s2*s3*s4)/(s3-s1)/(s3-s2)/(s3-s4);
k4 = (s1*s2*s3*s4)/(s4-s1)/(s4-s2)/(s4-s3);
deltat = 4e-4;
t = 0.1:deltat:100;
ha = (k1*exp(s1*t) + k2*exp(s2*t) + k3*exp(s3*t) + k4*exp(s4*t));
figure(3) % plot of ha
plot(t, ha)
grid on

Best Answer

Hi,
for me your code is running (made some assumptions and a small edit at the plot):
% I assume that s1...s4 are scalars and take some fantasy values,
% since you did not tell us something about them i use:
s1 = 0.01;
s2 = 0.02;
s3 = 0.03;
s4 = 0.005;
k1 = (s1*s2*s3*s4)/(s1-s2)/(s1-s3)/(s1-s4); %residues
k2 = (s1*s2*s3*s4)/(s2-s1)/(s2-s3)/(s2-s4);
k3 = (s1*s2*s3*s4)/(s3-s1)/(s3-s2)/(s3-s4);
k4 = (s1*s2*s3*s4)/(s4-s1)/(s4-s2)/(s4-s3);
deltat = 4e-4;
t = 0.1:deltat:100;
ha = (k1*exp(s1*t) + k2*exp(s2*t) + k3*exp(s3*t) + k4*exp(s4*t));
figure(3) % plot of ha
% Better visibility of the plot line:
plot(t, ha,'-b', 'LineWidth',2)
grid on
Best regards
Stephan