How to create a GUI in MATLAB ?

Hello friends, I hope you all are fine and enjoying life. Today i am going to share a new project tutorial which is How to create a GUI in MATLAB ? First of all, lets have a little introduction that what is meant by GUI? How it is created and what are the uses and applications of GUI? GUI stands for Graphical User Interface. We all know the basics of MATLAB that it is used for creating complex algorithms and to create Simulink simulation, but we don't know that it aalso has another feature which is to create GUIs. The algorithms developed in MATLAB works on the background and do their tasks while MATLAB also emphasis on the user interaction that's why it has also provided us with GUI so that we can create a user friendly front end interface for our algorithm.

So, in today's post, we are gonna have a look at How to create a GUI in MATLAB so that we could also give a user friendly front end to our algorithms. MATLAB GUI has an extensive database with a lot of functionalities, which I can't cover in one post but atleast today, I will make you able to create a simple GUI and will also explain How to control buttons and edit/text boxes etc. After performing this tutorial, you will be able to try GUI on your own.

So, today we will create a simple project in which we will create a simple GUI as shown in below image. The functionality of this GUI will be that when you click on this START button then the text,you have written in the white edit box will appear at the text box above, as shown in figure below. Let's get started with the implementation of this GUI. Follow the steps carefully and ask in comments if you got into any trouble.

You may also like to read:

You can download this GUI by clicking on the below button, but first read the tutorial completely aand try to pratice it by yourself,don''t just download the run the applicationas it won't give you any help.

Download Simple GUI Project in MATLAB

How to Create a GUI in MATLAB ?

  • First of all, when you will open your MATLAB software then, the first window opened will look like as shown in the image below.This is the simple workspace of MATLAB, now in order to open theGUI toolbar, you have to write "guide" in the workspace as I did below:
  • After writing the "guide" in command window, hit ENTER and a new small window will open up as shown in the below image, from here we will start creating our GUI.
  • As you can see in this small window, there are two tabs, one tab is named as Create New GUI, which has the options for creating your GUI for the first time while the second tab is named as Open Existing GUI, which is used for opening the already designed GUIs and as we haven't designed any GUI yet so we will remain in the first tab and will select blank GUI from the list and hit Enter.
  • Then press "OK" button and as you will complete the action, a new window will immediately open and it will look like as shown in the image given below:
  • This is the place where we are gonna create our GUI. The left side toolbar is showing the controls which we will drag aand drop in the main window and will design our GUI.
  • Let's first have a look at the left side toolbar controls. On the top left side of the bar, the first button is to select 'cursor' . Below curser button we have icon of 'Push Button'. Next to that we have 'side scroll bar'. Then comes 'Radio Button' and 'Check Box'. Then we have most important buttons which are 'Edit text bar' button and 'Static text bar' button. Below are also some other buttons and you can also explore them by simply clicking on them.
Other MATLAB Projects:
  • Now we are going to make a very small and simple interface, in which we will first select a 'button' and then we will select 'Edit text bar' and 'static text bar' and we will make the arrangement in such a way that, when we will press the button then, data will move from Edit text box to Static text box.
  • Now click on the 'button' icon and the next thing which will happen on the window will be like as shown in the image below:
 
  • Now if you want to change the properties of the button, either you want to change its name or you want to change its setting then, simply double click the button and a new window will open, which will be as:
 
  • As you can see in the above image that a new window has been opened and it has a large no of options.
  • To change the name of push button, go to 'string' option and here you can change its name.
  • In above image, you can clearly see that, i have replaced the name 'Push Button' by 'Start'.
  • Now click on the Play icon in the top toolbar which is used to run the GUI. After doing that, a new window will open, which is shown in the below image:
  • This new window in above figure is the back end programming of this GUI created automatically by MATLAB, here we are gonna add all the codes for our ontrols.
  • Now we want to add a static text box and we will select it from tool bar manually.
  • And if you again want to change its name then, we will double click on that. Go to slide option and and write whatever you want to write there.
  • All this process is shown in the below image:
 
  • Now i want to write our official site address, which  is "www.TheEngineeringProjects.com" .
  • And when i will press OK button then our GUI window will look like as shown in the below image:
  • This time, I have not only changed the name of this text box but have also changed the font size and color that's why it is appearing now in light blue color and its font size has also increased. So, now you must have the idea that you can control all the properties and can make it literaly a new thing. The only thing stopping you is your imagination. :)
  • In the same manner we will select edit text box.
  • Now by doing all this, actually i want to write some data in Edit Text Box and when i will press Start button then, data will move from Edit Text Box to Static Text Box.
  • To implement this logic we need to load a function code in 'Start' button. To load the code, right click on the Start button and a new window will open as shown in the image below:
  • As shown in the above image when you will go to the 'view callbacks' option and a next window will open direct to it and then click on the 'call back' button.
  • After that a new window will open which will be representing the code which has been uploaded in the 'Start' button.
  • This window is shown in the below image:
  • Now code has been uploaded and the very next window which will open, will be of 'Edit Text Box' .
  • Here you can write anything which you want to Display in 'Static Text Box'.
  • So in this window, i am writing my tutorials title, which is "How to create a GUI in MATLAB".
  • It can be seen in the below image:
  • When you will press Enter then, immediately an-other button will open which will be representing that our data has been moved to 'Static Text Box'.
  • As you have seen that our Final Display is same. Which means we have moved data from Edit Text Box to Static Text Box.
  • The code added in the button CallBack is as follows:
 x = get(handles.edit1,'String'); %edit1 being Tag of ur edit box if isempty(x) fprintf('Error: Enter Text firstn'); else set(handles.text2,'String',x) end
  • Have a look at this below video in which we have explained in detail How to Create a GUI in MATLAB:
Alright Friends, that was all from today's post and i hope you have learned something new. Don't feel shy to ask anything in comments. Till next tutorial take care !! :)

Send data to Serial Port in MATLAB

Hello friends, hope you all are having fun and enjoying life. In today's post we are gonna see how to send data to serial port in MATLAB. Its a requested tutorial, asked by a follower and after giving him the code, I thought to share it on our blog so that others could also get benefit from it. We have discussed serial port many times and have seen how to communicate with it using different software but we haven't yet discussed how to send data to serial port in MATLAB. So, in today's post I am gonna share the complete code for sending data to serial port in MATLAB.

Serial port is most common way of communication, we can send or receive data using serial port. Normally, in engineering projects there's a need to send or receive data from microcontrollers to computer and in such projects, we used serial communication as its easy and quite quick in communication.

Send data to Serial Port in MATLAB

  • Its a quite simple project in which I am gonna send character over the serial port in MATLAB.
  • In order to do so first of all, I am gonna create an object and assign it to serial port object in MATLAB.
  • After that I am gonna set the properties of that serial port object.
  • After setting the properties, what we need to do is simple start our serial port object.
  • Once its started, now you can send any character via that serial port object.
  • After sending your desired characters, now what you need to do is simply close the serial port.
  • Closing the serial port is very essential in MATLAB because if its left open then you can't open it again in MATLAB and you need to restart your computer so be careful.
  • Here's the simplest code for sending the data:
  • Code 1:
tep=serial('COM1', 'BaudRate', 9600); fopen(tep); fprintf(tep,'a'); fclose(tep);
  • Now you can see, its too simple, we just set the com port with which we want to communicate and after that we gave the bud rate.
  • In the next line, we open our serial port object.
  • Now as our serial port is open, we can send any character to it. In this code, I am sending 'a' to serial port in MATLAB.
  • And finally I closed the serial port, which is very necessary as otherwise when you run this code again, it will start giving error.
  • Here's a bit explanatory code and much more flexible as you can change any property of Serial Port in MATLAB, you want to change.
  • Here's the code:
  • Code 2:
clc clear all close all disp(' Welcome to TEP!!!'); disp(' '); disp(' www.TheEngineeringProjects.com'); disp(' '); tep=serial('COM1'); % assign serial port object set(tep, 'BaudRate', 9600); % set BaudRate to 9600 set(tep, 'Parity', 'none'); % set Parity Bit to None set(tep, 'DataBits', 8); % set DataBits to 8 set(tep, 'StopBit', 1); % set StopBit to 1 %display the properties of serial port object in MATLAB Window disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'})); fopen(tep); % Open Serial Port Object fprintf(tep,'a'); %Print character 'a' to the serial port disp('Charater sent to Serial Port is "a".'); fclose(tep); %Close Serial Port Object
  • The code is quite self explanatory plus I have also added the comments in the code which will help you in understanding the code but still if you have any problem, then ask in comments.
  • Here's a screen shot of the above code:
  • Wen you run this code, you will get a below response in your MATLAB window:
  • Till now, we have seen how to send a single character defined in the m file of MATLAB, now let's make it a bit complex and send user defined data.
  • Now before sending the data, we will first ask the user to enter the data, he wants to send to serial port. Tis data could be a single character or could also be a combination of characters.
  • In order to do so, we are gonna use Input command in MATLAB and code is as follows:
  • Code 3:
clc clear all close all disp(' Welcome to TEP!!!'); disp(' '); disp(' www.TheEngineeringProjects.com'); disp(' '); tep=serial('COM1'); % assign serial port object set(tep, 'BaudRate', 9600); % set BaudRate to 9600 set(tep, 'Parity', 'none'); % set Parity Bit to None set(tep, 'DataBits', 8); % set DataBits to 8 set(tep, 'StopBit', 1); % set StopBit to 1 %display the properties of serial port object in MATLAB Window disp(get(tep,{'Type','Name','Port','BaudRate','Parity','DataBits','StopBits'})); fopen(tep); % Open Serial Port Object data = input('Enter character: ', 's'); %Ask user to Enter character fprintf(tep,data); %Print character 'a' to the serial port disp('Charater sent to Serial Port is:'); disp(data); fclose(tep); %Close Serial Port Object
  • The screenshot of code is as follows: (I am adding the screen shot of code because its colored and thus helps better in understanding the code)
  • Now when you run this m file, you will get results as shown in below figure and now you can see I have sent my blog url via serial port in Matlab.
  • I think we have played enough with sending data via serial port in MATLAB, now you can send any data via serial port in MATLAB, for example you can also create an infinite loop and keep on sending data to serial port.
  • That's all for today, in the coming post I will show how to receive data via serial terminal in MATLAB, so stay tuned and also subscribe us via email to get these exciting tutorials straight in your mailbox. Take care. :)

Logical Gates in Ladder Logic for PLC

In the previous post Logical Gates in Ladder Logic for PLC, we had an overview of what is Ladder Logic programming and we have also implemented three basic Logical gates in Ladder Logic form. Today, we are gonna have a look at some complex Logical Gates in Ladder Logic for PLC. So, I hope till now you guys have basic knowledge of Ladder Logic and can implement complex logical gates in it. If you haven't read the previous post then must read because without that knowledge you won't understand this post.

In today's post we are gonna implement few complex logical gates. Its not gonna be much difficult if you have the basic concepts. I am just pointing out few important points here. While implementing any gate in ladder logic, always consider rung as an electrical line having HIGH voltage at one end and LOW voltage at the other, while the inputs are simple switches. Voltage will be supplied to the output only when switch is closed i.e. input is HIGH, otherwise the output will remain OFF. You should also have a look at Introduction to Logic Gates.

You have seen in previous post, while implementing OR gate we have used a second switch in parallel which ends at the first rung so overall its a single rung having two inputs in parallel so input can come either from first switch or from second one. So, now let's start implementing some complex logical gates in Ladder Logic for PLC. Today, we are gonna implement these logic gates:

  • NAND Logical gate in Ladder Logic for PLC
  • NOR Logical gate in Ladder Logic for PLC
  • XOR Logical gate in Ladder Logic for PLC
  • XNOR Logical gate in Ladder Logic for PLC

NAND Logical gate in Ladder Logic for PLC

  • NAND gate is another type of logical gate, which is normally used. NAND gate is nothing but a simple NOT of AND gate. In simple words, if we add a NOT gate in front of AND gate, we get NAND gate. The truth tablel of NAND gate is shown in the below figure:
  • It is quite obvious from the truth table of NAND gate that the output will be OFF only when both the inputs will be ON otherwise output will remain ON. So, now lets implement this gate in ladder logic programming.
  • The below image shows the implementation of NAND logical gate in Ladder Logic form:
  • Now, if you understand the above figure, then its quite obvious. We have used both inputs in normally closed form so when both inputs are OFF the output will be ON. If we get X0 ON then in still we will get the HIGH voltage from X1. If we make X1 ON then we get HIGH voltage from X0, but if we get both X0 and X1 ON then our Y0 will get OFF. Again we are using inputs in normally closed form so when our actual input is OFF then our X0 is closed. :)

NOR Logical gate in Ladder Logic for PLC

  • In NOR gate, we simple place a NOT gate in front of OR gate. Its truth table is shown in below figure:
  • From the truth taable of NOR gate, its quite obvious that its output will be ON when both of its input goes OFF otherwise the output will remain ON. Lets implement this NOR logical gate in Ladder Logic diagram.
  • The below figure shows the NOR logical gate in ladder logic diagram:
  • If you got the ladder logic form of NAND gate, then its not gonna be much problem. Simple two normally closed inputs are placed in series, so now when any of them gets ON, then output will get OFF.
Note:
  • If you have noticed, whenever NOT gate is involved somewhere, we use normally closed inputs.

XOR Logical gate in Ladder Logic for PLC

  • The truth table of XOR gate is shown in below figure:
  • From the truth table, we can get this thing that, output will ON only when the inputs are in opposite states and output will be OFF when inputs are in same state.
  • The ladder logic implementation of XOR gate is shown in below figure:
  • Now it has gone a little complex but lets understand how's its working. We have placed X0 and X1 in series and also in parallel, but in first string X0 is normally open and X1 is normally closed while in second string X0 is normally closed and X1 is normally open.
  • Now, what we need to do is if both inputs are in same state we need to turn OFF the output. That's what we are doing in above logic diagram. Let's say X0 and X1 both are OFF then the normally open switches will be OFF and they wont let the HIGH voltage pass and hence our Y0 will remain OFF. And if both are ON then the normally closed will be OFF and again Y0 will remain OFF.
  • Now if X0 is ON and X1 is OFF, then the first string will connect and our output will ON, and if X0 is OFF while X1 is ON then our second string will connect and will make our output ON. Quite simple and easy.

XNOR Logical gate in Ladder Logic for PLC

  • Last but not the least XNOR gate, if we add NOT gate in front of XOR gate we get XNOR gate, let's have a look at its truth table below:
  • So, in XNOR gate, we get our output ON when both inputs are in same state otherwise its OFF. Let's implement it in ladder logic form below:
  • Now in this ladder logic diagram, we are getting introduced with a new symbol, till now we have used normally open output but here for the first time, we are using normally closed output Y0.
  • It's exactly the same logic as we used for XOR gate, but the only difference is ere we are using normally closed output. So, simple when the output is gets ON, its actually OFF and when it gets OFF its actually ON ;)
  • I hope now you got the clear concept of How to do programming using Ladder Logic and what's its difference with Microcontrollers like Arduino or PIC Microcontroller etc.
That's all for today, hope I have conveyed some knowledge. If you are new to PLC programming then you won't get it in the first attempt so my suggestion is give it some time, read it again and again and you will feel better :) I am not gonna post more about Ladder Logic designing, instead in the next post we are gonna have n overview of PLC simulation software in which we design this ladder logic diagrams. Till then take care and have fun :)

Introduction to Ladder Logic for PLC

Hello everyone, I hope you all are doing great. In today's tutorial, I am going to share the detailed fIn the previous post, we have seen Introduction to PLC, which was quite simple and has the basic introduction to PLC. To day we are gonna have a look at Getting Started With Ladder Logic For PLC. Ladder Logic, also named as Ladder Logic Programming, is the programming language for PLCs. Its normally considered as the most difficult language among the engineers because of its complex structure, but if you ask me then I will say its the most interesting programming language.

Ladder Logic is different from the usual programming language of Microcontrollers like Arduino, PIC Microcontroller etc. Microcontrollers programming usually compiled from top to bottom i.e. the compiler first capture the first statement and then moves downward till it reaches the end line but that's not the case with Ladder Logic Programming for PLC. In ladder logic, the compiler moves from left to right and it gets all the lines at the same time. It seems bit difficult to understand at first but be with me and you will get it at the end. :)

Introduction to Ladder Logic

Ladder Logic is a programming language used for PLC as C for Microcontrollers. Ladder logic is a combination of rungs. Each rung is executed from left to right. For example, have a look at the below figure, a single rung of ladder logic is shown in it.

  • In the above figure, a single rung of ladder logic is shown. Now as I mentioned earlier, each rung is executed from left to right, so the above rung will also do the same behavior.
  • There are two symbols mentioned in the above rung, one is X0 and the other is Y0. X0 is placed on the left side while Y0 is placed on the right side.
  • We have seen in our previous tutorial Introduction to PLC, that X always indicates input and Y indicate output, so in short the above rung has input on the left side while output on the right side.
  • So combining all the above discussion, we come to the conclusion that input will be executed first and then output will be executed, as shown below. (I hope you got the basic theory now :) )
  • So now the thing is, if we only consider the above rung, the output Y0 will be ON only if input X0 will be ON. If X0 is OFF then Y0 will also be OFF. Consider this rung as a voltage wire as shown in below figure:
  • So, now the output will be ON only when it has HIGH and LOW but input is acting as a switch and in normal condition, its OFF so HIGH is not reaching to output so it will remain OFF, as we turn ON the input X0, it will be like the switch is closed and HIGH will pass through the X0 and will reach Y0 and Y0 will turn ON. I tried my best to explain it as simple as I can but still having confusion, ask in comments.
  • Now let's have a look on different logical gates i.e. AND gate, OR gate, NAND gate etc, we normally create in ladder logic.

1. Logical AND in Ladder Logic for PLC

  • We all know about the Logical AND gate, in AND gate we get output only if both the inputs are HIGH, otherwise OUTPUT remain OFF.
  • The below figure shows the same logical AND gate designed in Ladder Logic diagram:
  • Now in the above figure Y0 will be ON when both X0 and X1 are ON, otherwise Y0 will be ON, again consider inputs as switches.
  • Its a simple 2 input AND logic, we can add as many inputs as we want in it. For example, below image shows a four input AND gate.

2. Logical OR in Ladder Logic for PLC

  • In Logical OR gate, output goes ON when any of the inputs is ON, lets implement it in our ladder logic form.
  • The below figure shows the ladder logic form for OR gate:
  • If you check the above figure, if X1 goes ON then our connection will connect and Y0 will be ON, similarly, if X0 is OFF and X1 is ON then again Y0 will be ON because now voltage is coming from X1. Again consider inputs as switch.

3. Logical NOT in Ladder Logic for PLC

  • In logical NOT gate, output is always opposite to input, if input is HIGH then output will be LOW and vice versa.
  • In order to implement NOT gate, we have to consider another type of input, the input which we are using till now is normally open input, means it is open (OFF) in its normal condition and gets closed (ON) when input is supplied, but in ladder logic there's another type of input also present named as normally closed input.
  • Normally closed input is closed (ON) in its normal condition and goes open (OFF) when it gets actual input.
  • So, using this normally closed input, we can quite easily implement this Logical NOT gate in ladder logic as shown in below figure:
  • In the above figure X0 will be ON in normal condition and hence, Y0 will also be ON and when we get actual input then X0 will get OFF and our Y0 will also be OFF.
So, that was all for today. As you have got the basic knowledge of Ladder Logic, so now its time to have a look at How to design Logical Gates in Ladder Logics for PLC. Thanks for reading. :)

Introduction to PLC

Hello friends, I hope you all are fine and enjoying good health. Today's tutorial, as the name shows, is on Introduction to PLC. PLC is an abbreviation of Programmable Logic Controller. Recently I worked on a project in which I have to design a Automated coffee Mixing Machine Using PLC. It worked quite good and I had a great time while working on it. After completing that project, it occurred to me that I haven't posted any tutorial on PLC. So I thought of starting this tutorial. This tutorial is not gonna cover in single post so my plan is to divide it in parts.

Today. I am gonna give an overview about PLC. We will have a look on basics i.e. what is PLC? Why we use PLC instead of microcontroller like Arduino or PIC Microcontroller? What's its advantages and disadvantages? I will try to cover all about the basics. After reading this tutorial, you must have a look at Introduction to Ladder Logic for P L C, Ladder Logic is programming language for PLCs.

There are different types of PLCs available in the market manufactured by different companies, so its impossible to cover all of them. In this tutorial, I am gonna discuss Fatek PLC as I have worked on it during my project. The model I have used is Fatek PLC Fbs-20MA. The reason I used this model because it was cheap and has enough input/output ports sufficient for my project. That's why I preferred it as its engineers' task to optimize the cost as well. Let's get started with PLC.

What is PLC?

Its a basic question, which is normally asked by all the starters so I am gonna reply it first for the newbies.

  • PLC is nothing but an advanced form of Microcontroller. It is usually used in industries because of its flexibility and ease of use.
  • It can be attached quite easily with computer via serial port as well as usb port.
  • PLC is used when we need to automate anything just like microcontroller. We attach our sensors and actuators etc with PLC and then insert some programming code in it and let it do its job.
  • You have seen automated lifts, they all are operated with PLC.
  • We can use timers, counters, registers in PLC and can get any kind of output from it.
  • We can program PLC with different languages and the most commonly used language for PLC is named as Ladder Logic.

Internal Overview of PLC

What's inside PLC, which makes it so cool ? That's a good question and normally engineers wonder about it. PLC can be divided into 3 sections, which are as follows:

  • Power Supply - Thissection provides power to the PLC, in my case it is operated on 220V AC, so when I provide 220V AC to my PLC, it got activated and start performing functions.
  • Centeral Processing Unit (CPU) - Its the actual brain of PLC, it is further divided into several parts i.e. RAM, ROM, EEPROM, microcontroller etc. The programming code is uploaded in this CPU and according to that program, it performs its functions.
  • Input / Output Section - This section is the one from where PLC communicates with the external world. We can attach sensors to the inputs of PLC and can operate our motors, actuators etc from the outputs of PLC.

Types of PLCs

  • There are different types of PLCs available in the market manufactured by different companies.
  • Few famous PLC companies are Siemens, Mitsubishi, Fatek etc.
  • Moreover, they are also available in different sizes and functions. The one I used has 14 inputs and 8 outputs. It doesn't support analog inputs as I don't require them.
  • There are PLCs available with analog inputs or you can also buy cards which are interfaced with the PLC and make them capable to work on analog inputs.
  • Another function which is not available in my PLC is the Serial communication, but such models are available which supports serial communication.
  • So in short, there are several models of PLC available in the market and you have to consider your project demands while buying a PLC.

Why use PLC instead of microcontrollers?

  • Microcontroller is normally used in small products, where you need to control some sensors or some motors etc but when we talk about big automated plants in industries then PLC is always preferred over microcontroller.
  • The reason for preferring PLC over microcontroller in big projects is because of its flexibilty and ease of use. PLC can be programmed frequently with computer, suppose you have an automated system and you find some bug in it which you wanna remove, then what you need to do is simply attach a computer with the PLC of that plant and make changes in the code, which isn't possible with the microcontroller.
  • Moreover, PLC has lot of memory, you can add any size of data in it.
  • PLC is also long life as compared to microcontroller.
  • Last but not the least, PLC has built in cards to control heavy AC voltages, you can get any kind of voltage from PLC i.e. 220V AC etc but if you wanna get such voltages from microcontrollers then you have to add some extra circuitry.
  • In short, in all industrial automated plants, PLC is used.

Getting Started With PLC

I think now you have the idea about PLC, so now I am getting started with PLC. I am gonna explain the functioning of Fatek PLC as I have used that one but if you are using another model of PC then no need to panic as all PLCs have same functionality. So, it doesn't matter which one you are using. If you check the below image then you will see I have marked three sections in it.

  • Section 1 is indicating the status of input pins. If inputs are off then this section will remain as shown in above figure, but if any of the inputs get high, then the respective pin indicator will also glow into red, which indicates that this pin is ON. It helps while you are writing programming code for the PLC.
  • Section 2 indicates the status of PLC. If PLC is powered up then the POW led will go red, if you have uploaded the code in PLC and start it then the RUN led will go red and if your code has some error then ERR led will go red.
  • Section 3 indicates the status of output pins, it will tell you which output is currently ON.

In the below image, I have indicated Section 4 and 5, these are the input/ output section. If you have a look at it closely then you can see there are two rows of screws, where you plug your wires for inputs and outputs and above them, they are also labelled with white color. So, it goes like that, first row of labelling is for first row of screws and second row is for second row of screws.

  • Section 4 is the inputs pins section, so if you check above there are inputs from X0 to X13, which makes it overall 14 inputs. Moreover, there are two pins labelled as + 24V and - 24V, which PLC is providing us, so if you wanna give any input to this PLC you have to make sure that its 24V, otherwise PLC not gonna recognize it.
  • Section 5 is the output pins section. and you can see there are total 9 outputs starting from Y0 to Y8, now you are getting confused with C0 to C6. C pins are actually the voltage setter, let me explain, in projects there are different outputs are required like your motor is running at 12V DC while your solenoid valve is running at 220VAC. So, there's a need to set these voltages at the output. Here C pins are used. Suppose you need to give 12V output at Y0 and Y1 then give this 12V at C0 and when Y0 or Y1 is ON then they will give 12V at output. In short, when output gets ON it is actually connecting with their respective C pin.
  • Lastly, check the Port 0 in the above image, this is the port where you plug your serial wire inPLC and connect it with your computer in order to upload the programming code.

That's all for today. I hope you got the basic idea of Programmable logic controller and now its time to have a look at Introduction to Ladder Logic for P L C, ladder logic is programming language for PLC. Your feedback are warmly welcome. In the next tutorial, I am gonna cover about ladder logic and will show you how to program a PLC. Till then Take care and have fun.

Black Litterman Approach in MATLAB

Buy This Project

This post is the next part of our previous post Financial Calculations in MATLAB named as Implementation of Black Litterman Approach in MATLAB, so if you haven't read that then you can't understand what's going on here so, its better that you should first have a look at that post. Moreover, as this code is designed after a lot of our team effort so its not free but we have placed a very small cost of $20. So you can buy it easily by clicking on the above button.In the previous post, we have covered five steps in which we first get the financial stock data, then converted it to common currency and after that we calculated the expected returns and covariance matrix and then plot the frontiers with and without risk free rate of 3%. Now in this post, we are gonna calculate the optimal asset allocation, average return after the back test, calculation of alphas and betas of the system and finally the implementation of black-litterman approach. First five steps are explained in the previous tutorial and the next four steps for Implementation of Black Litterman Approach in MATLAB are gonna discuss in this tutorial, which are as follows:

  • Step 6: Calculate Optimal Asset Allocation
  • Step 7: Average Return after the back test
  • Step 8: Calculation of Standard Deviation
  • Step 9: Calculate alphas & betas of the system
  • Step 10: Implementation of Black Litterman Approach

You may also like to read:

Step 6: Calculate Optimal Asset Allocation

In this part of the problem,I calculated the optimal asset allocation in the different years by choosing a constant required return. I chose the constant required return equal to 0.01 and used the highest_slope_portfolio function and plot the graphs. The code used in MATLAB is shown in the below:

ConsRet=0.010 for w=1:10 [xoptCR(:,w), muoptCR(w), sigoptCR(w)] = highest_slope_portfolio( covmat{1,w}, ConsRet , estReturn(w,:)', stdRet(w,:) ); End

The result for this part is shown in the Figure 3. For a constant required return of 0.01, portfolio turnover for each year has increased approximately by 2%.

Figure: Optimal asset allocation for constant return of 0.01

Step 7: Average Return after the back test

In this part of the assignment, it was asked to perform a back test for the optimized portfolios and calculate the average return and the standard deviation for this portfolio. Average return is the average of expected return for the corresponding year and it is calculated by the below code in MATLAB, where w is varying from 1 to 10 to calculate for all the 10 years.

BTreturn(w,:)=estReturn(w,:)*xoptCR(:,w);
Results obtained after the back test for the optimized portfolios for average return are shown in table3 below:
Average Return after the back test
1st year 0.1158
2nd year 0.0889
3rd year 0.0797
4th year 0.0628
5th year -0.0660
6th year -0.4323
7th year -5.1212
8th year -0.6820
9th year 0.2891
10th year 0.1691

Table : Average return after the back test

Step 8: Calculation of Standard Deviation

The standard deviation of the rate of return is a measure of risk. It is defined as the square root of the variance, which in turn is the expected value of the squared deviations from the expected return. The higher the volatility in outcomes, the higher will be the average value of these squared deviations. Therefore, variance and standard deviation measure the uncertainty of outcomes. Symbolically,

Where,
  • S = Standard Deviation
  • E(r) = Expected return
  • p(s) = Probability of each scenario
  • r(s) = Holding-price return in each scenario.
  • s = number of scenarios.
  • n = Maximum number of scenarios.
Matlab code for calculating the standard deviation after the back test is shown below:
BTstd(w,:)=sqrt(stdRet(w,:).^2*(xoptCR(:,w).^2));
The results of standard deviation for the 10 years are as follows:
Standard Deviation after the back test
1st year 0.2942
2nd year 0.1833
3rd year 0.1799
4th year 0.1733
5th year 0.4026
6th year 1.5834
7th year 16.1279
8th year 2.1722
9th year 1.0430
10th year 0.4949
 

Step 9: Calculate Alphas & Betas of the system

In this part, it was asked to use a broad stock index for testing and check whether our portfolio is in line with the CAPM prediction: Hence, first of all I retrieved the historical data for ticker ^FTLC using the function hist_stock_data as I done in the first part of the assignment. The MATLAB code for retrieving the data is shown below:
FTLC= hist_stock_data('01111993','01112013','^FTLC','frequency','m'); LRFTLC=diff(log(FTLC.Close));
After that I calculated the expected return of one unit of each asset based on the model which gave me the total covariance matrix for the single and multi indexed model. Finally, I calculated the alpha and beta for the model. The MATLAB code used for performing these actions is shown below:
for i = 1:7 mdl_si{i} = LinearModel.fit(LRFTLC, logRet(:,i), 'linear'); mdl_ret_s(i) = mdl_si{i}.Coefficients.Estimate(1:2)' * [1; 12*mean(LRFTLC)]; mdl_cov_s(i) = mdl_si{i}.RMSE^2; alpha_s = [mdl_si{i}.Coefficients.Estimate(1), alpha_s]; beta_s = [mdl_si{i}.Coefficients.Estimate(2), beta_s]; end
As a result, alphas and betas of the system are obtained which are shown in the table below:
Aplha Beta
0.0068 0.1748
0.0057 0.0335
0.0050 0.0528
0.0063 0.0552
0.0030 0.0249
0.0035 0.0083
0.0047 0.0289

Table: Alpha & beta of the model

Step 10: Implementation of Black Litterman approach

In this part, I have finally implemented the Black Litterman approach on the data available. Black Litterman approach involves the below steps:

Few MATLAB Projects:

  1. The Covariance Matrix from Historical Data
  2. Determination of a Baseline Forecast
  3. Integrating the Manager’s Private Views
  4. Revised (Posterior) Expectations
  5. Portfolio Optimization
The code used for implementing the black litterman approach is shown below and the results obtained as a result of Black Litterman approach are shown in the below figure. Risk aversion is take as 1.9 while the precision is 0.3.
gamma = 1.9; tau = .3; for w=1:10 ind=[(w-1)*12+1 (w+10)*12]; logRet2=logRet(ind(1):ind(2),:); for i=1:7 OplogRet(:,i)=logRet2(i,:).*xoptCR(i,w)'*100; end covmatOP{1,w}=12*cov(OplogRet); end for w=1:10 Opweig(:,w)=xoptCR(:,w); Pi{w}= gamma *covmatOP{1,w}* Opweig(:,w);   end figure for w=1:10 title('BL'); hold on; bar(Pi{w}) hold on; end

Figure: Bar graph for Black-Litterman approach

That's all for today, hope it will help you all in some way. If you have any questions then ask in comments and I will try my best to resolve them.

Financial Calculations in MATLAB

Buy This Project Hello friends, today I am gonna share a MATLAB project related to finance which I have named as Financial Calculations in MATLAB. As this project is the outcome of our team efforts so its not free and you can buy it quite easily for just $20 by clicking on the above button. In finance studies, there are lot of calculations are required to be done so MATLAB plays a very important role in finance calculations and showing the pattern in graphical form. In this project, I am first gonna take the Historical Stock Data from web search online so in order to run this program, your computer must have internet access. After getting the historical stock data of 7 different markets or sectors, now there's a need to convert them into same currency so that we can compare it with each other. So, I took US$ as a common currency and convert all others to this currency.

After that I calculated Expected Returns & Covariance Matrix for all these data for the last 10 years and finally plot them. Moreover, I have also plotted the frontiers with risk free rate of 3% so that the ideal and realistic conditions can be compared. So, here are the overall steps we are gonna cover in this project:

  • Step 1: Getting Historical Stock Data
  • Step 2: Conversion of currencies
  • Step 3: Calculate Expected Returns & Covariance Matrix
  • Step 4: Plotting 11 different frontiers in one figure
  • Step 5: Plotting frontiers with risk free rate of 3%.
These are the first five steps of this project. The next five steps are discussed in Implementation of Black-Litterman Approach in MATLAB.

You may also like to read:

Step 1: Getting Historical Stock Data

  • First of all, I chose 7 financial stock indices for different markets or sectors. So, I used a function named hist_stock_data. The syntax of this function is as follows:

Stocks = hist_stock_data('X', 'Y', 'Z', 'frequency', 'm')

  • X is the starting date and is a string in the format ddmmyyyy.
  • Y is the ending date and is also a string in the format ddmmyyyy.
  • Z is the Ticker symbol, whose historical stock data is needed to be retrieved.
  • M denotes that the function will return historical stock data with a frequency of months.
Hist_stock_data function retrieves historical stock data for the ticker symbol Z between the dates specified by X and Y. The program returns the stock data in a structure giving the Date, Open, High, Low, Close, Volume, and Adjusted Close price adjusted for dividends and splits. I used 7 sectors and retrieved their data using this function. The commands used in MATLAB are:
snp500 = hist_stock_data('01111993','01112013','^GSPC','frequency','m'); NDX=hist_stock_data('01111993','01112013','^NDX','frequency','m'); GSPTSE=hist_stock_data('01111993','01112013','^GSPTSE','frequency','m'); DAX = hist_stock_data('01111993','01112013','^GDAXI','frequency','m'); CAC40=hist_stock_data('01111993','01112013','^FCHI','frequency','m'); FTAS=hist_stock_data('01111993','01112013','^FTAS','frequency','m'); SSMI=hist_stock_data('01111993','01112013','^SSMI','frequency','m');

Step 2: Conversion of currencies

The first two values were in US dollars, while third one was in CAD dollars, fourth and fifth values were in Euros, sixth were in GBP and the last one was in Swiss France. Hence, there was a need to convert all these currencies into one currency as instructed. I converted all of them into US dollars. In order to convert them, I first defined the exchange rate between these currencies and the US dollars using the below code:

GBP2USD=1.6; EURO2USD=1.34; CAD2USD=0.95; SF2USD=1.08;
After defining the exchange rate, I applied it to all the currencies using the below code:
GSPTSE=CurrencyConvert(GSPTSE, CAD2USD); DAX=CurrencyConvert(DAX, EURO2USD); CAC40=CurrencyConvert(CAC40, EURO2USD); FTAS=CurrencyConvert(FTAS, GBP2USD); SSMI=CurrencyConvert(SSMI, SF2USD);
Now all the currencies for the financial stock indices for 7 sectors are obtained in US dollars.

Step 3: Calculate Expected Returns & Covariance Matrix

In this part, we calculated the expected returns and covariance matrix in annual steps for a period of 10 years. I used the data for 7 markets or sectors were obtained in the first step and calculated their expected returns and covariance matrix. The expected rate of return is a probability-weighted average of the rates of return in each scenario. We may write the expected return as:

Where,
  • p(s) = Probability of each scenario
  • r(s) = Holding-price return in each scenario.
  • s = number of scenarios.
  • n = Maximum number of scenarios.

First of all, I initialized a column matrix and filled it with the above data and took log of each data separately by using MATLAB commands as follows:

covmat=cell(1,11); ret=flipud([log(SSMI.Close) log(FTAS.Close) log(CAC40.Close) log(DAX.Close) log(GSPTSE.Close) log(snp500.Close) log(NDX.Close)]);

Further, I calculated the differences between adjacent elements of each data using the diff command in MATLAB.

logRet=[diff(ret(:,1)) diff(ret(:,2)) diff(ret(:,3)) diff(ret(:,4)) diff(ret(:,5)) diff(ret(:,6)) diff(ret(:,7))];

Expected return is nothing other than a guaranteed rate of return. However, it can be used to forecast the future value of a market, and it also provides a guide from which to measure actual returns. Hence to calculate the expected return, I first take two indices with w as a variable where w = 1:10 and calculated these indices for all the values of w and finally took mean value of each data with these two indices as follows:

ind=[(w-1)*12+1 (w+10)*12]; estReturn(w,:)=[mean(logRet(ind(1):ind(2),1)) mean(logRet(ind(1):ind(2),2)) mean(logRet(ind(1):ind(2),3)) mean(logRet(ind(1):ind(2),4)) mean(logRet(ind(1):ind(2),5)) mean(logRet(ind(1):ind(2),6)) mean(logRet(ind(1):ind(2),7))];

The above values calculated for all the 10 times and hence it is placed within a for loop. estReturn gives us the estimated return for a single month and now there’s a need to convert it to annual return, which is accomplished by below command, simply by mutilpying it with 12.

estReturn(w,:)=estReturn(w,:)*12;

After the calculation of expected return annually, I used the command var(X) to calculate the variance of the data. Although it was not asked to calculate in the problem but in order to calculate the covariance, it is required to first obtain the data such that each row of the matrix becomes an observation and each column is a variable. The command used for the calculation of variance is as shown below:

stdRet(w,:)=sqrt(12*var([ logRet(ind(1):ind(2),1) logRet(ind(1):ind(2),2) logRet(ind(1):ind(2),3) logRet(ind(1):ind(2),4) logRet(ind(1):ind(2),5) logRet(ind(1):ind(2),6) logRet(ind(1):ind(2),7)]));

Finally, I used the MATLAB command cov(x) to calculate the covariance of the data. The syntax used is:

Y = cov(X)
Where,
  • X = Matrix of data whose covariance is required.
  • Y = Covariance of data X.
As x is a matrix of data in our case where each row is an observation, and each column is a variable, cov(X) is the covariance matrix. Results for the expected return and covariance matrix are shown in the below tables.
Expected Return SSMI FTAS CAC40 DAX GSPTSE SNP50 NDX
1st year 0.0625 0.0373 0.0524 0.0632 0.0700 0.0848 0.0644
2nd year 0.0954 0.0531 0.0762 0.0846 0.0884 0.0921 0.1290
3rd year 0.0872 0.0506 0.0972 0.0940 0.0915 0.0763 0.1004
4th year 0.0742 0.0457 0.0814 0.0925 0.0747 0.0610 0.0835
5th year 0.0006 -0.0064 0.0122 0.0147 0.0321 -0.0058 0.0110
6th year -0.0112 0.0007 -0.0039 0.0103 0.0537 -0.0055 0.0115
7th year -0.0144 -0.0069 -0.0356 0.0115 0.0494 -0.0148 -0.0307
8th year -0.0314 -0.0034 -0.0573 -0.0041 0.0295 -0.0048 -0.0080
9th year 0.0081 0.0180 -0.0209 0.0359 0.0454 0.0198 0.0470
10th year 0.0431 0.0529 0.0228 0.0907 0.0644 0.0575 0.1007

Table 1: Expected Returns for 10 years

 
Covariance Matrix for 1st year
SSMI FTAS CAC40 DAX GSPTSE SNP50 NDX
0.0334 0.0191 0.0285 0.0324 0.0168 0.0190 0.0196
0.0191 0.0201 0.0234 0.0271 0.0155 0.0169 0.0257
0.0285 0.0234 0.0434 0.0444 0.0211 0.0226 0.0380
0.0324 0.0271 0.0444 0.0609 0.0252 0.0280 0.0527
0.0168 0.0155 0.0211 0.0252 0.0268 0.0198 0.0342
0.0190 0.0169 0.0226 0.0280 0.0198 0.0234 0.0379
0.0196 0.0257 0.0380 0.0527 0.0342 0.0379 0.1411
Covariance Matrix for 2nd year
SSMI FTAS CAC40 DAX GSPTSE SNP50 NDX
0.0318 0.0179 0.0273 0.0322 0.0162 0.0185 0.0235
0.0179 0.0180 0.0213 0.0258 0.0151 0.0161 0.0269
0.0273 0.0213 0.0404 0.0427 0.0209 0.0219 0.0390
0.0322 0.0258 0.0427 0.0590 0.0255 0.0279 0.0503
0.0162 0.0151 0.0209 0.0255 0.0265 0.0193 0.0367
0.0185 0.0161 0.0219 0.0279 0.0193 0.0230 0.0394
0.0235 0.0269 0.0390 0.0503 0.0367 0.0394 0.1014
Covariance Matrix for 3rd year
SSMI FTAS CAC40 DAX GSPTSE SNP50 NDX
0.0314 0.0181 0.0280 0.0320 0.0164 0.0186 0.0237
0.0181 0.0181 0.0214 0.0261 0.0152 0.0160 0.0270
0.0280 0.0214 0.0397 0.0433 0.0212 0.0224 0.0399
0.0320 0.0261 0.0433 0.0579 0.0259 0.0282 0.0509
0.0164 0.0152 0.0212 0.0259 0.0266 0.0194 0.0371
0.0186 0.0160 0.0224 0.0282 0.0194 0.0227 0.0395
0.0237 0.0270 0.0399 0.0509 0.0371 0.0395 0.1014

Step 4: Plotting 11 different frontiers in one figure

In this part, it was asked to plot the 11 different frontiers in one figure. The concept of efficient frontier was introduced by Harry Markowitz and it is defined as if a portfolio or a combination of assets has the best expected rate of return for the level of risk, it is facing, then it will be referred as “efficient”.

Few more MATLAB Projects:

In order plot them, I used the below code in MATLAB, I used different markers for different plots so that they could be distinguished from one another quite easily. Moreover, I used the command legend in order to show the respective years for which the graphs are plotted. RF is a variable which indicate the risk-free rate and as it is asked to operate under efficient frontier that’s why risk-free rate is equal to zero.

RF=0; for w=1:10 [xopt(:,w), muopt(w), sigopt(w)] = highest_slope_portfolio( covmat{1,w}, RF, estReturn(w,:)', stdRet(w,:) ); end mker=['o' '+' '*' '.' 'x' 's' 'd' '^' '>' '<'] figure for w=1:10 plot (sigopt(w), muopt(w) ,'Marker', mker(w)); hold on; plot (0, RF, 'o'); hold on; RF_p1 = [0 sigopt(w) 2* sigopt(w)]; opt1_p = [.02 muopt(w) (2 * muopt(w) - RF) ]; line(RF_p1, opt1_p ); end legend('Year 1994', 'Year 1995', 'Year 1996', 'Year 1997','Year 1998','Year 1999','Year 2000', 'Year 2001', 'Year 2002', 'Year 2003')
In this code, first of all I used highest_slope_portfolio function. This function finds the portfolio with the highest slope. Results are shown in the below figure annually:

Figure 1: Graph for 11 different efficient frontier

Step 5: Plotting frontiers with risk free rate of 3%

The plot in Part (c) was about the efficient frontier with risk rate equal to zero i.e. operating in an ideal condition while in this part, it was asked to plot the same graphs but this time include a risk-free rate of 3%. Hence I used the same code as for the previous part but only this time I used RF = 0.03 as I needed to include a risk free rate of 3%. The code used in MATLAB for this part is shown below:

RF=0.03; %the risk free rate for w=1:10 [xoptRF{w}, muoptRF(w), sigoptRF(w)] = highest_slope_portfolio( covmat{1,w}, RF, estReturn(w,:)', stdRet(w,:) ); end figure for w=1:10 plot (sigoptRF(w), muoptRF(w) ,'Marker', mker(w)); hold on; plot (0, RF, 'o'); hold on; RF_p1 = [0 sigoptRF(w) 2* sigoptRF(w)]; opt1_p = [.02 muoptRF(w) (2 * muoptRF(w) - RF) ]; line(RF_p1, opt1_p ); end legend('Year 1994', 'Year 1995', 'Year 1996', 'Year 1997','Year 1998','Year 1999','Year 2000', 'Year 2001', 'Year 2002', 'Year 2003')

The result for this part i.e. after including a risk-free rate of 3% is shown in the figure below. If the Figure 1 and Figure 2 are closely examined then one can see the clear difference. When the risk-free rate was considered zero, all the expected estimate graphs were in positive direction depicting the profit annually while after adding a risk-free rate of 3%, few of the graphs went in the negative direction depicting the loss in those years. Hence adding the risk factor may cause the business to get deceased and it may even cause it to decline continuously which results in disaster.

Figure 2: Graph for 11 different efficient frontier for risk-free rate of 3%

That's all for today, in the coming post, I will calculate more financial terms like Optimal asset allocation, average return, standard deviation and much more, so stay tuned and have fun.

Modelling of DVB-T2 system using Consistent Channel Frequency MATLAB

Buy This Project

Hello friends, today I am going to post a complete project designed on MATLAB named as Modelling of DVB-T2 system using Consistent Channel Frequency in MATLAB. This project is designed by our team and it involved a lot of effort to bring it into existence that's why its not free but as usual I have discussed all the details below related to it, which will help you understanding it and if you want to buy it then you can click on the Buy button shown above.

This project aims to implement a DVB-T2 (Digital Video Broadcasting for terrestrial television) system using consistent channel frequency responses. Tthe code is designed to use the same output from a channel model for different transmitter configurations so that consistency of performance results can be obtained. After that the overall project will be modified to repeat an experiment “n” times collecting data so that “x%” confidence intervals can be calculated. Historically, DVB is a project worked by more than 250 companies around Europe at first and now worldwide. DVB-T2 is the world’s most advanced digital terrestrial television (DTT) system, offering more robustness, flexibility and at least 50% more efficiency than any other DTT system. It supports SD, HD, mobile TV, or any combination thereof. The GUI for DVB-T2 parameters selection in MATLAB is shown on the left.

MATLAB Simulations & Results

DVB-T2 is the second generation standard technology used for digital terrestrial TV broadcasting. As it’s a new technology so it has many fields to explore and research, and the best way of researching on any new technology is via simulations. Simulations provide an easy and efficient way to evaluate the performance of any system. For simulation purposes, MATLAB software was chosen in this thesis because of its wide range of tools and ability to show graphical results in a very appropriate form. . Further, this DVB-T2 simulation model could be extended easily to simulate DVB-H, which shares many features with DVB-T2 (only the physical layer that needs modification). The most important feature, I discussed in my simulations are:

  • Comparison of Bit Error Rate (BER) and Signal to noise Ratio (SNR).

DVB-T2 scheme can handle wide range of sub carriers from a range of 1k to 32k; these sub carriers can be fixed or mobile. In this thesis, experiments are performed on mobile transmission of signals to 4000 sub carriers. Below are discussed three different mobile scenarios, for different speeds of mobiles user, which are:

  • Pedestrian moving at the speed of 0.1 km/h.
  • Bus moving at the speed of 5km/h.
  • Car moving at the speed of 10 km/h.

In all the scenarios, the factors mentioned below are kept constant so that a real comparison can be obtained and it could be checked that whether the speed affects the signal or not. These constant factors are:

  • Transmission Mode is SISO.
  • Transmitting Antenna Cross Correlation is 0.5.
  • Receiving Antenna Cross Correlation is 0.5.
  • Environment considered for these simulations is rural.
  • Radio Channel type is Rayleigh with k factor of 1000.
  • Carrier frequency is 91.429MHz.

1.1  Initial MATLAB model

During this thesis, help was taken from a MATLAB model of DVB-T2 transmission system designed by a student at Brunel University. First this initial model was studied and then enhanced it to a higher level. The first model designed by the student at Brunel University, performed the iterations on the DVB-T2 system and gives the results for just one cycle. Explanation of this initial model is discussed in detail below.

1.1.1    Explanation of Initial Model

After the user input all the values in the GUI, this model first calculates the below three values depending on the number of subcarriers attached to the DVB-T2 system.

  • Useful OFDM period.
  • Maximum number of sub carriers.
  • IFFT / FFT length.

After getting this information, the model performs the QAM modulation over the signal so that it could be sent from the transmitter to the receiver. Next, depending on the value of Pilot Pattern given by the user, it calculates the scattered Pilot Amplitudes for the system. After that, it calculates the distortion in transmission depending on area in which the signal is propagating.

In order to calculate the distortion, FFT technique is performed on the signals to get their frequency response. As the signal has already sent from the transmitter after QAM modulation so demodulation on the receiver side is necessary. The model performs the same and demodulates the signal and finally it calculates the value of Signal to noise ratio (SNR) and Bit Error Rate (BER). At the end, it simply plots the graphs of SNR and BER for the visual representation.

1.1.2    Results of Initial Model

Different experiments were performed on the initial model and checked its results. The results are given below for three different experiments, which are:

  • Speed of mobile = 0.1 km/s , Total Iterations = 5000
  • Speed of mobile = 1.0 km/s , Total Iterations = 5000
  • Speed of mobile = 10 km/s , Total Iterations = 5000

Results of these experiments are shown in figure 6.1, 6.2 and 6.3 respectively. Table 6.1, 6.2 and 6.3 gives the values of BER and average BER for all the values of SNR. If these three graphs are closely examined then it can be shown that the band limited impulse response increases as the speed increase and so as the BER and SNR.

The reason for such behavior is that because as the speed of the mobile increase, signal distortion also increases and it becomes difficult for the receiver to catch the signal, that’s the main reason that user travelling in high speed vehicle faces more distortion as compared to a pedestrian.

Results of First Experiment (Speed = 0.1km/s, Iterations = 5000)

 
SNR BER & Average BER
SNR: 0 BER:0.103833
SNR: 0 NoAvrg_BER:0.160358
SNR: 5 BER:0.014366
SNR: 5 NoAvrg_BER:0.033706
SNR: 10 BER:0.000206
SNR: 10 NoAvrg_BER:0.001528
SNR: 15 BER:0.000002
SNR: 15 NoAvrg_BER:0.000107
SNR: 20 BER:0.001543
SNR: 20 NoAvrg_BER:0.002319
SNR: 25 BER:0.000076
SNR: 25 NoAvrg_BER:0.000184
SNR: 30 BER:0.000000
SNR: 30 NoAvrg_BER:0.000164

BER & Average BER Vs. SNR for experiment 1

Results of Second Experiment (Speed = 1km/s, Iterations = 5000)

SNR BER & Average BER
SNR: 0 BER:0.140855
SNR: 0 NoAvrg_BER:0.195596
SNR:5 BER:0.046527
SNR:5 NoAvrg_BER:0.071364
SNR:10 BER:0.011363
SNR:10 NoAvrg_BER:0.019860
SNR:15 BER:0.003815
SNR:15 NoAvrg_BER:0.006448
SNR:20 BER:0.000604
SNR:20 NoAvrg_BER:0.001222
SNR:25 BER:0.000214
SNR:25 NoAvrg_BER:0.000404
SNR:30 BER:0.000233
SNR:30 NoAvrg_BER:0.000503
BER & Average BER vs. SNR for experiment 2

Results of Third Experiment (Speed = 10km/s, Iterations = 5000)

SNR BER & Average BER
SNR: 0 BER:0.128177
SNR: 0 NoAvrg_BER:0.182924
SNR:5 BER:0.056198
SNR:5 NoAvrg_BER:0.084254
SNR:10 BER:0.023229
SNR:10 NoAvrg_BER:0.035131
SNR:15 BER:0.006793
SNR:15 NoAvrg_BER:0.010362
SNR:20 BER:0.001748
SNR:20 NoAvrg_BER:0.002801
SNR:25 BER:0.000425
SNR:25 NoAvrg_BER:0.000691
SNR:30 BER:0.000354
SNR:30 NoAvrg_BER:0.000515

BER & Average BER vs. SNR for experiment 3

Although the results given by these simulations were quite accurate but they were not accurate enough to be trusted, as they were performing the process just for one period and getting the results on the basis of that.

Final MATLAB Model after Modifications

The initial MATLAB model is modified in this thesis, in order to use the same output from the channel model with different transmitter configurations to obtain more consistent results that can be compared with each other. Then theDVB-T2model will be modified so that it can be simulated using Matlab n times collecting data so that an x% confidence interval can be measured.

The results obtained after modifications were very consistent as they were performing the whole scenario for N times (defined by the user), this attribute lacks in the initial model as it was performing the complete task just for one cycle of time and any kind of distortion could fluctuate the results. While in modified model, the same process was performed by N times defined by the user and the results obtained are actually the average of all the cycles and hence providing a very consistent output, which couldn’t be distorted by any external factors.

Moreover, this new model further enhanced the initial model to calculate the Mean BER as it will give the overall performance of BER and average BER. Furthermore, calculates the standard BER on the basis of which global BER is also calculated.

As the simulation of DVB-T2 requires a lot of input parameters from the user, that’s why a GUI is also designed in MATLAB, which makes the working of this project user friendly. User can easily change the parameters of the system using that GUI. On startup, the GUI looks like as shown in figure 4.2:

GUI for DVB-T2 parameters selection

As mentioned above, taking all the other parameters constant, three experiments are performed for the mobile user moving at different speeds with different Iterations and no. of repeats, which are:

  • Pedestrian moving at the speed of 0.1 km/h, with no of iterations = 500 and N=2.
  • Bus moving at the speed of 5km/h, with no of iterations = 200 and N=2.
  • Car moving at the speed of 10 km/h, with no of iterations = 1000 and N=2.

1.2.1    Results of First Experiment of Modified Model:

Results of the first experiment are shown in the figure 6.5, 6.6 and 6.7 respectively. While the theoretical values of BER and average BER for the corresponding SNR are shown in table 6.4 and the Mean BER and std BER are shown in table 6.5.

  • Value of Global BER for the experiment comes out to be -2.4021.

Results for Experiment 1 (Speed=0.1km/s, Iterations=500, N=2)

Results for Experiment 1 (Speed=0.1km/s, Iterations=500, N=2)

Results for Experiment 1 (Speed=0.1km/s, Iterations=500, N=2)

For N=1 For N=2
SNR: 0 BER:0.131272 SNR: 0 BER:0.131542
SNR: 0 NoAvrg_BER:0.185916 SNR: 0 NoAvrg_BER:0.186218
SNR:1 BER:0.107086 SNR:1 BER:0.106672
SNR:1 NoAvrg_BER:0.157698 SNR:1 NoAvrg_BER:0.157319
SNR:2 BER:0.086805 SNR:2 BER:0.086459
SNR:2 NoAvrg_BER:0.129841 SNR:2 NoAvrg_BER:0.129562
SNR:3 BER:0.087178 SNR:3 BER:0.086924
SNR:3 NoAvrg_BER:0.128066 SNR:3 NoAvrg_BER:0.127755
SNR:4 BER:0.081465 SNR:4 BER:0.081709
SNR:4 NoAvrg_BER:0.116619 SNR:4 NoAvrg_BER:0.116581
SNR:5 BER:0.028071 SNR:5 BER:0.028074
SNR:5 NoAvrg_BER:0.051596 SNR:5 NoAvrg_BER:0.051751
SNR:6 BER:0.016450 SNR:6 BER:0.016439
SNR:6 NoAvrg_BER:0.030762 SNR:6 NoAvrg_BER:0.030725
SNR:7 BER:0.012705 SNR:7 BER:0.012607
SNR:7 NoAvrg_BER:0.022399 SNR:7 NoAvrg_BER:0.022108
SNR:8 BER:0.036446 SNR:8 BER:0.036612
SNR:8 NoAvrg_BER:0.052421 SNR:8 NoAvrg_BER:0.052642
SNR:9 BER:0.026200 SNR:9 BER:0.026378
SNR:9 NoAvrg_BER:0.039987 SNR:9 NoAvrg_BER:0.040434
SNR:10 BER:0.014162 SNR:10 BER:0.014155
SNR:10 NoAvrg_BER:0.023779 SNR:10 NoAvrg_BER:0.023805
SNR:11 BER:0.007526 SNR:11 BER:0.007539
SNR:11 NoAvrg_BER:0.013874 SNR:11 NoAvrg_BER:0.013838
SNR:12 BER:0.015524 SNR:12 BER:0.015382
SNR:12 NoAvrg_BER:0.023693 SNR:12 NoAvrg_BER:0.023602
SNR:13 BER:0.005303 SNR:13 BER:0.005448
SNR:13 NoAvrg_BER:0.008758 SNR:13 NoAvrg_BER:0.008764
SNR:14 BER:0.008712 SNR:14 BER:0.008823
SNR:14 NoAvrg_BER:0.014517 SNR:14 NoAvrg_BER:0.014421
SNR:15 BER:0.013224 SNR:15 BER:0.013144
SNR:15 NoAvrg_BER:0.019547 SNR:15 NoAvrg_BER:0.019305
SNR:16 BER:0.001919 SNR:16 BER:0.001890
SNR:16 NoAvrg_BER:0.003767 SNR:16 NoAvrg_BER:0.003703
SNR:17 BER:0.002873 SNR:17 BER:0.002907
SNR:17 NoAvrg_BER:0.004932 SNR:17 NoAvrg_BER:0.005001
SNR:18 BER:0.000610 SNR:18 BER:0.000641
SNR:18 NoAvrg_BER:0.001197 SNR:18 NoAvrg_BER:0.001243
SNR:19 BER:0.006294 SNR:19 BER:0.006231
SNR:19 NoAvrg_BER:0.009262 SNR:19 NoAvrg_BER:0.009209
SNR:20 BER:0.001799 SNR:20 BER:0.001749
SNR:20 NoAvrg_BER:0.003268 SNR:20 NoAvrg_BER:0.003248
SNR:21 BER:0.000966 SNR:21 BER:0.000998
SNR:21 NoAvrg_BER:0.001677 SNR:21 NoAvrg_BER:0.001636
SNR:22 BER:0.001733 SNR:22 BER:0.001778
SNR:22 NoAvrg_BER:0.002772 SNR:22 NoAvrg_BER:0.002883
SNR:23 BER:0.004920 SNR:23 BER:0.004914
SNR:23 NoAvrg_BER:0.007638 SNR:23 NoAvrg_BER:0.007743
SNR:24 BER:0.000089 SNR:24 BER:0.000098
SNR:24 NoAvrg_BER:0.000220 SNR:24 NoAvrg_BER:0.000234
SNR:25 BER:0.000001 SNR:25 BER:0.000001
SNR:25 NoAvrg_BER:0.000052 SNR:25 NoAvrg_BER:0.000052
SNR:26 BER:0.000408 SNR:26 BER:0.000393
SNR:26 NoAvrg_BER:0.000695 SNR:26 NoAvrg_BER:0.000646
SNR:27 BER:0.000583 SNR:27 BER:0.000600
SNR:27 NoAvrg_BER:0.001222 SNR:27 NoAvrg_BER:0.001242
SNR:28 BER:0.000352 SNR:28 BER:0.000381
SNR:28 NoAvrg_BER:0.000609 SNR:28 NoAvrg_BER:0.000625
SNR:29 BER:0.000107 SNR:29 BER:0.000124
SNR:29 NoAvrg_BER:0.000365 SNR:29 NoAvrg_BER:0.000384
SNR:30 BER:0.000367 SNR:30 BER:0.000351
SNR:30 NoAvrg_BER:0.000720 SNR:30 NoAvrg_BER:0.000695

SNR Vs. BER values for Experiment 1

Mean BER std BER
-0.8814 0.0006
-0.9711 0.0012
-1.0623 0.0012
-1.0602 0.0009
-1.0884 0.0009
-1.5517 0.0000
-1.7840 0.0002
-1.8977 0.0024
-1.4374 0.0014
-1.5802 0.0021
-1.8490 0.0001
-2.1231 0.0005
-1.8110 0.0028
-2.2696 0.0083
-2.0571 0.0039
-1.8799 0.0019
-2.7203 0.0046
-2.5391 0.0035
-3.2039 0.0151
-2.2033 0.0031
-2.7511 0.0086
-3.0078 0.0099
-2.7556 0.0079
-2.3083 0.0004
-4.0308 0.0285
-6.1938 0
-3.3978 0.0118
-3.2281 0.0086
-3.4365 0.0247
-3.9387 0.0460
-3.4455 0.0137

Mean BER & std BER values for Experiment 1

1.2.2    Results of Second Experiment of Modified Model:

Figure 6.8, 6.9 and 6.10 gives us the results for the experiment 2, when user is travelling at the speed of 1km/s and the no of iterations taken here are 500 with repeat cycle i.e. N=2. Table 6.6 and 6.7 gives us the values of SNR vs. BER and the Mean BER and standard BER respectively.
  • Global BER comes out for experiment 2 was –inf.

Results for Experiment 2 (Speed=1km/s, Iterations=500, N=2)

Results for Experiment 2 (Speed=1km/s, Iterations=500, N=2)

Results for Experiment 2 (Speed=1km/s, Iterations=500, N=2)

For N = 1 For N = 2
SNR: 0 BER:0.144963 SNR: 0 BER:0.144537
SNR: 0 NoAvrg_BER:0.200382 SNR: 0 NoAvrg_BER:0.200617
SNR:1 BER:0.103536 SNR:1 BER:0.103496
SNR:1 NoAvrg_BER:0.153318 SNR:1 NoAvrg_BER:0.153312
SNR:2 BER:0.081079 SNR:2 BER:0.081874
SNR:2 NoAvrg_BER:0.123080 SNR:2 NoAvrg_BER:0.123966
SNR:3 BER:0.056279 SNR:3 BER:0.056618
SNR:3 NoAvrg_BER:0.096223 SNR:3 NoAvrg_BER:0.096636
SNR:4 BER:0.070647 SNR:4 BER:0.070241
SNR:4 NoAvrg_BER:0.103436 SNR:4 NoAvrg_BER:0.103023
SNR:5 BER:0.063094 SNR:5 BER:0.063427
SNR:5 NoAvrg_BER:0.089725 SNR:5 NoAvrg_BER:0.090577
SNR:6 BER:0.020785 SNR:6 BER:0.021318
SNR:6 NoAvrg_BER:0.039970 SNR:6 NoAvrg_BER:0.040469
SNR:7 BER:0.024660 SNR:7 BER:0.024455
SNR:7 NoAvrg_BER:0.040979 SNR:7 NoAvrg_BER:0.041170
SNR:8 BER:0.032986 SNR:8 BER:0.032662
SNR:8 NoAvrg_BER:0.052140 SNR:8 NoAvrg_BER:0.052100
SNR:9 BER:0.023306 SNR:9 BER:0.022988
SNR:9 NoAvrg_BER:0.037168 SNR:9 NoAvrg_BER:0.037283
SNR:10 BER:0.009120 SNR:10 BER:0.008878
SNR:10 NoAvrg_BER:0.017749 SNR:10 NoAvrg_BER:0.017499
SNR:11 BER:0.023258 SNR:11 BER:0.023224
SNR:11 NoAvrg_BER:0.034964 SNR:11 NoAvrg_BER:0.034473
SNR:12 BER:0.023534 SNR:12 BER:0.023745
SNR:12 NoAvrg_BER:0.034579 SNR:12 NoAvrg_BER:0.034325
SNR:13 BER:0.000103 SNR:13 BER:0.000101
SNR:13 NoAvrg_BER:0.000588 SNR:13 NoAvrg_BER:0.000648
SNR:14 BER:0.000016 SNR:14 BER:0.000010
SNR:14 NoAvrg_BER:0.000196 SNR:14 NoAvrg_BER:0.000231
SNR:15 BER:0.000009 SNR:15 BER:0.000014
SNR:15 NoAvrg_BER:0.000209 SNR:15 NoAvrg_BER:0.000240
SNR:16 BER:0.001996 SNR:16 BER:0.002008
SNR:16 NoAvrg_BER:0.003367 SNR:16 NoAvrg_BER:0.003535
SNR:17 BER:0.002367 SNR:17 BER:0.002430
SNR:17 NoAvrg_BER:0.003467 SNR:17 NoAvrg_BER:0.003535
SNR:18 BER:0.000002 SNR:18 BER:0.000004
SNR:18 NoAvrg_BER:0.000010 SNR:18 NoAvrg_BER:0.000018
SNR:19 BER:0.001298 SNR:19 BER:0.001367
SNR:19 NoAvrg_BER:0.002071 SNR:19 NoAvrg_BER:0.002116
SNR:20 BER:0.009918 SNR:20 BER:0.009850
SNR:20 NoAvrg_BER:0.014701 SNR:20 NoAvrg_BER:0.014585
SNR:21 BER:0.000472 SNR:21 BER:0.000521
SNR:21 NoAvrg_BER:0.000769 SNR:21 NoAvrg_BER:0.000854
SNR:22 BER:0.001085 SNR:22 BER:0.001169
SNR:22 NoAvrg_BER:0.001855 SNR:22 NoAvrg_BER:0.001917
SNR:23 BER:0.001360 SNR:23 BER:0.001495
SNR:23 NoAvrg_BER:0.002240 SNR:23 NoAvrg_BER:0.002427
SNR:24 BER:0.000595 SNR:24 BER:0.000621
SNR:24 NoAvrg_BER:0.001258 SNR:24 NoAvrg_BER:0.001321
SNR:25 BER:0.000873 SNR:25 BER:0.000820
SNR:25 NoAvrg_BER:0.001457 SNR:25 NoAvrg_BER:0.001422
SNR:26 BER:0.000003 SNR:26 BER:0.000003
SNR:26 NoAvrg_BER:0.000199 SNR:26 NoAvrg_BER:0.000201
SNR:27 BER:0.000326 SNR:27 BER:0.000342
SNR:27 NoAvrg_BER:0.000637 SNR:27 NoAvrg_BER:0.000651
SNR:28 BER:0.000198 SNR:28 BER:0.000216
SNR:28 NoAvrg_BER:0.000270 SNR:28 NoAvrg_BER:0.000262
SNR:29 BER:0.000000 SNR:29 BER:0.000000
SNR:29 NoAvrg_BER:0.000000 SNR:29 NoAvrg_BER:0.000000
SNR:30 BER:0.000000 SNR:30 BER:0.000000
SNR:30 NoAvrg_BER:0.000071 SNR:30 NoAvrg_BER:0.000078

SNR Vs. BER values for Experiment 2

Mean BER Std BER
0.8394 0.0009
0.9850 0.0001
1.0890 0.0030
1.2483 0.0018
1.1522 0.0018
1.1989 0.0016
1.6767 0.0078
1.6098 0.0026
1.4838 0.0030
1.6355 0.0042
2.0458 0.0083
1.6337 0.0005
1.6264 0.0027
3.9915 0.0072
4.8895 0.1323
4.9486 0.1512
2.6985 0.0018
2.6201 0.0081
5.5089 0.1569
2.8755 0.0159
2.0051 0.0021
3.3048 0.0302
2.9484 0.0231
2.8460 0.0291
3.2160 0.0133
3.0727 0.0192
5.4949 0
3.4765 0.0154
3.6850 0.0273
Inf NaN
Inf NaN

Mean BER and std BER values for Experiment 2

Remarks

This thesis presents the design and Implementation of DVB-T2 system in MATLAB software. The basic purpose of this thesis is to check the bit error ratio (BER) and signal to noise ratio (SNR) for DVB-T2 system so that the system could be improved to a better quality. DVB-T2 system is evaluated for mobile users moving at different speeds. It is clearly shown that the mobility has an impact on the received signal, where the SNR goes to zero in some points. This behavior will generate high BER. If the figures for impulse responses are checked for all the three experiments then it is depicted that the Impulse is high for the third experiment where the mobility speed is higher than the first two experiments. The packet data loss is almost zero for the first experiment while it’s increasing in the second and is higher in the third. The number of packet lost confirms this behavior that high losses occurred in the case of high mobility.

Sensorless Speed Estimation of Induction Motor in MATLAB

Buy This Project

Today I am going to show you Sensorless Speed Estimation of Induction Motor in MATLAB. In order to control and estimate the speed of Induction motor, there are many methods proposed by different scientists. The method I have selected in my project is Adaptive method. Using this method, I have controlled the speed of Induction motor using MATLAB software. Matlab software is used for simulation design. The simulation is designed in simulink and the MATLAB version used for designing this project is MATLAB 2010. It is also tested on MATLAB 2012 and 2013. All the details of this project are mentioned below.

If someone wants to buy this project then click on the button shown on right side. Its quite difficult to implement and is designed because of the efforts of our team that's why we haven't made it open source but we have placed a very small purchase amount because mostly it is asekBefore going into the details of Induction motor, let’s first have a look on the mathematical derivations. Few of the well-known methods are:

  1. Adaptive Method.
  2. Least-Squares Method.
  3. Non Linear Method.
So let's get started with Sensorless Speed Estimation of Induction Motor in MATLAB:

Mathematical Derivation - Sensorless Speed Estimation of Induction Motor

In order to apply the adaptive method on the Induction motor, there was a need to first design the induction motor on Simulink. For designing the Induction motor on Simulink, mathematical calculations were required. So, my first task was to derive the complete mathematical equations for all the variables of Induction motor.

The basic mathematical model also known as the a-b model (or two-phase equivalent model) of induction motor is given as:

Where,

  • ? is the rotor angular velocity.
  • ?Ra& ?Rb are the rotor magnetic fluxes.
  • iSa and iSbare the stator currents.
  • s = 1 – M­­­2/ LR LSalso known as leakage parameter.

Adaptive Method Calculation

The approach used in this report is to consider the speed as an unknown constant parameter. The reason for choosing this parameter is that it changes slowly as compared to all the other electrical parameters and as it changes slowly so it can be controlled more effectively. The adaptive method techniques are applied on the speed parameter and thus estimated it. This adaptive method approach on speed parameter was first implemented by Shauder and are further enhanced and researched by Peng and Fukao. Using the last two equations of the system (1), I derived the below equations:

Where,

  • ?maand ?mb are the magnetic fluxes and are thus known quantities.

Now take the second and third equations of system (1) and divide them by M / LR and then differentiate them w.r.t time and the below equations are obtained:

Where,

  • d? / dt = 0 as we have already assumed in this approach that the speed will remain constant.

System (3) gives us the derivative of magnetic fluxes. In order to calculate the error dynamics induced in the system, we need to calculate the estimated values of these magnetic fluxes and then subtract them from the system (3). The estimated values of the magnetic fluxes are as follows:

Now the error dynamics in the system will be calculated by subtracting system (4) from the system (3), which is calculated as:

Now, according to the Lyapunov function,

V (ema, emb) = ½ (e2ma + e2mb)

Using the above equation and the values of ema and emb, we get:

Now after putting the value of ?and then applying Popov’s criteria, we get:

These are the mathematical equations used in the modeling of this system in MATLAB. In the next part, we will check the simulation designed in MATLAB using these set of equations and will study that model in detail.

Modeling in Simulink

The model designed in MATLAB is shown in the figure 1. This model is performing the simulation of motor moving in both the directions i.e. clockwise and anti-clockwise. It contains four main blocks, which are:

  • 3-Phase Input Voltage with variable Frequency.
  • Vabcto stationary frame conversion block.
  • Motor system block.
  • Speed estimation block.

All these four blocks are discussed below in detail:

Figure 1: Model Designed in MATLAB for Induction Motor

3-Phase Input Voltage with variable Frequency

This block, as the name depicts, is used for generating variable frequencies. In the start, the first model, I generated, was for fixed frequency of induction motor and was also showing just one direction of motor. So, I did few modifications in the model and added this block so that the motor could move both in positive and negative directions and can also move at different frequencies.

Figure 2 shows the parameter block for this block and from this block one can set the frequency of this motor quite easily. From this parameter block, one can set:

  • Amplitude of the input signals.
  • Phase difference between the input signals.
  • Frequencies of these input signals.

By default, I have taken two frequencies, for which the motor will rotate during a cycle.

Reverse Direction of motor

In order to change the direction of the motor, I have used the phase change. When the voltage applied to the motor reverses its direction, the direction of the motor also reverses. For this simulation, the motor will rotate in clockwise direction when:

  • Phase of Va = 0
  • Phase of Vb = -2*pi/3
  • Phase of Vc = -4*pi/3

And it will reverse the direction, when:

  • Phase of Va = 0
  • Phase of Vb = -4*pi/3
  • Phase of Vc = -2*pi/3

i.e. Vb and Vc are changing their positions. In order to do so I added a phase change in this block and thus for the first 5 sec the motor will move in one direction and for the last 5 sec it will move in the opposite direction automatically.

Figure 2: Parameter Block

Vabcto Stationary Frame Conversion Block:

This block is separately shown in the figure 2. This block takes Vabc as an input and gives output in the form of V(alpha) and V(beta). This conversion is known as Clarke Transformation. This transformation is used in order to simplify the implementation of three phase systems as in Clarke Transformation, a reference signal is obtained. V (gamma) becomes zero in Clarke Transformation that’s why it becomes very easy to use.

Figure 3: Vabc to Stationary Frame Conversion Block

In Clarke Transformation, the relation between Vabc and V (alpha) and V (beta) is given as:

The above equation is implemented in the sub system named as Vabc to stationary frame in figure 2 and is shown in the below figure 3.

If we closely examine the figure 3, then it is shown that inputs coming are Va, Vb and Vc. After that the above equations are applied on these input signals and the output received is V (alpha) and V (beta). In simple words, figure 3 is implementation of Clarke Transformation.

  • Va, Vb and Vc are simple sine waves with amplitude of 2300 and frequency of 50 rad/s.
  • As it’s a three phase system so all these three signals have a phase difference of 120o.

Figure 4: Implementation of Clarke Transformation

  • V (alpha) and V (beta) obtained after the Clarke Implementation are shown in the Figure 4.

Figure 5: Graphical Representation of V (alpha) & V (beta)

Motor System Block:

Motor system block is the practical implementation of set of equations shown in the system (1). It is the basic mathematical model of Induction motor shown in figure 5. It is taking V (alpha) and V (beta) as an input along with the load applied on Induction motor. In other words, I can say that this block is the actual Induction motor and I need to apply the adaptive method technique on this block in order to estimate and control its speed.

V (alpha) and V (beta) applied here are the same obtained in the Clarke Transformation explained in the previous section. Outputs of this function are the states which we will study in detail in the fourth section and the derivatives of currents Isa and Isb.

Figure 6: Induction Motor System Block

Let’s double click this motor system block and check the functions it’s calculating. The functions of this sub system are shown in the figure 6. As I told earlier, this block is the simulation of system (1), which is also shown below:

Figure 6: Motor Block Functions

As shown in the figure 6, motor block is implementing all the five equations of system (1), which are:

  • First block in Figure 6 is calculating d?Ra/dtwhich is the equation 2 of the system 1.
  • Second block in Figure 6 is calculating d?Rb/dtwhich is the equation 3 of the system 1.
  • Third block in Figure 6 is calculating d? /dtwhich is the equation 1 of the system 1.
  • Fourth block in Figure 6 is calculating usawhich is the equation 4 of the system 1.
  • Fifth block in Figure 6 is calculating usbwhich is the equation 5 of the system 1.

All these functions are shown in the figures 7(a-e).

Figure 7a: Implementation of equation 2 of system 1

Figure 7b: Implementation of equation 3 of system 1

Figure 7c: Implementation of equation 1 of system 1

Figure 7d: Implementation of equation 4 of system 1

Figure 7e: Implementation of equation 5 of system 1

  • Graphical representation of all these systems are shown in the figure 7(f, g, h, i).

Figure 7f: Graphical Representation of equation 2 of system 1

Figure 7g: Graphical Representation of equation 3 of system 1

Figure 7h: Graphical Representation of equation 4 of system 1

Figure 7i: Graphical Representation of equation 5 of system 1

After the implementation of all these equations, a complete model of Induction motor has been obtained. Now there’s a need to apply the technique of adaptive method on it so that the speed could be controlled without the help of sensor, which is done explained in detail in the next section.

In order to change the parameter of this system, I have added a parameter block in it shown in the below figure:

Speed Estimation Block:

Let's have a look at the Speed Estimation Block of Sensorless Speed Estimation of Induction Motor in MATLAB. Speed Estimation is the place where adaptive method technique is applied to estimate the speed of Induction motor. This block is actually implementing the system (3) and system (4) and thus calculating the real speed and the estimated speed of the Induction motor respectively. After the calculation of these speeds, it is further calculating the error dynamics by subtracting the estimated speed from the real speed.

Figure 8: Speed Estimation Block

Speed Estimation block is shown in the figure 8. Inputs coming to the speed estimation are the same obtained in the first and second block i.e. V (alpha), V (beta), Isa, Isb, dIsa/dt and dIsb/dt. The functions implemented by this subsystem are shown in the figure 9.

Figure 9: Functions Implemented by System Estimation Block

System (3) and system (4) are implemented in the figure 9, which are as follows:

  • First green block in the figure 9 is implementing the equation 2 of the system 3.
  • Second blue block in the figure 9 is implementing equation 1 of the system 3.

Thus the outputs of these two blocks will give us the real speed values.

  • Third green block in the figure 9 is implementing the equation 2 of the system 4.
  • Fourth pink block of the figure 9 is implementing the equation 1 of the system 4.

So, the output of these two blocks will give us the value of estimated speed. The internal functions of all these four blocks are shown in figures 10a, 10b, 10c and 10d respectively.

Figure 10a: Implementation of Equation 2 of System 3.

Figure 10b: Implementation of Equation 1 of System 3.

Figure 10c: Implementation of Equation 2 of System 4.

Figure 10d: Implementation of Equation 1 of System 4.

After the calculation of all the four values, the speed estimator block then implemented the system (5), which is:

Implementation of this system 5 is separately shown in the figure 11, which finally gives us the value of estimated speed.

Figure 11: Implementation of System (5)

Graph of both the estimated speed and the actual speed is shown in the figure 12.

Figure 12: Graph of Estimated Speed and Actual Speed

Conclusion:

Let's have a look at the conclusion of Sensorless Speed Estimation of Induction Motor in MATLAB. Figure 12 shows both the actual and estimated speed induction motor. In the start, the motor is moving at the speed of around 25 rpm, after that the speed is increased to 50 rpm, and the motor starts to rotate in the opposite direction that’s why the graph shows the negative value. Now, it’s moving at 50 rpm in the opposite direction and lastly, it is moving at 25 rpm in the opposite direction. Figure 13 shows the graph for estimated errors. It is quite obvious from the error graph that whenever the speed of the motor fluctuates the error goes quite high. In other words, the acceleration produced in the motor causes the error to increase while the error remains zero when the motor is moving at constant speed, regardless of direction.

Figure 13: Estimated Error Dynamics

So, that's all for today. I hope you have enjoyed Sensorless Speed Estimation of Induction Motor in MATLAB. Will meet you guys in the next tutorial. Till then take care and have fun !!! :)

Roots of Quadratic Equations in MATLAB

Hello friends, hope you all are fine and enjoying good health. In today's tutorial, I am going to share How to find Roots of Quadratic Equations in MATLAB. It's quite a quick tutorial in which I will give you the code and will explain it a little. Benefit of this project is that when you are learning MATLAB then you must design such small codes so that you know more about the behavior of MATLAB.

Today two of my juniors came to me for a simple MATLAB term project. It's quite an easy project but i thought to share it for those students who are dealing with basics of MATLAB. Mostly such projects are offered to students in first or second semester when they have very basic knowledge of MATLAB coding and they feel helpless while solving such problems as is the case with those two students. So, let's get started with How to find Roots of Quadratic Equations in MATLAB.

Roots of Quadratic Equations in MATLAB

  • This finding Roots of Quadratic Equations in MATLAB takes three inputs from user.
    • Variables of Quadratic Equation.
    • Domain limit.
    • Variable to choose whether to show roots of the equation or minimum of function or both.
  • After taking these inputs the function calculates the roots of the quadratic equations.
  • After that finds the minimum of the function within the domain limit.
  • And finally show both of them on the graph.

Code of the Project

MATLAB is  a really amazing tool and I really love to do coding in it.The code for this project is given below. I didn't give description of the code because its a simple project and second thing I want the young students to search these commands themselves so that they could learn something. Second thing MATLAB has a very strong help section, if you are having problem with any command simply enter doc [Command] or help [Command] in the main window and MATLAB will give you everything you need related to that command. Here's the code :
%==== Code Starts Here(www.TheEngineeringProjects.com) ==== clc clf % ============ Taking Inputs From User ============== handle = input('Enter the handle of the function : '); limit = input('Enter the domain limits : '); initial = input('Enter the initial solution estimate : '); k = input('Enter 1 for min, 2 for roots & 3 for both  : '); syms x; a1 = 100000; %====== Calculating Roots of the Quadratic Equation ========= func = @(x)handle(1,1)*x^2 + handle(1,2)*x + handle(1,3); root1 = (-handle(1,2) + sqrt((handle(1,2)^2)-(4*handle(1,1)*handle(1,3))))/(2*handle(1,1)); root2 = (-handle(1,2) - sqrt((handle(1,2)^2)-(4*handle(1,1)*handle(1,3))))/(2*handle(1,1)); roots=[root1,root2]; %====== Calculating Minimum Value Within Domain Limits ========= for x = limit(1,1):0.1:limit(1,2) a = func(x); if (a < a1) a1 = a; x1 = x; end if(k==1 || k==3) plot(x,a,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) hold on; end end min = a1; %====== Displaying Roots & Minimum Values ========= if ( k == 1) min end if ( k == 2) roots plot(x,root1,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','r',... 'MarkerSize',10) hold on; plot(x,root2,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','r',... 'MarkerSize',10) end if ( k == 3) min roots plot(x,root1,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','r',... 'MarkerSize',10) hold on; plot(x,root2,'--rs','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','r',... 'MarkerSize',10) end %==== Code Ends Here(www.TheEngineeringProjects.com) =======

Test Input

  • For the testing purposes, use the below values as a testing input :
  • First input  = [1 5 6]
  • Second input  = [-1 1]
  • Third input = 0
  • Fourth input = 3
  • The Code is self explanatory but if anyone having any problem in it may ask in comments.
That's all for today. I hope you now have the idea How to Find Roots of Quadratic Equations in MATLAB. I will meet you guys in the next lecture. Till then take care.
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir