Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How do I obtain an Impulse Response?

Asked by MathWorks Support Team on 22 Feb 2012

I would like to obtain an impulse response of a state space model in MATLAB or Simulink.

0 Comments

MathWorks Support Team

Products

1 Answer

Answer by MathWorks Support Team on 22 Feb 2012
Accepted answer

The secret to obtaining impulse responses lies in using the initial conditions that arise from impulse input. This approach allows the zero time duration of the impulse to be correctly modeled, rather than using an input signal of [1 0 0 0 ...].

Consider the following proof:

 xdot = ax + bu 
x = int(ax+bu)dt
= a*int(x)dt + b*int(u)dt

For the impulse response, u is a delta function which has an area of one from -inf to +inf. So,

 x = a*int(x)dt + b*1 
 = a*int(x)dt + b

We want to determine the value of x at t = 0 (i.e., the initial conditions that correspond to an impulse). Assume that from t = -inf to t = 0, x = 0. The result is that a*int(x) can be evaluated from 0 to time t. We are interested in the initial condition (t = 0), which leaves a*int(x)dt to be evaluated from t = 0 to t = 0.

The result is:

 z*int(x)dt=0

and

 x(t=0) = 0 + b = b.

Therefore, an impulse may be simulated by using an input of all zeros and initial conditions of b.

At first an appropriate state space model has to be defined:

a = -1; 
b = 1; 
c = 1;
d = 0;
sys = ss(a,b,c,d);

The following examples demonstrate various methods of obtaining impulse responses for the system.

1) Using the impulse command:

[y1,t1,x1] = impulse(sys);
plot(t1,y1)

2) Using the lsim command:

% Build the time vector and input signal
% Use time vector returned by IMPULSE 
% command for comparison:
t2 = t1; 
u = zeros(size(t2)); 
help lsim % This is for seeing help on LSIM command. 
[y2,t2,x2] = lsim(sys,u,t2,b);
plot(t2,y2) 

3) Using the ode45 command:

Define the MATLAB file for the derivatives (see attachment 'fun.m'):

function xdot = fun(t,x)
% xdot = a*x + b*u 
% u is zero for all t, therefore,
% xdot = a*x, where a = -1 
xdot = -x;

Evaluate the function from t = 0 to t = 6:

[t3, y3] = ode45('fun',[0 6],b); 
plot(t3,y3) 

4) Using SIMULINK:

Remark: Additional to the description below, an appropriate Simulink (R2011b) model is attached, named 'obtain_impulse_response.mdl'. (You can directly start with point f, using this model)

a) Using a State-Space block, enter the a, b, c, and d matrices from above.

b) Specify b as the initial condition.

c) Use a constant input of zero and send the output to the workspace (use y4 as the return variable).

d) In the Simulation / Configuration Parameters / Data Import/Export enter t4 as the return variable for the simulations time vector.

e) Set the initial step size (in Solver Configuration Parameters) to 0.01 and the maximum step size to 0.1 and use the ode45 algorithm with a stop time of 6.

f) Run the simulation and plot t4 versus y4:

plot(t4,y4) 

0 Comments

MathWorks Support Team

Contact us