MATLAB: How to generate a repetition of impulse response when I feed the system with repetition of pulses

Control System Toolbox

I have the transfer function for a system and I want to generate a repetition of pulses as the input to the system and output the impulse response of the input pulses. The impulse response should be a repetition of the system impulse response.

Best Answer

We can use the Control System Toolbox to do this. 
The following code generates the system from the transfer function using 'tf' function
close all, clear all, clc
t=[0:.2e-3:1]; % Time vector
C=1e-2; L=20e-4; R=80e-3; % System parameters
a=1; b=[L*C R*C 1]; % Denominators and numerators
sys=tf([a],[b]) % Transfer function
impulse(sys) % Just a single pulse
Then we can generate the repetition of pulses and invoke the system impulse response using 'lsim' function.
% Generate input pulses
dt = 0.0002; %Sample rate
tend = 2.5; %Simulation period
t = 0:dt:tend;
period = 0.5; %Period of the input pulses
u = zeros(length(t),1);
for i=1:length(t)
if rem(t(i),0.5)==0
u(i)=1;
end
end
% Invoke the system response
% sysd = c2d(sys,dt); % Continuous to discrete system conversion.
[y yt] = lsim(sys,u,t);
y = y/dt; % Normalize with sample time.
% Plot the input and the output.
subplot(2,1,1);
plot(t,u);
title('Input');
subplot(2,1,2);
plot(yt,y);
title('Impulse Responce');