MATLAB Simulink – Useful Resources ”; Previous Next MATLAB (Matrix Laboratory) is a programming language developed by a computer software company MathWorks. Simulink is a simulation and model-based design environment for dynamic and embedded systems, which are integrated with MATLAB. Simulink is also developed by MathWorks. This tutorial is designed to give students fluency in MATLAB Simulink. Problem-based examples have also been given in simple and easy way to make your learning fast and effective. Useful Links on MATLAB Simulink MATLAB Simulink Wiki − Wikipedia Reference for MATLAB Simulink. MATLAB Simulink − Official website of MATLAB Simulink. Useful Books on MATLAB Simulink To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Category: Computer Programming
MATLAB Simulink – For Loop
MATLAB Simulink – For Loop ”; Previous Next In this chapter, let us understand the working of for-iterator block. First, create a blank model as shown below − In this model, we are going to make use of for iterator that will give us the sum of 1..N. You can use the value of n as per your choice. This value will take the constant block and update it with value 5 as shown below − Let us add the for-iterator block as shown below − Select the for Iterator subsystem block and add to your model. Next, we need display block as shown below − Connect the blocks as shown below − The for iterator block is a subsystem. Select the block and click enter. It will take you to new model area, where the for block has to be defined. Right click on the for iterator and select the block parameters, as shown below − Change the States when starting as reset and Iteration limit source as external. Click on Ok to update the changes. Now, you will get an input block to your for loop, as given below − We need a sum block and a delay block as shown below − The delay block has to be flipped so that it can be added to the output. We need to give the output back to the sum block so that it can be added with the current iteration. Right click on delay block and change the delay length from 2 to 1 as shown below. Click on OK to update the changes. The final for-loop subsystem block will look as follows − Now before you run the simulation, change the stop time to 1. We do this because we want the simulation to run only once. Click on Run now to see the result in display block as shown below The input value is 5, so the for-loop will go from 1 to 5. Hence, the values 1+2+3+4+5 = 15 is shown in the display. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Build & Simulate Model ”; Previous Next We have seen the Simulink library browser and the blocks available in the library list. In this chapter, we are going to use the blocks to build a simple sine wave model. Open Simulink and click on blank model as shown below − The blank model will open a blank popup window as shown below − Now, open the Simulink Library browser so that we can select the blocks. The following screen will appear on your computer To move the sine wave to your model, select the block and drag it inside your model workspace. We want to display the sine wave and here, we have taken four sign wave in our model workspace as shown below − Now we want to display the output of the signal, so let us use a Scope block from sinks library as shown below − Now select and drag the Scope block inside your model workspace. The sine wave has one output and the scope block has one input. We have four sine waves displayed. We have to change the parameters of scope block to take four inputs. Right click on scope block and click on Block Parameters and it will display the screen as shown below − Go to settings icon and change the input parameter from 1 to 4 as shown below − Click on Apply to save the changes. Let us now connect the sine wave to the scope block with arrows as shown below − We would like to change the frequency of each sine wave to a different one, so that we get a signal graph of different frequencies. So right click on sine wave and open the Sine wave block parameters as shown below − We are going to keep the amplitude as 1 for all sine waves and the frequency of the first sine wave is 1, second one is 3, third one is 6 and the last one is 10. Click on the Run button as shown below to see the sine wave. Open the scope block parameters to see the sine wave as shown below. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Environment Setup ”; Previous Next MATLAB simulink is a MATLAB product and to work with it, we need to download MATLAB. The official website of matlab is https://www.mathworks.com/ The following page will appear on your screen − To download MATLAB go to https://in.mathworks.com/downloads/ as shown below. MATLAB is not free to download and you need to pay for the licensed copy. Later on you can download it. A free trial version is available for which you have to create a login for your respective account. Once an account is created, they allow you to download MATLAB and also an online version for a trial of 30 days’ license. Once you are done with the creating a login from their website, download MATLAB and install on your system. Then, start MATLAB or you can also make use of their online version. Simulink comes in-built with MATLAB. Once you install MATLAB, you will get Simulink as shown below − Print Page Previous Next Advertisements ”;
MATLAB Simulink – Mathematical Library ”; Previous Next In this chapter, we will learn how to sum the two given signals and get the output. Select the blank model and open Simulink library browser as shown below − We are going to combine chirp signal and sine wave blocks by using add block from Mathoperation and see the final display. Let us pick the block we want. Select chirp signal and sine wave from sources library, add block from math operations, scope block from sinks library. Join the lines to each block. Double click chirp signal and change the initial frequency from 0.1 to 0.05 and click on Ok button. The other blocks are kept as the default values. Now, click on run to see the output in scope as shown below. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Signals Processing ”; Previous Next In this chapter, we will understand the signals generation in Simulink. To start with, select a blank model from Simulink page and open Simulink browser library as shown below − In sources library, you will get a signal generator symbol. It will help us to create different types of signals. Select the Signal Generator and drag it to get inside the blank model as shown below − To see the output of the signal generator, we need one more block called scope from sinks library as shown below − Select the block and drag it to get inside the model. Double click on signal generator or right click and select block parameters and it will display a screen as shown below − The signal generator can show waveforms like sine, square, sawtooth, random. We will select the square waveform. Let the amplitude and frequency be as 1. Click on OK to update the changes made. Now, connect the lines between signal generator and scope block as shown below − Now click on Run button to see the square waveform as shown below − Let us now try the sawtooth wave form. Right click signal generator or double click and change the waveform to sawtooth. Let us change the frequency to 2. Click on OK to update the changes. Now run the model to see the changes as shown below − Let us now add some more signals to the above model. We will take the step signal from the sources library as shown below − We just have one input for the scope block. Let us increase it to 2 inputs. Right click and open the block parameters. Click on OK button to update the changes. Now, the scope block has 2 inputs as shown below − Connect the step input arrow with the scope arrow. Now click on Run button to run the model. You can add some more signals and test the same. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Adding Delay To Signals ”; Previous Next We have learnt in the previous chapter about the different signal simulations. In this chapter, we will learn how to add delay to the signals. Let us take a blank model and add sine wave and scope block to it as shown below − Let us now run the model to see the simulation in scope block. The sine wave is as shown below − Let us now add delay for the sine wave. We will make use of transport delay block from continuous library as shown below − Select the block and drag it in your model canvas. Now that we have the Transport delay in our model, right click on it and open block parameters as shown below − Let us change the time delay from 1 to 3. Make the changes and click on OK button. Now add one more input port to scope block. Right click on scope block and select the signals and ports. Select 2 for number of input ports as shown below − Now connect the transport delay to sine wave and to scope as shown below Now run the simulation to see a delay of 3 seconds to the sign wave. Right click scope block and select block parameters to see the display. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Export Data ”; Previous Next In this chapter, we will learn how to use Simulink output results inside MATLAB. Let us try a simple model of sine wave as shown below − When we run the model, the scope displays the sine wave as shown below − Now to get the data of the sine wave, go to the configuration properties and select logging tab. Select the log data to workspace checkbox, as shown below − Set the variable name of your choice. Here, we have given the name as swave and the save format as Array. Click on OK button and run the simulation again. You should see the output in the workspace Double click and it will show you the details of the swave variable which we saved earlier. Inside command prompt type out .swave and it will give you the output as shown below − You can plot the sine wave using plot command as shown below − The graph is shown as follows − Print Page Previous Next Advertisements ”;
MATLAB Simulink – Function
MATLAB Simulink – Function ”; Previous Next In this chapter we will understand how to make use of MATLAB function in Simulink. Open Simulink and click on blank model. We need a constant block, a MATLAB function block and a display block for the output. Here is the model created − The MATLAB function is available inside the user defined functions library. Now, click on MATLAB function and drag it inside your model canvas. Double click on the MATLAB function block and write a function of your choice. We will try to display 1 if the number given is odd and 0 if it is even. You can also save the function to be used later with another one. Once the function is done click on the upward arrow close to the MATLAB function and it will take you back to the model you created earlier. Now, let us test the model by using the constant value as 5. We can see the display as 1, which indicates that the value 5 is an odd number. Let us now change the constant value to 10 as shown below and run the simulation: The output is 0 indicating it is even number. Print Page Previous Next Advertisements ”;
MATLAB Simulink – Script
MATLAB Simulink – MATLAB Script ”; Previous Next In this chapter, we will use MATLAB script to create a model. We do have a direct and easy method to create a model by just picking the blocks we need. But, writing the code to create a model can sometimes help you to automate a task as your projects get complex. So, let us learn how to create models by using the Application Programming Interfaces (APIs) as discussed below. We will create a very simple sine wave model. For that we need sine wave and scope blocks. Inside the MATLAB command window, we can use API to create the model and blocks. To create a new model, the API is as follows − new_system(”matlabmodel”) Here, matlabmodel is the name of the model. You can open the model by using open_system() with the name of the model as parameter to the function. The command is as shown below − open_system(”matlabmodel”) When you click enter, the model is opened as shown below − Now, let us add sine wave block to it. The command is to add_block(source, dest). You will get the source of the block from Simulink library browser. The highlighted code is the source of sine wave. Let us add that in the add_block as shown below − add_block(”simulink/Sources/Sine Wave”,”matlabmodel/Sine”) The following screen will appear on your computer − Let us now add the scope block, as mentioned below − add_block(”simulink/Sinks/Scope”,”matlabmodel/Scope”, ‘Position’ , [200 315 135 50]) The model shows the scope block as shown below − You can make use of position inside the add_block to position the block properly. For example, add_block(‘simulink/Sinks/Scope’, ‘matlabmodel/Scope’, ‘Position’ , [200 315 135 50] Now, let us connect the line between the sine wave and scope by using the command as shown below − add_line(”matlabmodel”, ”Sine/1”, ”Scope/1”); For add_line, you have to pass the name of your model, followed by the block name and the input port of the blocks. So now, we want to connect the first output port of sine wave with the first input port of scope. Let us now run the simulation by using the command below − result = sim(”matlabmodel”); Now to view the simulation result, run one more command as shown below − open_system(”matlabmodel/Scope”); You will get the output inside the scope as follows − Print Page Previous Next Advertisements ”;