Main Content

impulse

Impulse response plot of dynamic system; impulse response data

    Description

    Impulse Response Plots

    example

    impulse(sys)plots the response of a dynamic system model to an impulse input. The modelsyscan be continuous or discrete.

    • For continuous-timesys, the impulse input is the Dirac impulseδ(t). For continuous-timesyswith direct feedthrough,impulseignores the infinite pulse att = 0.

    • For discrete-timesyswith sample timeTs, the function computes the response to a unit-area pulse of lengthTsand height1/Ts. This pulse approaches the continuous-time Dirac impulseδ(t)asTsgoes to zero.

    syscan be SISO or MIMO. For MIMO systems, the plot displays the impulse responses for each I/O channel.impulseautomatically determines the time steps and duration of the simulation based on the system dynamics.

    example

    impulse(sys,tFinal)simulates the impulse response fromt = 0to the final timet = tFinal. The function uses system dynamics to determine the intervening time steps.

    example

    impulse(sys,t)plots the impulse response at the times that you specify in the vectort.

    example

    impulse(sys,t,p)plots the impulse response for LPV model with parameter trajectoryp.

    example

    impulse(sys1,sys2,...,sysN,___)plots the impulse response of multiple dynamic systems on the same plot. All systems must have the same number of inputs and outputs. You can use multiple dynamic systems with any of the previous input-argument combinations.

    example

    impulse(sys1,LineSpec1,...,sysN,LineSpecN,___)specifies a color, line style, and marker for each system in the plot. You can useLineSpecwith any of the previous input-argument combinations. When you need additional plot customization options, useimpulseplotinstead.

    example

    impulse(___,config)specifies additional options for computing the impulse response, such as the amplitude or input offset. UseRespConfigto create the option setconfig. You can useconfigwith any of the previous input-argument and output-argument combinations.

    Impulse Response Data

    example

    y= impulse(sys,t)returns the impulse responsesysat the times specified in the vectort. This syntax does not draw a plot.

    y= impulse(sys,t,p)also specifies the parameter trajectorypfor LPV models.

    [y,tOut] = impulse(sys)also returns a vector of timestOutcorresponding to the responses iny. If you do not provide an input vectortof times,impulsechooses the length and time step oftOutbased on the system dynamics.

    [y,tOut] = impulse(sys,tFinal)computes the impulse response up to the end timetFinal.impulsechooses the time step oftOutbased on the system dynamics.

    example

    [y,t,x] = impulse(sys)also returns the state trajectoriesx, whensysis a state-space model such as anssoridssmodel.

    example

    [y,t,x,ysd] = impulse(sys,___)also computes the standard deviationysdof the impulse responsey, whensysis an identified model such as anidss,idtf, oridnlarxmodel.

    [y,t,x,~,pOut] = impulse(sys,t,p,___)also returns parameter trajectoriespOut, whensysis anlpvssmodel.

    example

    [___] = impulse(___,config)specifies additional options for computing the impulse response, such as the amplitude or input offset. UseRespConfigto create the option setconfig. You can useconfigwith any of the previous input-argument and output-argument combinations.

    Examples

    collapse all

    Plot the impulse response of a continuous-time system represented by the following transfer function.

    sys ( s ) = 4 s 2 + 2 s + 10

    For this example, create atfmodel that represents the transfer function. You can similarly plot the impulse response of other dynamic system model types, such as zero-pole gain (zpk) or state-space (ss) models.

    sys = tf(4,[1 2 10]);

    Plot the impulse response.

    impulse(sys)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sys.

    Theimpulseplot automatically includes a dotted horizontal line indicating the steady-state response. In a MATLAB® figure window, you can right-click on the plot to view other impulse-response characteristics such as peak response and transient time.

    Plot the impulse response of a discrete-time system. The system has a sample time of 0.2 s and is represented by the following state-space matrices.

    A = [1.6 -0.7; 1 0]; B = [0.5; 0]; C = [0.1 0.1]; D = 0;

    状态空间模型创建和情节的冲动response.

    sys = ss(A,B,C,D,0.2); impulse(sys)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sys.

    The impulse response reflects the discretization of the model, as it shows the response as computed every 0.2 seconds.

    Examine the impulse response of the following zero-pole-gain model.

    sys = zpk(-1,[-0.2+3j,-0.2-3j],1) * tf([1 1],[1 0.05])
    sys = (s+1)^2 ---------------------------- (s+0.05) (s^2 + 0.4s + 9.04) Continuous-time zero/pole/gain model.
    impulse(sys)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sys.

    By default,impulsechooses an end time that shows the steady state that the response is trending toward. To get a closer look at the transient response, limit the impulse plot tot= 20 s.

    impulse(sys,20)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sys.

    Alternatively, you can specify the exact times at which you want to examine the impulse response, provided they are separated by a constant interval. For instance, examine the response from the end of the transient until the system reaches steady state.

    t = 20:0.2:120; impulse(sys,t)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sys.

    Even though this plot begins att= 20,impulsealways applies the impulse input att= 0.

    Consider the following second-order state-space model:

    [ x ˙ 1 x ˙ 2 ] = [ - 0 . 5 5 7 2 - 0 . 7 8 1 4 0 . 7 8 1 4 0 ] [ x 1 x 2 ] + [ 1 - 1 0 2 ] [ u 1 u 2 ] y = [ 1 . 9 6 9 1 6 . 4 4 9 3 ] [ x 1 x 2 ]

    一个= (-0.5572,-0.7814,0.7814,0);B = (1, - 1, 0, 2);C= [1.9691,6.4493]; sys = ss(A,B,C,0);

    This model has two inputs and one output, so it has two channels: from the first input to the output and from the second input to the output. Each channel has its own impulse response.

    When you useimpulse, it computes the responses of all channels.

    impulse(sys)

    Figure contains 2 axes objects. Axes object 1 with title From: In(1) contains an object of type line. This object represents sys. Axes object 2 with title From: In(2) contains an object of type line. This object represents sys.

    The left plot shows the impulse response of the first input channel, and the right plot shows the impulse response of the second input channel. Whenever you useimpulseto plot the responses of a MIMO model, it generates an array of plots representing all the I/O channels of the model. For instance, create a random state-space model with five states, three inputs, and two outputs, and plot its impulse response.

    sys = rss(5,2,3); impulse(sys)

    Figure contains 6 axes objects. Axes object 1 with title From: In(1), ylabel To: Out(1) contains an object of type line. This object represents sys. Axes object 2 with ylabel To: Out(2) contains an object of type line. This object represents sys. Axes object 3 with title From: In(2) contains an object of type line. This object represents sys. Axes object 4 contains an object of type line. This object represents sys. Axes object 5 with title From: In(3) contains an object of type line. This object represents sys. Axes object 6 contains an object of type line. This object represents sys.

    In a MATLAB figure window, you can restrict the plot to a subset of channels by right-clicking on the plot and selectingI/O Selector.

    impulseallows you to plot the responses of multiple dynamic systems on the same axis. For instance, compare the closed-loop response of a system with a PI controller and a PID controller. Create a transfer function of the system and tune the controllers.

    H = tf(4,[1 2 10]); C1 = pidtune(H,'PI'); C2 = pidtune(H,'PID');

    Form the closed-loop systems and plot their impulse responses.

    sys1 = feedback(H*C1,1); sys2 = feedback(H*C2,1); impulse(sys1,sys2) legend('PI','PID','Location','SouthEast')

    Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent PI, PID.

    By default,impulsechooses distinct colors for each system that you plot. You can specify colors and line styles using theLineSpecinput argument.

    impulse(sys1,'r--',sys2,'b') legend('PI','PID','Location','SouthEast')

    Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent PI, PID.

    The firstLineSpec'r--'specifies a dashed red line for the response with the PI controller. The secondLineSpec'b'specifies a solid blue line for the response with the PID controller. The legend reflects the specified colors and linestyles. For more plot customization options, useimpulseplot.

    The exampleCompare Impulse Response of Multiple Systemsshows how to plot responses of several individual systems on a single axis. When you have multiple dynamic systems arranged in a model array,impulseplots all their responses at once.

    Create a model array. For this example, use a one-dimensional array of second-order transfer functions having different natural frequencies. First, preallocate memory for the model array. The following command creates a 1-by-5 row of zero-gain SISO transfer functions. The first two dimensions represent the model outputs and inputs. The remaining dimensions are the array dimensions.

    sys = tf(zeros(1,1,1,5));

    Populate the array.

    w0 = 1.5:1:5.5;% natural frequencieszeta = 0.5;% damping constantfori = 1:length(w0) sys(:,:,1,i) = tf(w0(i)^2,[1 2*zeta*w0(i) w0(i)^2]);end

    (For more information about model arrays and how to create them, seeModel Arrays.) Plot the impulse responses of all models in the array.

    impulse(sys)

    Figure contains an axes object. The axes object contains 5 objects of type line. This object represents sys.

    impulseuses the same linestyle for the responses of all entries in the array. One way to distinguish among entries is to use theSamplingGridproperty of dynamic system models to associate each entry in the array with the correspondingw0value.

    sys.SamplingGrid = struct('frequency',w0);

    Now, when you plot the responses in a MATLAB figure window, you can click a trace to see which frequency value it corresponds to.

    When you give it an output argument,impulsereturns an array of response data. For a SISO system, the response data is returned as a column vector of length equal to the number of time points at which the response is sampled. You can provide the vector t of time points, or allowimpulseto select time points for you based on system dynamics. For instance, extract the impulse response of a SISO system at 101 time points betweent= 0 andt= 5 s.

    sys = tf(4,[1 2 10]); t = 0:0.05:5; y = impulse(sys,t); size(y)
    ans =1×2101 1

    For a MIMO system, the response data is returned in an array of dimensionsN-by-Ny-by-Nu, whereNyandNu是dynami的输出和输入的数量吗c system. For instance, consider the following state-space model, representing a two-input, one-output system.

    一个= (-0.5572,-0.7814,0.7814,0);B = (1, - 1, 0, 2);C= [1.9691,6.4493]; sys = ss(A,B,C,0);

    Extract the impulse response of this system at 200 time points betweent= 0 andt= 20 s.

    t = linspace(0,20,200); y = impulse(sys,t); size(y)
    ans =1×3200 1 2

    y(:,i,j)is a column vector containing the impulse response from thejth input to theith output at the timest. For instance, extract the impulse response from the second input to the output.

    y12 = y(:,1,2); plot(t,y12)

    Figure contains an axes object. The axes object contains an object of type line.

    Compare the impulse response of a parametric identified model to a non-parametric (empirical) model. Also view their 3 σ confidence regions.

    Load the data.

    loadiddata1z1

    Estimate a parametric model.

    sys1 = ssest(z1,4);

    Estimate a non-parametric model.

    sys2 = impulseest(z1);

    Plot the impulse responses for comparison.

    t = (0:0.1:10)'; [y1, ~, ~, ysd1] = impulse(sys1,t); [y2, ~, ~, ysd2] = impulse(sys2,t); plot(t, y1,'b', t, y1+3*ysd1,'b:', t, y1-3*ysd1,'b:') holdonplot(t, y2,'g', t, y2+3*ysd2,'g:', t, y2-3*ysd2,'g:')

    Figure contains an axes object. The axes object contains 6 objects of type line.

    Compute the impulse response of an identified time-series model.

    A time-series model, also called a signal model, is one without measured input signals. The impulse plot of this model uses its (unmeasured) noise channel as the input channel to which the impulse signal is applied.

    Load the data.

    loadiddata9;

    Estimate a time-series model.

    sys = ar(z9, 4);

    sysis a model of the formA y(t) = e(t), wheree(t)represents the noise channel. For computation of impulse response,e(t)is treated as an input channel, and is namede@y1.

    Plot the impulse response.

    impulse(sys)

    Figure contains an axes object. The axes object with title From: e@y1 To: y1 contains 2 objects of type line. One or more of the lines displays its values using only markers This object represents sys.

    Create a state-space model.

    A = [-0.8429,-0.2134;-0.5162,-1.2139]; B = [0.7254,0.7147;0,-0.2050]; C = [-0.1241,1.4090;1.4897,1.4172]; D = [0.6715,0.7172;-1.2075,0]; sys = ss(A,B,C,D);

    Create a default option set and use the dot notation to specify values.

    respOpt = RespConfig; respOpt.InputOffset = [-2,3]; respOpt.Amplitude = [2,-0.5]; respOpt.InitialState = [0.1,-0.1]; respOpt.Delay = 5;

    Compute the impulse response.

    t = 0:0.1:20; impulse(sys,t,respOpt)

    Figure contains 4 axes objects. Axes object 1 with title From: In(1), ylabel To: Out(1) contains an object of type line. This object represents sys. Axes object 2 with ylabel To: Out(2) contains an object of type line. This object represents sys. Axes object 3 with title From: In(2) contains an object of type line. This object represents sys. Axes object 4 contains an object of type line. This object represents sys.

    This example shows how to simulate the impulse response of an LPV model. This example simulates the closed-loop response of a levitating ball model defined infcnMaglev.mto a disturbance du .

    maglev-feedback.png

    You must set the reference to h 0 to properly initialize the system and maintain it around h = h 0 .

    Create the model and discretize it.

    hmin = 0.05; hmax = 0.25; h0 = (hmin+hmax)/2; Ts = 0.01; Glpv = lpvss("h",@fcnMaglev,0,0,h0); Glpvd = c2d(Glpv,Ts,'tustin');

    Sample the LPV model for three height values and tune a PID controller.

    hpid = linspace(hmin,hmax,3); [Ga,Goffset] = sample(Glpvd,[],hpid); wc = 50; Ka = pidtune(Ga,'pidf',wc); Ka.Tf = 0.01;

    Create the gain-scheduled PID controller.

    Ka.SamplingGrid = struct('h',hpid); Koffset = struct('y',{Goffset.u}); Clpv = ssInterpolant(ss(Ka),Koffset);

    Create the closed-loop model.

    CL = feedback(Glpvd*[1,Clpv],1,2,1); CL.InputName = {'du';'href'}; CL.OutputName ='h';

    Get steady-state current for h = h 0 to size the disturbance

    [~,~,~,~,~,~,~,u0] = Glpv.DataFunction(0,h0);

    Response to impulse change in du and h 0 .

    t = 0:Ts:2; pFcn = @(k,x,u) x(1); Config = RespConfig('InputOffset',[0;h0],'Amplitude',0.2*[u0;h0]*Ts,'Delay',0.5,'InitialParameter',h0); impulse(CL,t,pFcn,Config) title('Impulse disturbance in current and impulse change in height')

    Figure contains 2 axes objects. Axes object 1 with title From: du, ylabel To: h contains an object of type line. This object represents CL. Axes object 2 with title From: href contains an object of type line. This object represents CL.

    Input Arguments

    collapse all

    Dynamic system, specified as a SISO or MIMO dynamic system model or array of dynamic system models. Dynamic systems that you can use include:

    • Continuous-time or discrete-time numeric LTI models, such astf,zpk, orssmodels.

    • Generalized or uncertain LTI models such asgenssorussmodels. (Using uncertain models requires Robust Control Toolbox™ software.)

      • For tunable control design blocks, the function evaluates the model at its current value for both plotting and returning response data.

      • For uncertain control design blocks, the function plots the nominal value and random samples of the model. When you use output arguments, the function returns response data for the nominal model only.

    • Sparse state-space models such assparssandmechssmodels. You must specify final timetFinalfor sparse state-space models.

    • Identified LTI models, such asidtf,idss, oridprocmodels. For such models, the function can also plot confidence intervals and return standard deviations of the frequency response.(Using identified models requires System Identification Toolbox™ software.)

    • Linear time-varying (ltvss) and linear parameter-varying (lpvss) models.

    impulsedoes not support frequency-response data models such asfrd,genfrd, oridfrdmodels.

    Ifsysis an array of models, the function plots the responses of all models in the array on the same axes.

    End time for impulse response, specified as a positive scalar value.impulsesimulates the impulse response fromt = 0tot =tFinal.

    • For continuous-time systems, the function determines the step size and number of points automatically from system dynamics. ExpresstFinalin the system time units, specified in theTimeUnitproperty ofsys.

    • For discrete-time systems, the function uses the sample time ofsysas the step size. ExpresstFinalin the system time units, specified in theTimeUnitproperty ofsys.

    • For discrete-time systems with unspecified sample time (Ts = -1),impulseinterpretstFinalas the number of sampling periods to simulate.

    Time vector at which to compute the impulse response, specified as a vector of positive scalar values. Expresstin the system time units, specified in theTimeUnitproperty ofsys.

    • For continuous-time models, specifytin the formT0:dt:Tf. To obtain the response at each time step, the function usesdtas the sample time of a discrete approximation to the continuous system. The simulation starts atT0and ends atTf

    • For discrete-time models, specifytin the formT0:Ts:Tf, whereTsis the sample time ofsys.

    Parameter trajectory of the LPV model, specified as a matrix or a function handle.

    • For exogenous or explicit trajectories, specifypas a matrix with dimensionsN-by-Np, whereNis the number of time samples andNpis the number of parameters.

      Thus, the row vectorp(i,:)contains the parameter values at theith time step.

    • For endogenous or implicit trajectories, specifypas a function handle of the formp=F(k,x,u)that gives parameters as a function of time samplek, statex, and inputu.impulseonly supports this option for discrete-time LPV models.

      This option is useful when you want to simulate quasi-LPV models.

    Configuration of the applied impulse signal, specified as aRespConfigoption set. By default,impulseapplies an input at timet = 0. Use this input argument to change the response configuration such as specify delay or input offset. SeeConfigure Options for Impulse Responsefor an example.

    Forlpvssandltvssmodels with offsets (x0(t),u0(t)), you can useRespConfigto define the input relative tou0(t,p) and initialize the simulation with the statex0(t,p).

    Line style, marker, and color, specified as a string or vector of one, two, or three characters. The characters can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line. For more information about configuring this argument, see theLineSpecinput argument of theplotfunction.

    Example:'r--'specifies a red dashed line

    Example:'*b'specifies blue asterisk markers

    Example:'y'specifies a yellow line

    Output Arguments

    collapse all

    Impulse response data, returned as an array.

    • For SISO systems,yis a column vector of the same length ast(if provided) ortOut(if you do not providet).

    • For single-input, multi-output systems,yis a matrix with as many rows as time samples and as many columns as outputs. Thus, thejth column ofy, ory(:,j), contains the impulse response of from the input to thejth output.

    • For MIMO systems, the impulse responses of each input channel are stacked up along the third dimension ofy. The dimensions ofyare thenN-by-Ny-by-Nu, where:

      • Nis the number of time samples.

      • Nyis the number of system outputs.

      • Nuis the number of system inputs.

      Thus,y(:,i,j)is a column vector containing the impulse response from thejth input to theith output at the times specified intortOut.

    Times at which impulse response is computed, returned as a vector. When you do not provide a specific vectortof times,impulsechooses this time vector based on the system dynamics. The times are expressed in the time units ofsys.

    State trajectories, returned as an array. Whensysis a state-space model,xcontains the evolution of the states ofsysat each time intortOut. The dimensions ofxareN-by-Nx-by-Nu, where:

    • Nis the number of time samples.

    • Nxis the number of states.

    • Nuis the number of system inputs.

    Thus, the evolution of the states in response to an impulse injected at thekth input is given by the arrayx(:,:,k). The row vectorx(i,:,k)contains the state values at theith time step.

    Standard deviation of the impulse response of an identified model, returned as an array of the same dimensions asy. Ifsysdoes not contain parameter covariance information, thenysdis empty.

    Parameter trajectories, returned as an array. Whensysis a linear-parameter varying model,pOutcontains the evolution of the parameters ofsysat each time intortOut. The dimensions ofpOutareN-by-Np-by-Nu, where:

    • Nis the number of time samples.

    • Npis the number of parameters.

    • Nuis the number of system inputs.

    Thus, the evolution of the parameters in response to a signal injected at thekth input is given by the arraypOut(:,:,k). The row vectorpOut(i,:,k)contains the parameter values at theith time step.

    Limitations

    • The impulse response of a continuous system with nonzeroDmatrix is infinite att=0.impulseignores this discontinuity and returns the lower continuity valueCbatt=0.

    • Theimpulsecommand does not work on continuous-time models with internal delays. For such models, usepadeto approximate the time delay before computing the impulse response.

    • Theimpulsecommand does not support simulation along an implicit parameter trajectory for continuous-time LPV models.

    Tips

    • When you need additional plot customization options, useimpulseplotinstead.

    • 如果模拟系统对任意输入gnals, uselsim.

    Algorithms

    Continuous-time LTI models are first converted to state-space form. The impulse response of a single-input state-space model

    x ˙ = A x + b u y = C x

    is equivalent to the following unforced response with initial stateb.

    x ˙ = A x , x ( 0 ) = b y = C x

    To simulate this response, the system is discretized using zero-order hold on the inputs. The sample time is chosen automatically based on the system dynamics, except when a time vectort = T0:dt:Tfis supplied. Hence,dtis used as sample time.

    Version History

    Introduced before R2006a

    expand all