Discrete step response

To plot a step response of a discrete system, we will use two separate Matlab functions, dstep and stairs. The dstep will be used to obtain N number of output sample points, where N is supplied by an user. The stairs plots a stairstep graph of supplied vectors, namely the time vector [t] and the amplitude vector [x].

1. Transfer function

First, we will introduce to you how to use these two functions to obtain a step response of a given discrete transfer function. Suppose you have the following transfer function

We will use the dstep to obtain a vector of sample points. Create an m-file and enter the following commands.

```
numDz=[0.05 0.05];
denDz=[1 -1.6 0.7];

IU=1; 	%This is the input value

N=101;
[x] = dstep (IU*numDz,denDz, N)
```
Running this m-file in the command window gives you 101 sample points.

Notice that the function dstep does not consider the time vector [t]; instead, it considers the number of sample points (N). In deed, if you take out the left hand side argument [x] from the dstep(numDz,denDz) command, you get the step response of the system as a function of sample (k), not as a function of time (Try this yourself).

To obtain a response as a function of time, first, we need to consider the relationship between the number of samples and the sampling time (Ts). Let's say our digital control system has the sampling time of t sec/sample. Using this digital control system, it takes t*(N-1) seconds to obtain N samples. For example, if above 101 samples were taken with the system having a sampling time of 0.05 sec/sample, the total sampling period equals to 5 seconds. If you plot this, it looks like the following.

The function stairs connects these sample points in a way that it represents the output y(k) preceded by zero-order hold. Let's use stairs to connect these sample points. Add the following commands to the above m-file and rerun it. You should get the following stairstep response.

```
t=0:0.05:5;
stairs (t,x)
```

2. State-Space

To obtain a step response from the state-space model, we will follow the same procedure as what we did for the transfer function. The only difference is that we now deals with matrices F, G, H, and J instead of num and den matrices. Suppose we have the following state-space model

Note: This state-space represents the same system as the above transfer function

The following commands will plot a stairstep response of the system represented by this state-space model. Copy these commands to an new m-file and run it.

```
F = [1.6 -0.7
1	   0];

G = [1
0];

H = [0.05 0.05];

J = [0];

N=101;
IU=1;	%Input value
[x] = dstep (F,G,H,J,IU,N)

t=0:0.05:5;
stairs (t,x)
```

You should see the same plot as the one shown above.