How to use Lags and delay in simulink : tutorial 9

In this tutorial, I will explain you the working of lags and delays in Simulink. Lags and delays seem to be a similar term but in fact they are not. In this tutorial we will discuss that particular difference between lags and delays. In simulink there are multiple blocks that can do the delay operation with a little distinction in their functionality. We will also discuss that distinction in this tutorial along with the working and implementation of each block. I will provide you with a comprehensive example regarding the working of delays (two types from the simulink library browser) i.e. Delay block and Transport delay block also I will explain the working of lags in the output or response of a system and their difference.

How to use Lags and delay in simulink

  • Open MATLAB and then open Simulink as we have been doing in previous tutorials. Now create a new blank model from Simulink and save it so we can use it in future. In the blank model, click on the library browser icon as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 1: Library browser

  • Now first of all we want a source on which we will apply delays and see lags in them therefore, in library browser click on the sources block from where we will select the required source as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 2: Sources blocks

  • Now from the sources section of library block select the blocks named as step at the output of this block we will receive a step input. Refer to the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 3: Step

  • This block will be used as input and delays and lags will be applied on this input waveform as you will see shortly. Right click on this block and click on Add block to the model to add the block to the model you created previously as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 4: Adding to model

  • Now we also need a sink or an output block at which we will see the delayed and lagged output. Therefore, from the library browser select the sinks section as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 5: Sinks

  • From this section select the block named scope as we have been using in all the previous tutorials and add the block to the model as we have done previously. Now double click on the step block and from the block parameters dialog box, change the step time of the step input to 2 as shown in the figure below, so that the input and all the delayed blocks are visible at the oscilloscope output.How to use Lags and delay in simulink : tutorial 9

Figure 6: Step time

  • Connect the step block to the scope block as shown in the figure below,How to use Lags and delay in simulink : tutorial 9How to use Lags and delay in simulink : tutorial 9

Figure 7: Diagram

  • Run the blocks from the run button as shown in the figure below,

Figure 8: Running

  • After running the block double click on the scope to see the output and the output of the step is shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 9: Step input

  • Now let’s apply the delay function on the input step. For that purpose, open the commonly used blocks section of the library browser and select the delay block as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 10: Delay block

  • As we are interested in viewing both the input and the delayed input on the same window hence we will increase the number of input ports from 1 to 2. We can do this by simply right clicking on the delay block then click on the signals and ports label then on number of input ports and then on 2 as shown in the figure below, this will change the number of ports of the scope block to two.How to use Lags and delay in simulink : tutorial 9

Figure 11: Input ports

  • Connect the simple input to one input port of scope block and the delayed input to the other as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 12: Diagram

  • Run the blocks and again open the scope window by double clicking on the scope block. The normal input and the delayed input are shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 13: Delayed output

  • We can also change the delayed time of the block by double clicking on the delay block and changing the value parameter in the delay block. The delayed output with a different delay time is shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 14: Changed delay

  • Now let’s see the functionality of a different delay block in simulink. From the library browser select the continuous section as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 15: Continuous block

  • From the continuous block of library browser select the block named as transport delay as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 16: Transport delay

  • Add the block to the model and after that double click on the block and from the block parameters you can change the delay time of the block. For example, I set the delay time of 5 sec here as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 17: Delay time

  • Now as we have three different inputs to display on oscilloscope so we need to change the number of input ports of oscilloscope to 3 as we have done previously as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 18: Number of ports

  • Connect the newly created delayed output to the third input port of the scope as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 19: Diagram

  • The input of the step and the two delayed inputs as the outputs are displayed simultaneously on the same graph in the scope when you run the block diagram as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 20: Delayed outputs

  • The red wave in the above graph is the input of the step block, the yellow is the output of the delay block and the blue is the output of the transport delay block. The difference in the outputs of the delayed blocks is visible from the graphs shown in the figure above. The small slope of in the transport delay blocks’ output is also referred as a lag which occurs in all the physical circuits of real time. Lets’ discuss this lag operation further more using another different block. From the continuous section of the library browser select the transfer function block as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 21: Transfer function block

  • Place that transfer function block in the model and at the input of it connect the step input and at the output connect the output. But first you must change the number of input ports of the scope as we have done previously. The connected diagram is shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 22: Diagram

  • Now run the block diagram and double click on the scope block to see the output. As there are multiple outputs it might be difficult for you to recognize which output is who’s. Therefore, from the scope window, click on the view label at the top a drop down will appear and from that drop down check the label named as legends as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 23: Legends

  • These legends will assign proper names to each waveform as shown in the figure below,How to use Lags and delay in simulink : tutorial 9

Figure 24: Output

  • The lagged output is the red one, and is same as the input but it is showing the real time effect of the normal step input function.

Leave a Comment

shares