How to use Data Types in MATLAB?

Hey geeks, welcome to the next tutorial about MATLAB software and language. In this series, we have been working on MATLAB with the basic information and in the previous lecture, we worked deeply with the workspace window and learned about the functions and variables that are commonly used when we are dealing with the data in the command prompt. In the present lecture, we are dealing with the data types in MATLAB. This is related to the command prompt window but the reason why I have arranged this lecture after the workspace practice is, there will be different steps where the usage of the workspace will be included. Other details will be cleared when you will take this lecture yet, have a look at the list of content that will be included in this tutorial:

  • Introduction to the data types.

  • What are some important data types that we will use in MATLAB coding?

  • What is meant by the numeric and text data types?

  • How can we make tables in MATLAB?

  • Why data types are important in programming?

  • How can you say that different programming languages have different data types?

What are Data Types

In almost every programming language, the data types are the important topics and these do not end with a single lecture, but knowingly or unknowingly, you have been using these data types in the practice of your MATLAB codes. So, first of all, I am going to provide you with the proper definition of data types:

In programming, a data type is a classification that specifies what type of value a variable has and what mathematical, relational, or logical operations can be performed on it without causing an error.

If this definition seems difficult to you then do not worry, all the details will be clear to you when you will see the example of each of its types. When you use any type of data in your programming language, it is not of the same type but varies according to your needs and requirements. There are several data types but we will discuss the basic and most important in this lecture so we may elaborate on each and every type effectively. But before going into the examples, I am dividing the whole languages into two main classes:

  1. Strongly typed programming languages

  2. Weakly typed programming languages

Both of them have different ways of implementation, so have a look at them.

Strongly Typed Programming Language

Strongly types data types are the ones in which there is a restriction of using the particular variable is used according to its data type. You must know, MATLAB is a strongly typed programming language because you can not connect irrelevant data types together in it but you have to use the same data type all the time when connecting two or more together. 

Let us have an example. We have seen the concatenation process in the previous lecture where two digits may have the arithmetic operation if they belong to the same class that is the same data type. So, if you try to connect an integer with the string, it will throw an error. 

Weakly Typed Programming Languages

The weakly typed data type, contrary to the first case, can be used in an easy way because there is the independence to use the different data types together with the help of any operation. It happens in only a few programming languages and it is not relevant to our MATLAB so I am not explaining it more. 

List of Data Types in MATLAB 

Finally, I am going to describe the detail of almost all the data types that you are going to use in the MATLAB throughout your course and with the help of this knowledge, you will be able to use these data types according to your needs and at the final result, you will code in the best way. So, have a look at the detail of each data type. 

Numeric Types

The first and most basic type that we all know is the numeric type. Here, if you are new to programming, I must mention that numerics also has different classes in it and two of them are:

  1. Integer

  2. Floating Points

  3. Single

  4. Double

Integers: 

The numbers that mostly we use in our daily life are integers we have read the definition of integer in our begging classes that these are whole numbers ranging from positive infinity to negative infinity but we are mentioning here the definition because I want to make sure you use the code without any confusion.

Floating Points:

The floating points are the numeric types that contain the part, less than one in them, in addition to the whole number. This portion is then added in the form of points. To memorise well, you can think that every integer has zero additional points than a whole number and the floating point digits additional to that whole number. 

Single:

It is the array of single precision numbers that occupies less memory because it just stores the first digit after the point. Basically, it is the subclass of the floating number and is less accurate than the other case that we are discussing next. It is less likely to choose and if the user is not using scientific information, then they use the single integer to fix less memory for their data type. For instance, the result of the calculation will only be shown just after one point such as 12.3 only.

Double:

It is also the class of the floating point that stores more memory than the single data type. It is more accurate because it can store the two numbers after the floating point. For example, if you choose the double floating point, it will provide you with the results as 12.34. The numbers having a value more then this will require to be saved int eh data type of character or string according to the length of the number.

IntX numbers:

These are the interesting types of data in which users may get the integer type of his/her own choice. There are different int X numbers where the X varies from 8 to 64. So, by applying the numbers 8, 16, and 64 with the X separately, you can fix the memory space of your own choice where you can easily declare the variables. 

For example, if you want to declare the variable of the size 8 bits, you will write the following command: 

int8(value)

It will create a space of 127 numbers. The total size of this 8 bits data is one byte and it occupies the space to accommodate 0 to 127 numbers. By default, if you do not specify, it is the unsigned data that starts from 0 to 127. 

If you want the numbers with the same memory size but the ones that include the negative sign as well, you can do so by changing the command to:

uint8(value)

Now, I am writing both these commands in the command prompt and with the help of the workspace window, you can compare the values stored in both these cases.

Similarly, you can check for the int16 and int64 as well and the workspace window will tell you about the detail of each and every case with the signed and unsigned value. 

If you do not want to use the workspace window, you can find the details of your data type with the help of whos command that we have learned in the past lecture.

So in this way, it becomes easy to search and get the results of details of any kind you want about the particular data type. 

Class of The Data Type

It is time to tell you about a useful and simple command to get the class of the data type easily if you do not remember the size or data type of your variable. So, the syntax to do so is:

class(variable)

Where the variable amy be any data type, this keyword will help us to find its class.

Keep in mind, the A varialbe was declared by you before using this class keyword otherwise, you will ge tthe error.

Text Data Type

When using the text in the code in any way, you have to use the alphabet, as expected. But, you must know that there are also two types of text data types that are, the same as the numeric type, have a slight difference between them and we use them according to the need of time. Here are these two:

  1. Character  type data

  2. Sring type data

CharacterText:

The character type data is used when we want to declare the variable of the text with relatively less memory space. In simple words, when we want to declare a single alphabet or small sentences, we use the character. The declaration for the characters is as follows:

A=’Tom’

Where the single quotation tells the compiler that we want the space for the character text.

String Text: 

The string text, as you can expect, has more memory space than the character. These concepts are discussed in the last lecture so I am not going to give you unnecessary details and examples.

Tables

Row and column variables are present in the table. Each variable can have different data types and sizes, but they must all have the same number of rows. A variety of functions are used to access data in order to create, edit, and read table data.

Syntax

A=table(column1,column2,....,column(n))

Here, you can easily declare the column's name and after that, you can enter the data according to your choice.

Structure Data Type

Data containers are used in the structure to group related data and their types, which are referred to as fields. Fields can hold any type of data. The dot notation is used to access data in structures.

Why We Use Data Types in Programming?

We know you have an idea that data types are important in programming languages yet, I always use the explanation of the importance of the topic that is being discussed. 

  • The data types are used to occupy a specific amount of the data according to the need of the user. For example, there is no need to reserve the memory space equal to the string data when you need only the data of a single integer. In this way, the program runs slowly and this problem is unbearable if you have a large data in the program or have a slow system than required. 

  • The data types make the code more organized and clean. 

  • With the help of data types, the path of the program is more clear that how the flow is being used from start to end when you are programming your code. 

  • The readability of the program is enhanced with the help of clearly defined data types. 

Data Types in Different Programming Languages

It is an interesting question that must be cleared when dealing with programming languages. We know you have a basic knowledge of programming languages and therefore, I am not explaining from the scratch. But, you must know that it is not necessary that all the programming languages are based upon the same data types. Usually, the code of the programming language is distinguished by its data types and the keywords that we use with the specific syntax.

Hence, it was a detailed lecture on the data structure where we learned a lot about the data types and we have learned a lot of infprmation in differnet ways. All the work was practiacally performed but if you find that something that needs implementation, you should practice it by yourself as your homework. We had a lot of discussion related to the different case where we use some special keywords to find the type or the relation of different data types. Hence, you can now designed you codes according to the required data type. Stay with us for more interesting tutorials. 

Command Window in MATLAB

Hello, peeps! Welcome to another exciting tutorial on MATLAB in which we are discussing one of the most important windows of MATLAB that you are going to use the most. In the previous tutorial, we learned a lot about the basics of MATLAB and the different types of windows that are used in MATLAB and are present on the face of MATLAB when you launch it. There was a piece of interesting information about the basics of this fantastic development environment. This is the next step in the related tutorial in which we study the applications and workings of command windows in depth. Here is a glance at the topics that you are learning about today. 

  • How can you define the command window of MATLAB in detail?

  • What are some examples of commands related to online help?

  • How can you use the useful commands on MATLAB related to the variable?

  • Give the information about the commands related to the files, directories, and the PC that you are using. 

  • What are some examples of the type of equations that are solved in the command prompt?

Thus, let’s start learning.

Introduction to Command Window in MATLAB 

Recall that the command window is the basic window that is shown in the centre of the screen when you fire up your MATLAB, and here, the pre-defined commands are run in the easiest way by merely providing the command and values. If it seems to be normal right now, then maybe you have unclear programming skills because programmers know that in most languages, the commands and functions have to be defined first. 

Not only this, but the command window also performs another responsibility. In some programs, when we are using the edit window, the command window shows us the results and outputs of the calculations, if applicable. The usage of edit windows is not yet discussed in his tutorial, but you can understand that the command window shows us the numerical output and the command’s results when we allow it to do so. 

Using Command Window for Online Help

As we have said earlier, the command window is used for different purposes, and therefore, at the beginning, we are telling you about the different ways to seek official help from MATLAB if you are stuck in any situation and do not know how to tackle it. The good thing about MATLAB is that it provides you with the maximum information and helps in different ways and it is made for students. Therefore, it not only provides you with the terms of help but also defines them in the easiest way so the students may know where they have issues in the calculations. So let’s start the process of finding help in different ways in MATLAB. Just follow the steps given below:

  • Launch your MATLAB software. 

  • Go to the command prompt where the function catalogue is blinking. 

  • Start writing the following commands to check what they do.

  1. help

By writing this in your command window, you will get the list of the commands for which, MATLAB can help you by defining the introduction and codes of that particular command.

  1. helpdesk

It creates a helpdesk for you and directs you towards the MATLAB official page where you can report and find help regarding your issues. 

  1. help topic

This command provides you with help regarding a particular topic. Assume that you want to get help related to MATLAB's "help" command, which was also mentioned above. You can type "help" instead of "topic" in this command. You will get the details all the time. 

  1. helpwin

It is a special command that is used to get the help link and details in a separate window.

  1. lookfor string

This is an interesting command that is designed to provide you with help related to the strings that we will use in the codes. If you are new to this concept, skip it for now because you are going to learn about it in detail in the coming sessions.

  1. demo

It is one of the most amazing commands in MATLAB where you can find demo examples of different types of code by merely writing a single word, and you will be directed to the official page of MATLAB where all the demos of various programs are present. 

  1. whatsnew

If you want to get the Readme files of MATLAB, you just have to write this command in the command prompt and you will get the required output.

  1. why

This command has some different types of work. Every time you write “Why” in your command prompt, you will get a different type of sentence with a different meaning.

  1. home

This is a command resembling the “clc” command where you can go to the start of the command prompt and all the results and writings will be cleared from the screen and you will start writing from the beginning.

  1. global

This command is used to declare the variable globally. In other words, you will not have to declare the variable again and again in different sections, but it will be defined once and can be used anywhere in the program.

Commands Related to variables in and Workspace Information

Here is another category that deals with variable or workspace information, and you can easily perform them as you have practised the commands discussed above. So here is the list of this particular type. 

  1. who

This command is used to get all the variables that are declared in the workspace in which you are working.

  1. whos

If you want to know the variables declared in the workspace along with their sizes, then you will use this command. In this way, by adding only one character, you can also examine the size of the variable.

  1. clc

Sometimes, or I should say, many times, we want to clear the screen so we may try other codes and commands. For this, you do not have to select all the content and then press backspace, but you just have to write a simple “clc” command and all the data will vanish from your screen. But be careful while using this command because once the data is removed, you will never get the same data back.

  1. clear x,y,z

Consider the case when you just want to remove the specific lines of code or the variables and other code that are useful to you. Then you will use the clear command in a specific manner in which you will specify the variables that you want to remove from the screen and the memory. In this way, the declaration and erasure of data become easy.

  1. mlock fun

As we said earlier, it may be a disaster in your code if you clear the instructions in the code that were supposed to be there in the command prompt, and in such cases, you can lock the function by putting the name of that particular function just at the place of “fun” in this command.

  1. clf

As we have defined the figure window in our previous lecture, if you have the results of your code in the form of a figure window and want to close it with the help of a simple command, then simply write this command and the window will be closed.

Commands Related to Files and Directory Information

While using MATLAB, I face some cases where I have to think a lot about the directory and want to get information about different files saved in MATLAB by e. So, I found some interesting commands that tell me the exact information about the directories and files I am using efficiently and in great detail. Some of them are given below:

  1. cd

It changes the current working directory. It seems the same command we use in the command prompt of windows.

  1. dir

The purpose of this command is to see the content of the current directory. 

  1. copyfile

This command is used to copy the content of the files that we are working on. 

  1. rmdir

To remove the current directory from your MATLAB, we use this simple command. 

  1. what

It is an interesting command. You can access all the data on which you are working with the help of this simple one-word command.

General Information with The Help of Command

Yes, it is right. You can find general information about your computer with the help of commands in the command prompt. MATLAB does not only work as simple software that works separately from the other functions of the computer but it is also connected to the internal system of your PC. For instance, if you want to know the basic information about your PC, then you have to see the commands given below:

  1. clock

This is my favourite command. You can have the time and date in the form of a vector wall clock by writing this on your command prompt.

  1. ver

The licence and version of MATLAB can be seen with the help of this command.

  1. bench

This command must be used when you want to compare your computer to other devices while MATLAB is running. 

  1. computer

Many times, people do not know the type and specifications of the computer, and they can find them with the help of this command.

Keep in mind, just like some other programming languages, MATLAB is a case-sensitive language, and therefore, if you put these commands with different spellings or change the way of the writing that they were supposed to be, you will get an error. Usually, if the case or one or two characters are changed, MATLAB gives you the suggestions and, therefore, you can easily press the enter key and get the required work from MATLAB. Otherwise, you have to write the exact command.

Examples of Numerical Problems in MATLAB Command Prompt

Now, you know the basics and easy commands that are used in the command prompt, you can easily use the command prompt for different numerical problems. Now, we are starting MATLAB and solving the simplest numerical problems, and then we will move towards more complex problems. 

First of all, have a look at the equation that we are going to solve in MATLAB.

4x + 2 = 18

Here, x is the variable, and we want to find the value of this variable. So, we are using the following code to get the required output. You must know that the 18 on the right-hand side is moved to the left-hand side and, therefore, the equation becomes

4x + 2 - 18= 0

4x -18 = 0

We will write this problem in MATLAB and will get the results:

As you can understand with the help of this image, we are declaring a variable with the name “equation” and then feeding the values of x and the constant into it. By default, MATLAB reads the equation from the right side, and it reads the rightmost value as constant, and after that, moving towards the left increases the value of the polynomial. So, MATLAB understood that 4 is the value of variable x. 

Consider another equation that is shown as:

34x4 +45 -12=0

Here, you can see that the cubic value of the variable x is missing, so in place of this value, we will write zero. So the code and the output of the equation given above are:

You can use any word instead of "equation" to declare the equation. Yet, be careful, you have to write the exact word in the root command to get the desired results. The roots command simply takes the equation, solves it, and provides us with the result instantly.

So, it was the day when we learned a lot about the command prompt and saw some amazing commands related to MATLAB that, when written on the command prompt, give us the useful required information, and we checked most of them during the lecture. Your homework is to check the missing commands and get the results related to MATLAB. We will do some complex calculations in the next session, and now you are ready to get the answers to the complex calculations and codes, so stay with us for more action.

Applications of Matrices in MATLAB

Matrices are an essential topic in different fields of study, especially in mathematics, where you have a bulk of data and want to organize, relate, transfer, and perform different operations on data in a better manner. We have studied a lot of types and operations on the matrices and have worked on different types with the help of MATLAB. Today, we are here to present the applications of the matrices in different fields of study to clarify the importance of this topic. So, have a look at the list of topics we are going to learn. Yet, first of all, I am going to describe what a matrix is.

What is a Matrix?

In the fields of physics and mathematics, there is the use of different types of numbers in groups of various types. In order to organize the data into a manageable format, matrices are used. A matrix is a rectangular array of numbers that are enclosed by a square matrix (or, in some cases, parentheses). 

The information about the numbers of rows and columns is called the order of matrices, and on the basis of this information, we can recognize different types of matrices. The types, in turn, are used in different applications because of their unique behavior. By changing the order of the matrix, the properties and working of the matrices changes according to the changes. Mostly, square matrices are used in different applications.

It is interesting to know that in the early days of matrices, these were considered arrays. With the passage of time, when they were involved more and more in different research and methodologies, matrices gained popularity. Because of the ease of usage, this popularity is not going to end. So, have a look at the different types of fields where matrices are used in different ways but before going into details, you must know, these fields are not only dependent on the matrices but the normal functioning of these fields include the usage of matrices in different ways. 

Applications of Matrices

As we have said earlier, matrices are used to deal with massive amounts of data better. The matrices that we have learned and seen till now are of very minimum order, and these are kept simple for the better concepts in easy ways, but in practice, we have seen that there are gigantic matrices with complex data in them, and at that point, it is difficult to solve and save them manually. Have a look at the different fields of practical life where matrices are used in a routine.

Matrices in Cryptography 

Data cryptography is an important department in data communication in which the encryption of the data is an important process. It is done by using different keys and codes to secure the message and communication in a better way. A large amount of data is sent and received by different parties, and the encryption techniques also require some other space as well. Matrixes are used to make sure that all the data and its codes are stored in a better way. These matrices 

save the keys of the encrypted data to decrypt them on the receiving end and in this way, matrices play a key role in cryptography.

Use of Matrices in Wireless Communication

We all know that in wireless communication, usually air is used as the medium to send and receive messages from one point to the other. In this process, matrices are used to detect, extract, and process the information about the message that is to be delivered. Here are some other uses of matrices in this department:

Signal estimation and the detection of the problem during communication are done with the help of matrices. 

  • Sensor array signal processing involves the matrices.

  • In the processing and representation of a digital image, matrices have a great role. 

  • Radar signals

  • Underwater surveillance

With the help of matrices, wireless communication is done efficiently, and understanding the code becomes easy. Think about the case if the data of different queries are not used in the form of a matrix, then finding the data of a simple command would never be organized. 

Matrices in Mathematics

The use of matrices in the field of mathematics is not new to us. We all know that it is a basic concept in mathematics and a great variety of concepts of matrices are used in different ways while solving mathematical problems. One of the major use in mathematics is a solution of linear equations with the help of matrices. The complex and time taking equations can be easily solved with the help of rules of matrices in different ways. 

In engineering and other related fields of mathematics, matrices are the basic concepts and it is used in different ways to make the working of the system better manner. We have seen different cases in which the matrix is used as the alternative method to find the unknown value because it is a more organized way and the great number of research resulted in different theorems and laws therefore, the long calculations are minimized to their result by simply using the theorems.

Matrices in Computer Graphics

One of the amazing applications of matrices is in the form of computer graphics where the pictures and the graphics comprise pixels and the array of these pixels and points are arranged in the form of matrices for easy transformation and working. Overall, you can say that in computer graphics, each digital image is treated as a matrix. Therefore, different types of operations used in the matrices are applied to the graphics with great ease. Not only in the dimensions and the sizes but also for the colors of the images, matrices are used to store and reuse the values for the images and graphics. For example, in the CNN technique, different types of matrices are used. For the greyscale image, only a 2D image is used and if one wants to get the RBG system image, there is a need for a 3D matrix. 

Three Dimensional Games and Matrices

Gaming is one of the most important filed in graphics and when we talk about three-dimensional games, matrices are important there in order to alter the 3D space in different ways. For this purpose, if we use simple words, the conversions between the 2D and 3D matrices are used by different techniques, and therefore, we get the final output. Moreover, the quality of the result depends upon the way you use the data in different ways. 

Matrices and Geology

During the seismic survey in geology, matrices are used in a great way. For real-time surveys of different areas of common real problems such as mortality rate, population, the number of people in different areas of the world, and other specific counting related to real-life problems involve the use of matrices because it becomes easy to deal with great data using different operations on the data.

The Matrices in the Field of IT

In different Information technology organizations, matrices are used to execute and search the different queries. The IT security system needs to have a secure way to deal with all the information and once saved, data is to be retrieved in an efficient way with the help of minimum commands. If the data is not present in the form of tables, or we should say, in the form of matrices, organizing, storing, retrieving, and dealing with the data will be like a nightmare. 

Using Matrices to Find the Collinear Points

It is one of the procedures in mathematics in which the values of collinear points are found with the help of matrices. If it seems simple at this time then you should think of the case where gigantic collinear points are found with the help of matrics with the help of different software and these points are in return used in different ways. 

Pre-allocation of Matrices in MATLAB

As we have said, matrices make the working of daily life data and complex calculations easy. We read different types of commands about the matrices when we were learning about their functioning and therefore, we can now use them in a simple program to prepare the code in which the matrix is used for the pre-allocation of the data in a simple way by using limited lines of codes. Trus, have a look at the code given below:

Code:

p=zeros(5)

p(1,:)= [ 3 6 2 8 7]

for i=3:4

p(i,:)=p(i-1,:) +1

end

Output:

Understanding the MATLAB Code

In this code, we have used a simple function of zeros and used a loop to execute the whole instruction. Let us discuss both of them in detail:

Zeros Function

It is a pre-defined function of MATLAB that is used to make a null matrix of the required dimensions by using just a simple signal command. For the null matrices, there is the condition that the square matrix should be used.

For loop in Matrix

There are certain loops used in the MATLAB and with the help of this for loop, we just have to simply follow the syntax given below:


for index = value

statement

end

Here, the index value is the starting point where we want to start the matrix formation and the statement is the condition that we want to be executed while the formation of our matrix. If it is not clear right now in your mind, just have a look at the flow of the program.

  • First of all, we have used the zeros function to allocate the space in the memory according to the requirement. We have used the square matrix which has the order of 5 by 5. 

  • I wanted to pre-allocate the values in the matrix row after the row therefore, we simply changed the values of the matrix p formed before from 0 to other values defined by us. If you are not familiar with this function, have a look at the notation given below:

p(a,b)

Where,

a=number of row

b=number of column

As we did not want to alter any value in the columns so we have used a colon in its place. 

  • By using the for loops, we have specified that the index value starts from 3 and ends and 4. 

  • In the next step, we are using these index values and specifying to MATLAB that we want to change the values of the 3rd and 4th rows only and the program ends. 

  • MATLAB does this task step by step and changes the null or zero values of the matrix p into the required pre-allocated values in the matrix.

  • For the best concepts, we have changed the values of just two rows and the other matrix remains the same.

Larger versions of these kinds of procedures are used in diverse ways to recognize, store, and use the data in a better way, and with the help of this short program, we have seen a glimpse of a real-time application in which a matrix can be used to pre-allocate the different values and people can have benefit from it.

Trus, today, we have learned a lot about matrices and their applications. We have read great information about matrices in the past lectures and it was quite interesting to know how can you use these basic pieces of information in a better way and how people are working on the matrices to make their daily tasks easy during their professional life. We have seen different departments where matrices are making the work easy and more efficient. Most of them can not work without using matrices. Moreover, one must have the idea that many times we use matrices in our daily life unintentionally. As we have said earlier, 3D games require the involvement of a matrix. So, when your child is playing the game, he or she is enjoying the application of the matrices without knowing it. In the end, the small program was helpful to understand how little programs and the working of matrices are helpful to perform different tasks automatically.

Special Types of Matrices in MATLAB

Hey students welcome to another tutorial in The Engineering Projects where we are going to learn a lot about matrices. If you are a beginner to the metrics, then you should go to learn the fundamentals of matrices. Yet, if you know the basic introduction, you are at the right lecture because we are learning about the special kinds of matrices and you are also going to see the matrices in action using MATLAB. So, here is a simple list of today’s topics. 

  • What is a matrix?

  • How can we identify the matrix with the help of its general form?

  • What are the different types of matrices?

  • What is the concept of transpose while dealing with matrices?

  • How can we implement these types of matrices in MATLAB by different commands?

What is a Matrix?

A matrix is a type of array that stores data of the same kind. It has great importance in the world of technology and it is defined as:

"A matrix takes the form of an ordered rectangular array surrounded by a square bracket and has entries of the same kind in the form of real or complex data."

To perform different operations on the matrices, you just have to apply them to the whole matrix at once; there is no need to apply them to all the entries one after the other. This will make sense when you see the matrices in action. 

Till now, we have learned about the basic introduction of the following types of matrices:

  • Row matrix

  • Column matric

  • Square matrix

  • Rectangular matrix

These are the basic types irrespective of the elements or entries present in them, and now, we are going to discuss some types that have the features of these matrices but the entries in them are in a specific pattern, so they are considered the special kinds of matrices. Before going into the details of each of them, there must be the foundation of a concept of a general form of the matrix. 

The General Form of the Matrix

To examine the location of a specific element, we use the terms "rows” and “columns” where

  1. Rows are the horizontal entries of the matrix.

  2. Columns are the vertical entries of the matrix.

A specific element is the part of a row and column at a time and to mention the location of an element, it is important to know the information about both of them. So, in the general form, a three-by-three matrix is shown as:

Where

  • A= name of the matrix
  • a= elements of the matrix A

Notice that a has two numbers with them in which the first number denotes the rows and the second one is the number of columns. To make it easier, we denote rows with i and columns with j. So we can say,

  • aij=a23=element of the second row and first column

Keeping this concept in mind, now it is easy to understand the types of matrices in which the value of the elements matters. Have a look at some of these types.

Identity Matrix

The identity matrix is a special kind of matrix having the arrangement of entries in such a way that all the diagonal entries are one and the remaining ones are all zero. In this way, we get the matrix of the form:

You can observe that for an identity matrix, the elements where i=j are all ones, and all the elements other than this are zero. There are certain applications of the identity matrix and you will know them in the upcoming lectures. 

Zero or Null Matrix

Here is an interesting type of matrix. This matrix has all the entries zero and no other value can be found in this element. So we assume the zero or null matrix as:

Where the sequence of the matrix can be any. No matter whether it square, row, or rectangular matrix. 

Singular Matrix

A singular matrix is the type of square matrix that has the determinant equal to zero. It is possible in the condition when all the entries of the matrix have the value one.

We all know the procedure to find the determinant. So, taking the determinant of this matrix C, we provide ourselves with the following calculations:

|C|=1x[(1x1) - (1x1)] - 1x [(1x1)-(1x1)] + 1x[(1x1)-(1x1)]

    =1x(1-1) - 1x(1-1) + 1x(1-1)

    =1x(0) - 1x(0) + 1x(0)

    = 0 - 0 + 0

    =0

So in general, we say, in a singular matrix:

|C| =0

Non-singular Matrix

A non-singular matrix, on the other hand, has entries in such a way that the determinant is never zero. So, we can say, most of the matrices are included in a non-singular type of matrix. Here is an example of a non-singular matrix, which we have also mentioned in other categories.

|C|=3x[(-6x7) - (1x-1)] - 0x [(2x7)-(1x4)] + (-5)x[(2x-1)-(-6x4)]

    =3x(-42+1) - 0x(14-4) - 5x(-2+24)

    =1x(-41) - 0x(-10) + 5x(22)

    = -41 - 0 + 110

    =69

Hence, we can conclude for the non-singular matrix that if A is a non-singular matrix, then:

|A|≠ 0

Diagonal Matrix

The concept of diagonal was used in the identity matrix, but it is a slightly different case. A diagonal matrix is one that has all the entries, other than the diagonal, equal to zero. The values in the diagonal may be anything. 

Here, one concept must be clear. In some cases, all the diagonal values except one may be zero, but it will still be called the diagonal matrix. In other words, by changing even one of the values in the null matrix, we can convert it into the diagonal matrix. 

Scalar Matrix

A scalar matrix has all the diagonal values the same, no matter what the value is, and all other values are zero. So, in the scaler matrix, three conditions must be satisfied:

  1. The values other than the diagonal are all zero. 

  2. The values in the diagonal must be non-zero.

  3. All the values of the diagonal are the same, no matter what the value is. 

  4. The matrix is a square matrix.

If one of the conditions is not satisfied, it is not a scalar matrix. 

Upper Triangular Matrix

This is an interesting type of matrix. The upper triangular matrix can be recognized when all the entries below the diagonals are zero and the entries above the diagonal are non-zero. So we get the matrix as:

The value in the diagonal must be non-zero for at least one value. And the 

The Lower Triangular Matrix

As you can guess, the lower triangular matrix has non-zero values in the lower elements than the diagonal. The values presented in the upper portion of the diagonal are all zero. So the lower triangular matrix looks like this:

Transpose of a Matrix

This is another concept in matrices that is important to discuss here because some types of matrices depend upon it. We know that a matrix has i rows and j columns. Then, the transpose of the matrix is defined as:

The transpose of matrix A, denoted by AT , is obtained when the rows and columns of matrix A are interchanged no matter what the total number of rows and columns. 

This concept is used in different ways, and the results obtained are important. To understand well, you must know, that a rectangular matrix of order 2 by 3 will be converted into a matrix of order 2 by 3 when the transpose is applied to it. 

Symmetrix Matrix

It is a special kind of matrix that involves the procedure of transpose. A skew-symmetric matrix is one that has the arrangement of elements in such a way that applying the transposed result in the matrix that has the same entries and same order. In other words:

AT=A

So, the skew-symmetric matrix is always a square.

The Skew Symmetrix Matrix

Here is another kind of square matrix that involves the transpose, and it is slightly different from the one discussed just before. This type of matrix, after taking the transpose, results in a matrix with all the negative values. So we define this in a simple way as

AT=-A

Harmatian Matrix

A hermitian matrix involves complex numbers in it. That means some, or all the elements of a matrix A are complex numbers, and the transpose of that matrix A results in the transpose of a conjugate matrix. So, the following conditions are applied to the hermitian matrix:

  • It is a square matrix.

  • It involves complex numbers.

  • A conjugate of the matrix is obtained. 

  • The resultant matrix has the conjugate values.

    The Skew Harmatian Matrix

    A skew hermitian matrix, with the complex conjugate, is the one that involves the negative values of the original matrix ( the one before the transpose procedure). It will be crystal clear to you when you examine the case given below:

    Special Matrices in MATLAB

    Are you enjoying the different types of matrices? Matrices are fun in MATLAB, it is good practice if we attempt all these types in MATLAB. Notice that, these types follow a specific sequence. Hence, MATLAB has a special function designed for the user with the help of which, one can have all these types by simply writing some commands. But it would be helpful if you understood the commands first.


    Command

    Description

    eye(a,b)

    It creates an identity matrix.

    Where

    a=number of rows

    b=numbers of columns


    triu(A)

    It converts the matrix A into the upper triangle.

    tril(A)

    It converts matrix A into the lower triangle.

    null(a,b)

    It creates a null matrix. 

    Where,

    a=number of rows

    b=numbers of columns

    ones(a,b)

    Creates the singular matrix having the rows a and columns b. 

    diag(A)

    Used to get only diagonals of the matrix provided by you as A.

    sort(A)

    Sort the elements of the matrix A in the ascending order column-wise.

    A’

    It takes the hermitian of a complex matrix A.


    Follow the procedure given below to perform the tasks.

    • Start your MATLAB software. 

    • Go to the command window.

    • Start typing the codes given below and get your desired matrix.

    A=[ 2 7 4; 5 11 5; 3 8 23]

    • Notice that we have a square matrix now. It will help us in different operations. So let’s start using different operations. 

    • Write your first command.

    IdentityMatrix=eye(3,3)

    • It will create an identity matrix with the name IdentityMatrix with three rows and columns.

    • Similarly, write the command given below:

     UpperTriangularMatrix=triu(A)

    • It's time to create the lower triangular matrix. So write the command.

     LowerTriangularMatrix=tril(A)

    • For the null matrix, we are going to use:

    NullMatrix=null(2,5)

    • For the singular matrix, we are using the following command:

    SingularMatrix=ones(3,4)

    • If you wish to have a diagonal matrix of A, write the command:

    DiagonalOfMatrix=diag(A)

    • To sort your matrix A, we are using the command given below:

    SortMatrix=sort(A)

    • If you want to find the hermitian of the matrix, first you have to introduce the complex matrix in MATLAB. So we are writing the following matrix:

    B = [1+j; 1-j; 2-j; 1+2j]    

    • Now, by simply applying the command, we can get the hermitian of this matrix.

    HermitianMatrix=B’

    Thus, today’s lecture was full of different types of matrices, and many of them were new to us. We began with the definition of the matrix, then we saw different types of it where the data or the elements of the matrix were important. Many of them have conditions where the order and location of the elements are important. The concept of transport in the matrix was new to us, and by using it, we explored different types. In the end, with the help of different commands in MATLAB and with the help of practice, we sharpened our concepts. There are different and interesting types of matrices, and we are going to explore all of them in our upcoming lectures.

    Introduction to Matrix in MATLAB

    Hello, learners welcome to The Engineering Projects. We are working on MATLAB, and in this tutorial, you are going to learn a lot about matrices in MATLAB. We are going to learn them from scratch, but we will avoid unnecessary details about the topic. So, without wasting time, have a look at the topics that you will learn in detail.

    • What is an array?

    • What is the matrix?

    • How can we declare a matrix in MATLAB?

    • What are the different types of matrices?

    • Can we find the unknown values of two equal matrices?

    • How can we solve the simultaneous equation in MATLAB?

    What is an Array?

    In this world of technology, the use of data is everywhere, and therefore, we can say there is a need for arrays in every field. You will find the reason soon. But before this, look at the introduction of an array.

     An array is a simple data structure that contains a collection of data presented in contiguous memory locations.

    So, the term “contiguous” used in the definition tells us that the data is in a continuous format, so we are not required to search here and there because the data is in a structured format. Moreover, arrays are of many kinds, such as

    • Two-dimensional arrays

    • Three-dimensional arrays

    In different types of cases, the suitable array is picked up so that we may get the best result with limited memory occupancy. With this type of foundation concept, we can now move forward toward our main topic, which is matrices. 

    What is a Matrix?

    In real-life applications and in higher studies, matrices are used in plenty in different forms, and therefore, we have decided to talk about them from a very basic level since it is important to understand the key features of the topics we are studying. Moreover, matrices are introduced in early classes, and it is important to refresh the basics in our minds so that we may proceed to the more complex problems. Here is the definition of "matrix":

    A matrix is a two-dimensional array in the form of an ordered rectangular array enclosed by a square bracket that has entries of the same kind in it in the form of real or complex data.

    The plural of the matrix is matrices, and sometimes the rectangular bracket is replaced by the parentheses according to the case. Just look at the image given below:

    This is a matric that contains nine elements, and you can also name this matric anything you want. In this way, it becomes easy to deal with more than one matrix, and you will see this action soon.

    Order of a Matrix

    To proceed forward, you must know the types of matrix and, for this, it is important to know the order of the matrix.

    The matrix given above is a square matrix and the horizontal lines are called columns, whereas the vertical entries are termed the rows of that particular matrix.

    If we represent the rows with the name m and the columns as n, then the order of the matrix is given as:

    mxn

    In this way, it is clear that the matrices given above have the order 3x4. If it seems to be an unnecessary thing to you, think again, because, with the help of order, we can know the type of a matrix and then perform different types of operations on it. But before this, have a look at some code in MATLAB to design matrices of different kinds. 

    Code for the Simple Matrix

    The Matrix is easily used in MATLAB, and you can start working with it by following the simple steps given below:

    • Start your MATLAB software.

    • Go to the command window.

    • Start writing the following code:

    A=[23 14 -8 33; 17 -102 0 37;3 -31 98 4];

    • Press enter. 

    In the image given overhead, these are the same entries that we have seen in the image given above, and in MATLAB, you will see the following result:

    The square bracket is not shown on the sides of the array in MATLAB. As you can see, the semicolon after every three entries indicates that the row is completed and the MATLAB compiler has to start the other row. 

    Here, A shows the name of the matrix that is compulsory, and you can name your matrix any word. If you do not follow the exact format and provide the number of entries different in rows, you will get the error. Once you know how to get started, you are ready to learn about the types of matrices.

    Types of Matrices

    There are several different types of matrices, and you can perform different arithmetic operations on the matrices only if they are of the same kind. This condition is not applied to all the operations, but most of them follow these rules. Here are some important types of matrices.

    Row Matrix

    A row matrix contains only one row and it is one of the simplest forms of a matrix. In this way, we get the matrix with a horizontal shape. The order of this matrix is:

    mxn=1xn

    Where n may be any number. 

    Column Matrix

    As you can guess, the column matrix is a type of matrix containing only one column and one or multiple rows. In this way, we get a matrix that has a vertical shape. Have a look at the order of a column matrix:

    mxn=mx1

    Where m may be any number, but the value of n is always one.

    Square Matrix

    A square matrix always has the number of rows and columns equal. It means, that no matter what the total number of entries is, the number of entries in each row and column must always be equal. In other words,

    m=n

    When you examine the example of a square matrix, you will get the reason why it is called so. The shape of this type of matrix is always square.

    Rectangular Matrix

    A rectangular matrix is one that has the arrangement of elements in such a way that the number of rows of the matrix is not equal to the number of columns. The same statement can be represented in the equation given next:

    m!=n

    Therefore, the matrix formed is in a rectangular shape, either in vertical format or horizontal format, according to the number of rows and columns.

    Diagonal Matrix

    We all know that the diagonal is the line or area that joins the upper left area with the lower right area of a rectangular or square. By the same token, a diagonal matrix is the one that contains all the diagonal values equal to zero and s in such a way that all the values other than the diagonal are zero. It will be clearer when you see the example of the diagonal matrix. We have set the examples of all the types of matrices that we have defined previously into a single MATLAB screen so you may have the best idea of each of them.

    Code and Output

    Moreover, here you can observe that instead of naming the matrices A, B, and so on, we have used the real names of the matrices for a clear declaration. Your homework is to make examples of each of them by yourself for the sake of practicing.

    Finding the Unknown Values Between Two Matrices

    Do you remember when we said the order of the matrix matters? This is one of the uses of an order of a matrix. Suppose we have two matrices named A and B, declaring that both are equal. This means that each corresponding value of a matrix A at position row 1 column 1 is equal to the corresponding value of the same position of matrix B. This is true for all the remaining values q of both matrices. Let me be clear with one example. Have a look at the picture given below:

    So, the value of r and, in return, the value of all r variables in each entry can be easily obtained by following the rules of the equation. It is one of the simplest examples of doing so, but in real life, we face complex problems. So, we use MATLAB for simplicity and accurate results. Have a look at the MATLAB code where we are going to show you an application of you can easily solve the simultaneous equation in MATLAB as well. 

    Solving Simultaneous Equations in MATLAB

    By using the property of the matrix of equality in more than one matrix, we can easily solve the simultaneous equations that are difficult and time taking if we solve them by hand. So let's see how we can declare and solve the simultaneous equation in MATLAB.

    Code:

    syms x y

    equa1= 6*x + 9*y==13;

    equa2= 9*x + 6*y==12;

    [A,B]= equationsToMatrix([equa1,equa2],[x,y])

    z=linsolve(A,B)

    Output:

    Understanding the Code

    To understand this code, you have to learn the basic definition of the function we have used in the code. It is the equationsToMatrix function. 

    equationsToMatrix Function

    The equationsToMatrix is a pre-defined function of MATLAB that converts the linear equation into a matrix so that we can use different operations on it more efficiently. It does it in the same way as we do in real life while solving the simultaneous equation with pen and paper. There are three types of syntax if this particular function. The one that we have used has the following syntax:

    [A,b] = equationsToMatrix(eqns,vars)

    Here, a minimum of two equations are required and the variables have the same condition. You must keep all the functions in mind and have to follow the exact syntax. Otherwise, it will show an error.

    linsolve Function in MATLAB

    In MATLAB, to solve the linear equation, we use this pre-defined function as it works in two ways:

    1. LU factorization with partial pivoting when in equation AB=X, A is a square. 

    2. QR factorization, otherwise.

    In our case, it has used the QR factorization. Now, you are able to understand the code clearly. 

    • First of all, the syms sign tells MATLAB that we are defining the variables. These may be one or more. But, we wanted two variables here, and we named them x and y. 

    • Now, we simply provide the values of the equation to MATLAB and store both of them into variables named equa1 and equa2 respectively. 

    • The values of variables and equations are fed into the eqautionToMatrix function to convert the linear simultaneous equation into a matrix for easy solving. 

    • In the end, we simply named a matrix z and told MATLAB that we wanted the value of variables x and y.

    Simultaneous Equation in MATLAB: Method 2

    By the same token, we can use the other method that is similar to it but the way it solves the equation is a little bit different. 

    Code:

    syms x y

    equa1= 6*x + 9*y==13;

    equa2= 9*x + 6*y==12;sol=solve([equa1,equa2],[x,y])

    asol=sol.x

     bsol=sol.y

    Output:

    Here, the only pone this is to understand. sol.x and sol.y are the functions that are used by the compiler to find the value of variables x and y respectively. You can use any variable with this sol function, after naming them at the beginning. After that, a variable is used to store and present the value of the answer obtained.

    It was an interesting lecture about the matrix, and we worked a lot from scratch to the end on many topics. We have defined the arrays and seen the introduction of the matrix. We also found information about the types of matrices. Once we have a grip on the basics, we learn that a matrix can be used to find the unknown value of two matrices, and as an application of this method, we found the values of the variable by using linear equations and learned how to declare, use, and solve the linear equation with the help of matrices in MATLAB.

    Ramp Response of an LTI System in MATLAB

    Hello readers, Welcome to another tutorial about the signal and system. In this lecture, you are going to read details about the ramp response of a signal. In the past lectures, we have been dealing with different types of responses of LTI systems, and therefore, we know that linear invariant systems, or LTI systems, are those which follow the rules of linearity and are also time-invariant. So, at present, our focus is to examine what happens when the ramp signals are fed into the LTI system and which type of output signal we receive. Here is a glimpse at today’s topic that we will learn deeply.

    • What is the RAMP signal?

    • How can you define the ramp response?

    • How to use the ramp function in MATLAB to get the ramp response?

    • What are some important properties of the ramp function?

    • How is ramp response used in different fields in different ways?

    What is a Ramp Signal?

    We all know that a signal is a function of one or more variables that are independent and contain some information in them. When talking about ramp signals, we get the following definition:

    “A ramp signal is the one that always has its initial condition at 𝑡  = 0,  and with time, this signal increases exponentially. Therefore, it is linear in its behavior with time.“

    So, when representing these with the help of graphs, we get a smooth result all the time instead of any abrupt change in the pictorial representation. 

    As with other types of signals, ramp signals can also be described in two ways:

    • Continuous-time signal

    • Discrete-time signals

    When the ramp signal is in the form of continuous values, we represent them as:

    r(t)= { t for t=>0 } and {0 for t<0}

    Similarly, the same condition in the discrete-time format is described as

    r(n)= { n for n=>0 } and {0 for n<0}

    Let us clarify the meaning of the statements given above. In both cases, the value of t or n increases with time simultaneously. Therefore, we get the smooth slop in the case of continuous signals and smooth points when we are dealing with discrete ramp signals. In other words, the values on the x-axis and the y-axis for a ramp signal are always equal if we are plotting a graph for them.

    What is the Ramp Response?

    As we have discussed at the beginning of this lecture, linear time-invariant systems have the linearity property, and you can use the ramp function in the time-invariant system. It has the input at one end, then the input faces some procedures according to the conditions, and from the other side of this LTI system, we get the output. So, in simple words, we define the ramp response as:

    “The ramp response is one of the responses of the LTI system when the signal used as input is the ramp signal and the output of that system has the same features.”

    In some places, the ramp function is defined in other ways, but the basic definition remains the same as we have provided you before. Other ways to introduce the ramp function are:

    The resultant value is when the mean is calculated between the independent variable and its absolute value, which is called the ramp response.

    R(x)=(x+|x|)/2

    Here,

    R= ramp function 

    x = the variable based on which R is taken.

    Ramp Response in MATLAB

    Code:

    num=[0.9 0.18 0.27];

    den=[1 0.2 0.3 0.4];

    n=0:0.1:7;

    x=n.*(n>=0);

    y=filter(num,den,x);

    stem(n,y)

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('Ramp Response in CT') 

    Output:

    We have used the filter function in the previous tutorials as well. But, for a revision, it is important to know about it again. 

    Filter Function in MATLAB

    The filter function is used when the digital filters are to be applied to a vector in MATLAB. The information that is to be fed into this function is delayed before this function. The syntax is given as

    filter(b,a,x)

    Where

    b=co-efficient of the numerator

    a=co-efficient of the denominator,

    And x is different in different conditions. 

    • Filter returns the filtered data as a vector with the same size as x if x is a vector.

    • The filter operates along the first dimension of a matrix if x is one, and it returns the filtered data for each column.

    • If x is a multi-dimensional array, the filter operates along the first dimension of the array whose size is not 1.

    In our case, num and den are the matrices. So we are using the second case.

    Explaining Code for Ramp Response

    Have you seen the code? For a super easy-to-understand, we are going to discuss every step in detail. 

    • In the first step, we declared two arrays and stored their values in the num and den separately. 

    • In the second step, the time is provided to MATLAB, which shows the time has an upper limit of seven and a lower limit of zero. The interval between the times is taken as 0.1.

    •  Now, we have just used these two arrays for the multiplication and used the dot along with the multiplication sign so the compiler may understand that it has to multiply every term in the loop. 

    • In the next step, we are going to use all the results in the filter function, and this is the step that provides us with the results in a better manner. 

    • The results are then fed into the variable y. 

    • In the end, to get the result graphically, we used the stem function and provided the values of n as time. 

    Note:

    If you want to have the same graph in the continuous-time signal, you just have to:

    1. Replace the n with t for the best representation.

    2. Replace the stem function with the plot function.

    In this way, you will get the same graph, but the slope will be smooth. 

    Properties of the Ramp Function

    To deal with different types of cases when using ramp response, one must know the properties of ramp response in detail to avoid the long calculation all the time. So here are some of these:

    Laplace Transform of Ramp Response

    The Laplace transform is used to convert the system from the time domain to the frequency domain, and when talking about the ramp function, it says that the Laplace transform of a ramp function results in a calculation that is equal to the square of the variable based on which the integration of that ramp response occurs.

    Observe that this property is valid for the single-sided Laplace transform. 

    Fourier Transform of the Ramp Function

    The Fourier transform is another way to convert the function from the time domain to the frequency domain so that it may become easy to deal with that particular function. The process of Fourier transform on the ramp function provides us with the following results:

    Non-Negative Nature of Ramp Function

    At the start, we mentioned that the ramp function does not exist in negative values and that the values are always in positive coordinates. So, we can represent this property mathematically as

    ∀ x ∈ R: R(x)>=0

    In this way, the definition and nature of the ramp response are now clearer in our minds. There are certain conditions when the negative values of the ramp function and in return, ramp response are obtained. In such conditions, the negative values are always ignored.

    Derivative of Ramp Function

    To know about this property, you must know about the Heaviside step function. It is the type of step function that always has a zero for negative values and one for positive values. It is usually denoted with a capital H. When we take the derivative of the ramp function, we get the Heaviside step function. When writing it mathematically, we get the following equation:

    R’(x)= H(x)          for x !=0

    There are different conditions and properties of the Heaviside step function, but we are not going to explain them because it is out of the scope of this lecture. For now, you just have to remember the equation that we discussed just before this paragraph. 

    Applications of Ramp Response

    We know the signals are important in almost every type of field of science and therefore, we have the emphasis learning more and more about them. When the topic is ramp response, there are different ways in which ramp signals are used, and therefore, ramp response also has an application in that particular field. So let’s discuss the important fields where ramp function and, in return, ramp response are used. 

    System Testing using Ramp Response

    We know that in the ramp function, the values on the x-axis are equal to the y-axis and these are always positive values. Therefore, we can guess the results before the time. This property is easily used in different systems for testing different conditions or when starting a new system, it is used to check particular features. 

    Ramp Response in Engineering Fields 

    In different engineering fields, signals are used in different ways, as we are learning in one such subject, “Signal and System”. Electrical, computer, civil, and other engineering disciplines involve the use of ramp signals and ramp responses. 

    Ramp Response in the Filed of Finance 

    Those who belong to the field of finance know that the payoff of the call option is in the form of a ramp function, and therefore, ramp response has major usage in this field. The put option is set by flipping the ramp horizontally, and the short option is obtained when the ramp is flipped vertically. The graph formed in this way is called the "hockey stick" because of its shape. 

    It becomes easy to deal with the results, and we get accuracy.

    Using Ramp Response in Statistics

    When we use the ramp function, we face different conditions while studying statistics. Some cases are

    • Multivariate Adaptive Regression Splines or MARS

    • Hinge Function

    To deal with such complex calculations, it becomes easy to use the ramp properties so that unnecessary work may be ignored. For example, the non-negative property of the ramp function provides us the facility to ignore the negative values and focus on the calculations of positive values. 

    Traffic Signaling and Ramp Response

    It may look unusual, but the real-time application of the ramp function is in the traffic signals. A bottleneck is a situation when on the highway several vehicles are entered in an unmarred way and it results in the blockage of traffic. A ramp signal is used to break up this blockage, which is a cost-effective way to deal with this situation. The work is done. When the ramp signal is applied to the traffic lights effectively, this is one of the easiest ways to deal with this situation.

    Today, we learned a lot about the ramp response, ramp function, and unit ramp signal. We saw the introduction of all of these and the interesting thing about the ramp response was the code of the ramp response in MATLAB because it was so clean and easy to understand. In addition to this, we have learned about some properties of the ramp function that helped us to clear the concepts and to know how we can skip long calculations all the time if we know the properties of the ramp function. In the end, we had a glance at the application of the ramp function in different fields of science, such as statistics, engineering, and finance. We hope it was an informative lecture for you. Stay with us for more interesting lectures about signals and systems.

    Frequency Response of an LTI System in MATLAB

    Hello learners, Welcome to another tutorial on signals and systems. We are learning about the responses of the signals. We all have experience in situations where the change in the frequency of a system, such as radios or control systems, results in a change in the working or result of that system. So we have the idea that frequencies play an important role in different types of systems. In the previous lecture, we saw the impulse response of the system. Our mission today is to learn about the frequency response of the LTI system. We will learn all the basic information about the topic and will revise some important points as well. To do this, have a look at today’s concepts:


    • What is the LTI system?

    • What is frequency response?

    • How is frequency response performed without the function in MATLAB?

    • How is frequency response performed in MATLAB by using the function?

    • What are the applications of frequency response in other fields?

    What is the LTI System?

    We all know that a system is something that has input at one end and, after certain procedures on the input, the output is obtained from the other end. When talking about the LTI system, we define it as:

    “The linear time-invariant system, also known as an LTI system, is one that possesses both linearity and the time-invariant property simultaneously."

    Now, to make a solid foundation, let's recall that a signal is represented in the form of a wave, and all the waves are made of three basic quantities:

    1. Magnitude

    2. Phase

    3. Frequency

    The time period of the wave is the inverse of frequency, and in this way, if we know the magnitude (amplitude is used interchangeably), frequency, and phases, we can form a wave or signal. 

    The Frequency Response of the LTI System

    We are using discrete-time signals to learn the frequency response of the LTI system. The frequency response is the steady output of the system when the input is in the form of a sinusoidal signal. Before going into the proper definition of frequency response, you must know about the types of responses in the system. 

    Types of Responses in the System

    Responses are the types of behavior or results that a system represents. There are two types of responses in the LTI systems:

    1. Transient response

    2. Steady-state response

    The details of both of these are not necessary here. To make it simple, we are not discussing the transient response here. 

    Introduction to Frequency Response of the LTI System

    As we have read a little bit about this function, we know the type of response we are discussing. You must know that frequency is the steady-state response of the system, which means the frequency repose tells us how the system will work in the steady state.

    The frequency response of the LTI system is a type of steady response, and both input and output are in the form of sinusoidal waves with the same frequency but with different values of amplitude and phase angle.

    r(t)=Asin(ω0)              (eq. 1)

    Similarly,

    G(s)=G(jω)                 (eq. 2)

    If we represent the equation 2 in the form of phase and amplitude. then,

    G(jω)=|G(jω)|∠G(jω)

    Replacing ω with ω0 we get,

    c(t)=A|G(jω0)|sin(ω0t+∠G(jω0))

    So, by using these equations, one can calculate the magnitude and phase of the wave through frequency response.

    If you have the idea of impulse response that we have discussed in the previous lecture, then you must have an idea of how the LTI systems work. Yet, in the case of frequency response, we are going to study it in another way. It is now time to discuss some examples in which we will get the different procedures to perform the frequency response efficiently in MATLAB.

    Frequency Response Without Function in MATLAB

    Code:

    w=(0:10:600)*pi/300;

    z=exp(-1i*w); 

    x=3*(1-0.9*z).^(-1);

    a=abs(x);

    subplot(2,1,1);

    stem(w/pi,a) 

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    title('Magnitude')

    grid on

    b=angle(x)*180/pi;

    subplot(2,1,2);

    stem(w/pi,b) 

    xlabel('Angle /The Engineering Projects.com')

    ylabel('amplitude') 

    title('Angle')

    grid on

    Output:

    We have used a new function here, and we want to discuss it before elaborating on the program given above.

    Angle of the Wave through the Function in MATLAB

    To find the angle at which the wave or, in return, a signal is working, we use the following function:

    angle(x)

    This function calculates the angle of the wave whose value is stored in x and, after that, using the stem function of results, provides us with the resultant wave. Now let’s move toward the code and match the statements given next with the code.

    • It is a simple program that uses some basic operations. We are using these operations in a different way to get the output of the frequency response. Let’s discuss what happened in this code.

    • First of all, we have provided the value of omega. Here, time is represented in a simple way, as we have been doing it from the beginning so far in this series. Yet, multiplying the whole time period t with pi provides us with the value of omega. 

    • This value is used in the exponential form while it is being multiplied with the imaginary number. So, we are providing a variable z in which the whole value of the is saved. 

    • This is used to provide the equation that we want to work with. 

    • Once we get the equation, we are then using the absolute value of this signal and plotting it on the y-axis where the time period is on the x-axis as always. 

    • To get the angle of the wave, we are multiplying the angle results by 180 degrees and simply representing the data in the form of a discrete value graph. 

    Frequency Response Using Built-in Functions

    Code:

    a=-4*pi:0.4:pi;

    num=[7 1] ;

    den=[1 -0.32] ;

    h=freqz(num,den,a); 

    subplot(2,2,1); 

    stem(a/pi,real(h)) 

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('Real Part')

    subplot(2,2,2); 

    stem(a/pi,imag(h)) 

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('Imaginary Part')

    subplot(2,2,3); 

    stem(a/pi,abs(h)) 

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('Magnitude')

    subplot(2,2,4);

    stem(a/pi,angle(h))

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on 

    title('Angle')

    Output:

    We have used some built-in functions of MATLAB here, and the description of all of them is here:

    Real value Function in MATLAB

    This is an interesting function that takes a signal or wave and provides us with the value of the real part of the wave by ignoring the imaginary part containing values of iota and other imaginary numbers. You just have to feed the value of a signal into it. The syntax of this function is

    real(x)

    where x is any signal. 

    Imaginary Value Function in MATLAB

    Yes, you are guessing right. This is the function used to get only the imaginary part of the wave, and the real-time values are ignored with this function.

    imag(x)

    Here, x is the number/signal, and you just have to put the results into this function. 

    Let’s understand the code now.

    • At the beginning of this code, we provided the time period and stored it in the variable a. We used the variable t for this purpose, but I just want to show that it's just a variable and you can name it anything.

    • After that, we provided the information for our equation and then fed it into the built-in function of frequency response to get the results. 

    • In the end, the results are shown with the help of a graph for better representation. 

    • The equation provided by us had different parts, and for the best understanding of the concepts, we used each part of the signal and shown it in the form of a separate signal. 

    • In the second part of the code, we are using the stem operation, in which we use the time period on the x-axis and the imaginary part of the resultant signal on the y-axis. 

    • We all know that magnitude is the absolute value of some wave, and here, we are using the absolute function to represent the magnitude. We have also used this function in the other codes in this series. 

    • The last part contains the angle of this wave, and we have used the angle function here. In this way, the changing angles of the wave throughout this procedure are shown on the graph with the help of stem operation. 

    Frequency Response Using Fast Fourier Transform

    Let’s try to use some of the concepts of the signal and system that we have learned till now to calculate the frequency response in another way. 

    In the previous lectures, we have said that the transforms are used to convert the signal from the time domain into the frequency domain. We are using this concept and converting the frequency domain, and in return, we are simply presenting the signal in graphical form. For this, let’s try the shortest method, which is the Fast Fourier transform, and to make it simpler, we will use the built-in function in the code. All these concepts are used in the code given below, so have a look at them. 

    Code:

    signal=[11 44 12 27 53 19 34 ];

    a=fft(signal);

    subplot(2,1,1);

    stem(signal,a)

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('(n,fft(n))')

    subplot(2,1,2);

    stem(a);

    xlabel('n /The Engineering Projects.com')

    ylabel('amplitude')

    grid on

    title('(fft(n))')

    Output:

    Here you can clearly see that we have provided you with the two types of signals. One has the time on the x-axis and the frequency part on the y-axis. On the other hand, the second wave represents the frequency part of the wave only. 

    Application of Frequency Response

    As you can see in the information given above, frequency response is the measure of the magnitude and phase of the signals in the LTI system. There are several applications of frequency response, and some of them with their details are given below:

    Frequency Response in Sound Systems

    We all have experienced the role of frequency in sound devices, especially in the music system, where changing the frequency of the sound system results in a change in the quality of voice and some other features. Frequency response evaluates whether and how well an audio component reproduces each of these audible frequencies, as well as whether it modifies the signal along the way.

    Radio Spectrum Frequency Response

    There are certain frequencies that come in different regions and using these regions results in interesting applications. Changing in the frequency spectrum results in the usage of frequency response in the field of different cables, such as

    • Video switching

    • Twister pair cable

    • Coaxial cables, 

    and some other types as well. 

    When changing the radio spectrum of the cables results in a change in the behavior of the cables in working condition and the data rate and other features.

    Reading the Waves Through Frequency

    Frequencies are used in different ways to measure the infrasonic frequency response. We have seen that the prediction of earthquakes in the past was done with the help of the change in frequencies of waves. Moreover, some specific types of waves are used in the diagnostic and working of brain waves. In this way, frequencies are used in the medical field as well.

    Today we read about the frequency response and worked in MATLAB to get the concept through the practical implementation of the signals. In digital systems, frequency response is an important concept, and we have seen its multiple applications in different fields. These are just the introduction and when studied deeply, they can be used in complex systems efficiently. Get ready for other topics related to signals and systems that we are going to discuss with you soon. As for homework, you must practice more and more on these topics and try to solve the problems.  Examples are given in MATLAB theoretically by your own research and match the result to whether you get the same results when trying the theoretical procedures.

    Responses of Discrete Time Signals in MATLAB

    Hello learners, welcome to another topic of signals and systems. We hope you are having a reproductive day and to add more information in the simplest way to your day, we are discussing the responses in discrete-time signals. If you do not get the idea of the topic at the moment, do not worry because we are going to learn it in detail and you are going to enjoy it because we are making interesting patterns in MATLAB as the practical implementation of the topics. Have a look at the points that we are making clear today. 

    • What is the LTI system?

    • What is impulse response?

    • How can we get the impulse response in MATLAB?

    • How can we have the output signal using codes and impulse response in MATLAB?

    As we have learned so far in this series, there are two types of signals based on the shape of the signal we obtain, and these are

    1. Discrete-time signals

    2. Continuous-time signals

    The focus of our topic is discrete-time signals in which the points of the signals are not connected with each other, but we get a line for each point in the graph, and in this way, we get a non-continuous wave. There are different types of operations that can be performed on discrete-time signals to get useful results from them. The types of operations that we are going to discuss on discrete-time signals are

    1. Impulse Response

    2. Frequency Response

    Both of them are simple yet different from each other, and we are going to discuss all the necessary details about the impulse response in the next section. But to make a solid foundation, let us first define the LTI system. 

    What is an LTI System?

    We have read about the types of systems at the beginning of this course, and we know that:

    “The LTI system, or the linear time-invariant system, is those which have both characteristics at the same time, that is linearity and the time-invariant property."

    We are now moving towards the introduction of the impulse response.

    Impulse Response in DT Signals

    Recalls that a system is something in which we provide the input at one end of the system, the operations in the system take place on the input, and from the other end of the system, we get the output. 

    Now coming towards the impulse response, it is the procedure or the operation that is implemented on the discrete time signal and after the application of this signal, we get the required output. To clarify this statement, have a look at the image given below:

    The impulse response here is the procedure that converts the input into the required output. When calculating the result theoretically, we use the mathematical form of this image. 

    x[t]=h[t] * y[t]

    Considering the equation given above, we see that it is in the form of a time domain, and if we want to change it into a frequency domain, then we are using the Laplace transform (if you don't know it, recollect from the previous lectures).

    L(x[t])=(h[t] * y[t])

    Y(s) =X(s). H(s)

    And in this way, we can also change the form of the equation to get the required quantity. 

    Y(s) =X(s). H(s)

    Or

    H(s)=Y(s)/X(s)

    So, in this way, we can calculate the impulse response of the discrete-time signals. The H(s) here is called the transfer function, and these are used interchangeably. When we use the function in the time domain, we call it an impulse response, and in the case of the s-domain, we call it the ratio of input and output transfer function. Both of these are used for the LTI system.

    While performing the transform, the signal from the time domain to the frequency domain, you can also use the other forms of transforms as well, if you do not want to use the Laplace transform. The other two types of transform that we already know are

    1. Z transform

    2. Fourier transform

    Impulse Response in MATLAB

    Once you know the basic definition of the impulse response, you might be interested in the example. We are describing the two methods to perform the impulse response and instead of making two different programs, we are merging them into one. Suppose we want to perform the impulse response operation with the equation given below:

    ½(y[n]-⅓[y-1]+2/7[y-2]+1/7[y-3]=(x[t]+x[x-1]+x[x-2])/6

    Have a look at the program and if it confusing for you at the moment, do not worry, we are going to discuss it in just a bit. 

    Code:

    fs=25;

    t=0:1/fs:1;

    c=(t==0)

    num=1/3*ones(1,3)

    den=[1/2 -1/3 2/7 1/7]

    y1=filter(num,den,c)

    subplot(211)

    stem(t,y1)

    xlabel('Using filter method /The Engineering Projects.com')

    ylabel('Amplitude')

    grid on

    y2=impz(num,den,length(t),fs)

    subplot(212)

    stem(t,y2)

    xlabel('Using impulse Function /The Engineering Projects.com')

    ylabel('Amplitude')

    grid on

    Output:

    Filter (b,a,x) function in MATLAB

    The function of a filter is used to apply the digital filters to the equation with the values that are stored in the num and den. We all know that when dealing with the equations representing a  signal, the ideal format is the one in which the values of the variable y are on one side of the equation and the values of the x variable are on the other side of the equation. So keep this point in mind and look at the representation of the signal. The syntax of this function is given next:

    d= filter(b, a,x)

    Where:

    d= variable in which the result is stored

    a = values with the x

    b = values with the y

    c = time

    Impulse Response Function in MATLAB

    There is a built-in function in MATLAB to perform the impulse function, and you do not have to do much work to perform it. It will be clear with the help of the following syntax:

    impx(b,a, l, f)

    Where:

    b=values with y

    a = values with x

    l= length of the time duration

    f=frequency of the signal

    We have to declare the variables first and then just use them in the formula. We have used this formula in the code, and you will get the concept of working when you will learn the flow of this code. So let’s try to understand the whole code.

    • In the first part, we are providing the frequency with which we want to produce the output.

    • The time here is from 0 to 1, and the interval is the inverse of the frequency that we specify. We all know that frequency is the inverse of time.

    • The equation is presented as a numerator and a denominator. 

    • In the first part, we are using the method of filtering. 

    • In the second part of the code, the built-in impulse function is used and here we have to specify the length of the x that depends upon the time period of the signal that is specified by us in the code. 

    • After applying the values in the function, just use the stem function and the results are here in front of you. 


    You can compare the results in the code. Both methods produce the same output, and it is now totally up to you which type of method you prefer to solve your impulse response problems. Your homework is to look at the numerical values that are present in the command window and the workspace area to get the concept of the graph represented. 

    The Output of Impulse Response in MATLAB

    Now moving towards an interesting concept. Keeping this in mind, we can reverse the whole procedure easy to get the output of the system. At the start of this lecture, we said that by the convolution of impulse response and the input, we get the output. Let's look at this statement in action with the help of this code.

    Code:

    fs=100;

    f=5;

    t=0:1/fs:1;

    x=cos(2*pi*f*t)

    n=-0.9+(0.1+0.3)*rand(1,length(x));

    nx=n+x;

    num=1/3*ones(1,3)

    den=[1/2 -1/3 2/7 1/7]

    imp=impz(num,den)

    subplot(211)

    stem(t,nx)

    xlabel('Input /The Engineering Projects.com')

    ylabel('Amplitude')

    grid on

    y=conv(nx,imp,'same')

    subplot(212)

    stem(t,y)

    xlabel('Output /The Engineering Projects.com')

    ylabel('Amplitude')

    grid on

    Output:

    Isn’t it interesting? We have used the same equation and we can get the required results by using some different functions of MATLAB. We are going to introduce some functions used in this code one after the other, and after that, we’ll discuss the code.

    Random Function in MATLAB

    As the name of the function suggests, the results themselves. You can see it is used to choose any random number between the two that will be specified by us. The syntax of this function is:

    rand(x,y)

    Where:

    x= starting limit

    y = ending limit

    So, you just have to provide two numbers and this random function will choose any number between those limits and provide you with the random number. Keep in mind, that these are not the chosen numbers by the compiler but the limit of the quantity of the random numbers. It helps a lot in many systems and calculations where we want different results every time we run the code.

    The keyword “Same” in MATLAB

    This is a different kind of work that we have done in this code, and it will be new to you because we have not used it before in this series. While performing the operation of convolution, we require an equal length of both of the signals. If we do not do so, we’ll get an error because we know that convolution is the procedure in which two signals are overlapped with each other in such a way that we get the third signal. So, we just used the word “same” in the formula of convolution to get the same length of these signals. 

    Understanding the Code for Output of Impulse Response

    • First of all, we are going to provide two types of frequencies. One is for the time period and the other is used to provide the equation of input in which we are using the cosine function. 

    • We want to add noise to the signal. So here, we have specified a signal that is represented by the variable n. This has an upper limit of 0.1 and a lower limit of -0.1 (the difference between both of these is the plus sign). So in this equation, we are specifying two things:

    The limits of the number from which the values of noise signals will be picked and the number of digits that will be picked by the compiler as the length of the noise signal.

    • Do not be confused between these two types of limits. By using these kinds of conditions, we will always have a different type of signal with different lengths all the time when we run the code. 

    • Once the noise signal is generated, we’ll have the input signal containing both parts, the noise signal, and the cosine function. 

    • We have used the same equation that we used in the impulse function, so the impulse is the same as in the previous code. 

    • The input signal is shown with the help of a subplot and stem to represent the input signal. 

    • In the second half of this code, we are convoluting the noise and the input signal by using the same length of both these signals. 

    • The result is then stored in the variable y, which is represented in discrete values by using the stem function. 

    So, it was an interesting lecture in which we learned the impulse response in detail, and with the help of codes in MATLAB, we studied the input, output, and impulse generation in an easy way.

    Properties of Fourier Transform in MATLAB

    Hey, pupils welcome to the next session about the Fourier transform. Till now, we have learned about the basics of Fourier transform. It is always better to understand all the properties of a mathematical tool to understand its workings and characteristics. You will observe that most of its properties are similar to the topics that we have discussed before, and the reason is, that all of them are transforms, and the core objective of these transforms is the same. We have learned about the simple and easy discussion of the Fourier Transform, but when dealing with complex problems, it involves the usage of different properties so that we do not have to repeat the calculations all the time to get the required results. Have a look at what you are going to learn today:

    • What are the basic properties of the Fourier transform?

    • How can you ding the inverse Fourier Transform?

    • How to implement inverse Fourier transform in MATLAB?

    • What are some applications of the Fourier transform?

    So let’s start with the properties of this transform. 

    Linearity

    First of all, the Fourier transform is linear. It means if we have two expressions of the Fourier transform that are denoted by G(t) and H(t) then combining them with the help of mathematical operations such as multiplication or addition results in an expression that is also linear. 

    Duality 

    It is an attractive property of the Fourier transform that says when a discrete-time signal is transformed into the frequency domain, then it can be regenerated into its time domain form by multiplying it with a negative factor, but in this way, we will get the reverse of the original signal.

    Modulation of the Fourier Transform

    The modulation of the Fourier transform occurs only when both the signals, that are to be modulated are in the form of functions of time. 

    Time Shifting Property of Fourier Transform

    This property of Fourier transform says that if we are applying it on a function g(t-a) then it has the same proportional effect as g(t) if a is the real number. If you have a clear idea of the procedure of time scaling, it will be easy for you to understand the situation here. 

    Parseval’s Theorem of Fourier Transform

    This theorem is related especially to the Fourier transform. It says that the sum of the squares of a function x(t) is equal to the Fourier transform of the function x(t). 

    It is an important theorem because once we have this clear theorem, we do not have to calculate the square of the whole series of Fourier transforms. So, it becomes easy to deal with these quantities with the help of this theorem.

    Scaling in Fourier Transform

    Scaling of the signal is the process in which there is a change in the independent variable or the data features in the form of a range of the signal. This property says that if the values of the signals on the x-axis in the time domain are inversely proportional to the values on the x-axis when we convert them into the frequency domain. In other words, the more stretched a signal is in the time domain means less stretched and a taller signal in the frequency domain and vice versa.

    If

    f(t) = F(w) 

    Then,

    f(at) = (1/|a|)F(w/a)

    Convolution in Fourier Transform

    Convolution is the process in which two signals are overlapped on each other in such a way that we obtain a third signal that is different from the first two. When we talk about the convolution of the two signals, we get results that are equal to the convolution of the same function in the Fourier transform. 

    Mathematically,

    If 

    f(t) = F(w) and g(t) = G(w)

    Then, 

    f(t)*g(t) = F(w)*G(w)

    In this way, it becomes easy to predict the result if we know the value of one function and are interested in knowing the other.

    Differentiation of the Fourier Transform

    We all know the procedure of differentiation, and when we are differentiating the Fourier transform, we may get confused about following the rules of both these procedures. So, with the help of using this property, you can easily guess the results. This property says that:

    If

    f(t) = F(w) 

    Then,

     f'(t) = jwF(w)

    Where j is the variable and w is the function based on which the differentiation is occurring.

    Inverse Discrete Fourier Transform or DFT

    So far, we have learned how DFT is used to obtain the signal in the frequency domain. But what if we want the inverse results? What if we want our original signal back? Well, it is the requirement of a large number of applications, and then the inverse Discrete Fourier Transform is used. It is not a new concept to use the inverse methods, as we have also read it when we were discussing the previous transforms. 

    To perform the inverse method, we just have to simply follow the formula given below:

    All the other variables are the same. We just have to remember the formula and we are good to go. 

    Code:

    clc;

    x=input('Enter the Input')

    N=length(x);

    m=zeros(1,N)

    for n=0:N-1

        for k=0:N-1

            m(n+1) = m (n+1)+((1/N)*(x(k+1)*exp(((i)*2*pi*k*n)/N)));

        end

    end

    disp('m=')

    disp(m)

    Output:

    Let’s understand this code. There are a few things that we have used for the very first time in this series, and therefore, I want to describe them all. 

    clc; in MATLAB

    It is a very common and useful command that you will often see in the first place of almost every MATLAB code. The purpose of using this line is to clear all the data that you are looking at on the screen of your display window. 

    There is a window just below the working area of MATLAB called the “command window." main reason why we are discussing this line here is that we have not used the input function till now in this series, and therefore, I do not feel any need for this clear screen command here. This will be more clear when you learn about input functions. 

    Input Function in MATLAB

    In MATLAB, when we want to input the values of a particular quantity on our own, we use the following function:

    input(x)

    Where x is the quantity that we want to have the input of. Moreover, you can also use it to provide the statement on your own (as we have done in our program), but the statement should be enclosed in inverted commas if you want to print the statement as it is.

    disp(x) in MATLAB

    This is another function that we have used for the first time in this series. Well, this is the display function, and it is used to display the result or quantity that we want. Here in this code, for instance, we wanted to show the value of the result that we have stored in “m”. Therefore, we first displayed the m in inverted commas so that it was printed as it was, and after that, when we used the same function without the inverted commas, we got the value of the m that was stored before. 

    For Loop in MATLAB

    Loops are used in many programming languages, and if you have the basic concepts of programming languages, then you must know that “for loops” in MATLAB are used when we want that compiler to stay at a particular line and repeat the same line until a particular condition is fulfilled. 

    In our case, we started the first loop when m=0 and it stayed at that particular line till the value was one less than N. The same case was with the second loop. Once the condition was met, the compiler moved toward the next line. 

    The syntax of the for loop in MATLAB is:

    for x:y

    Statement

    end

    Where x is the starting point of the for loop and y is the ending point of the for loop, both of these are specified by the programmer, and a statement is a calculation that we want to perform again and again.

    Explaining the Code of IDFT in MATLAB

    • Clc clears the screen of the command prompt in case you are using the code for the second or more time. 

    • The input function displays a message to the user that input is required from him/her. 

    • The input by the user is stored in the variable x. 

    • Now, we are introducing another variable, m, that stores the result calculated by the length function. It is the total number of values provided by the user. 

    • Here, we are calculating the number of zeros between the number 1 and the length of the input by the user that was stored in N. 

    • The interesting part starts here. We are using two for loops, which means we are nesting the loops. The condition of both of them has been discussed before. The formula that we have hardcoded inside these loops is used till the conditions provided by us are met. To perform the functions on the series of signals, loops are used in this way so that we do not have to write the same lines again and again.

    • In the end, when we have the results stored in the variable m, we just display it with the label m, and our program is completed.

    Applications of the Fourier Transform

    As we have mentioned that Fourier transform has great importance in many fields of education and science and therefore, great work has been done by using this technique. Some important fields and applications of the Fourier transform are discussed in this section. 

    Fourier Transform in Medical Engineering

    In medical engineering, where we get complex and hard results. The Fourier transform is an old technique and therefore, it is used in the field of medical engineering for a long time. The impulse response and delicate results in the form of the signal are fed into the compilers where these signals are tested and examined deeply in a better way. 

    Fourier Transform in Mobile phones

    Here is an interesting application of the Fourier transform. We all know that cell phones work with the help of signals and therefore, there is a lot of work that can be done by using the Fourier transform. If you are wondering how the Fourier transform is performed in the cell phone then you are at the right point. Actually, while making, testing, and designing cell phones and other such products, the rules and calculations of Fourier transform are used widely because of its precise result and research. 

    Fourier Transform in Optics

    As we discussed from the beginning, the Fourier transform works great with the signals. The optic is the field that works in the waves and delicate signals and therefore, the Fourier transform is used to sum all the results in a great way and to find the results according to the need. Most of the process occurs in the optics when the light or other rays are merged into one point, and with the collaboration of other techniques, the Fourier transform works great to make all the procedures easy and accurate. Moreover, the Fourier transform is also useful for the smoothness of the signals and filtering of the results as well.

    So, today we learned interesting information about the Fourier transform, and now we can say that we have all the basic information about the Fourier transform. We have seen the properties of the Fourier transform and also learned about the inverse Fourier transform, along with the MATLAB code for a perfect concept. The concept of the for loop, clc, and input method was new to us. In the next session, we are going to talk about the comparison of all these transformations. So be with us.

    Introduction to Z Transform in Signal and Systems with MATLAB

    Hey learners! Welcome to another exciting lecture in this series of signals and systems. We are learning about the transform in signals and systems, and in the previous lectures, we have seen a bulk of information about the Laplace transform. If you know the previous concepts of signal and system, then this lecture will be super easy for you to learn, but if your concepts are not clear, do not worry because we will revise all the basic information from scratch for our new readers. So, without wasting time, have a look at the topics of today.

    1. What is z transform? 

    2. What is the region of convergence of z transform?

    3. What are some of the important properties of the region of convergence?

    4. How to solve the z transform?

    5. What is an example of the z transform in MATLAB?

    6. What are the methods for the inverse z transform?

    What is z transform?

    You must have an idea that the Laplace transform is a general case transform and converts the signal from a time domain into a frequency domain. The same is the case with the z transform, it changes the domain of the signal but in another way. The Laplace transform is associated with the power signal and the z transform has some other characteristics. Usually, the z transform is used to understand the stability of the system. Z transforms are used in

    • Energy signals

    • Power signals

    • Neither power nor energy signals

    Yet it is applicable to a certain level, and after that level, it is not that much more effective. The Z transform is a powerful mathematical tool and is widely used in mathematical courses and applications including signals and systems. We introduce the z transform as:

    "The Z transform is a mathematical tool that, after different procedures, converts the differential equation (with time domain) into the algebraic equation of the z domain."

    Mathematically, we show it as:

    As you can see clearly, the summation sign contains the limits from negative infinity to positive infinity which means it is a bilateral function of the z transform that we have shared with you. 

    By the same token, you can also predict that the z transform also has another region that lies between the zero to positive infinity. It is called the unilateral z transform and it works a little bit differently than the first case discussed here. We describe it as:

    Let’s discuss the whole statement in detail but prior to starting, recall in your mind the definition of discrete-time signals. We know that:

    “A discrete-time signal is one whose value can be measured at discrete intervals." When working with a discrete-time signal, there will be time intervals of n during which you will not have a value. In the representation of DT signals, the form x[n] is used. Discrete signals approximate continuous-time (CT) signals."

    Therefore, when talking about the z transform, keep the definition of z transform in your mind to understand what exactly is going on. 

    Now, look at the statement given above.

    • We have the discrete-time signal in the time domain represented by x[t]. 

    • We applied the z transform to it. 

    • Now, we got the same signal that lies in the z domain and is multiplied with a complex number z having the exponential of the n with a negative sign. 

    • Do not worry about the value of n all the time. The summation sign indicates that the value of n starts from negative infinity (or zero in unilateral z transform) to positive infinity, and in this way, we found the values of the series. (This will be much clearer when we discuss the procedure).

      Here z is a complex number that is described with the help of this equation:

      At this level, there is no need to describe the basic concepts of complex numbers. In general, we can summarize the above discussion through the statement given next:

      x(n)⟷X(Z)

      The whole discrete time signal is converted into another format with the z transform as a base,

      Region of Convergence of z Transform

      The region of convergence, or simply ROC, is an important term that is used to describe the range of z in the z transform. As we have said, z is a complex number and its range, therefore, has different types of properties. 

      Properties of the Region of Convergence

      • No. of poles: In z transform, where x[z] is always finite, there are no poles. (We’ll define them in a later section). The ROC of the z transform does not contain any poles. 

      • When talking about a right-sided signal, the region of convergence is always outside the z-plane circle.

      Where the shaded area is ROC.


      • When talking about a left-sided signal, the region of convergence is always inside the z-plane circle.

      Where the shaded area is ROC.

      • If we have the signal on both sides, then the region of ROC is in the form of a ring inside the circle. 

      • To have a stable form, the region of convergence has a unit value.

      Procedure to Solve z Transform

      There are different cases in the z transform that if we start to describe, will be more confusing and time taking than other transforms. So, we’ll discuss a general format of z transform, and after practice, you will learn the procedure effectively. 

      Thoroughly examine the question. 

      Use the formula of the z transform given above.

      • Put z into the denominator as it has negative power. Doing so will convert the negative power into a positive. 

      • Make sure you take the common values out of the sequence. 

      • Put the value of n as 0, 1, 2, 3, 4, and so on to get the series. 

      • Solve the equation.

      It is the most basic and simple description, but the z transform is not that simple. Instead of solving the long calculations, why not use MATLAB for practical implementation? If you have your own course instructor at university, you must have the idea of solving the procedure by hand. 

      Z transform in MATLAB

      In MATLAB, the z transform is as simple as the previous transform was. Therefore, we are emphasizing the usage of MATLAB at every step. Note that if you want to have a detailed procedure to perform the functions theoretically, you can find your instructors. But from the performance point of view, you should go to MATLAB to confirm your answers all the time. Here is a simple example of an equation that also shows some little details. 

      Code:

      syms n;

      f=(2*n+5)/3

      disp('x[n]=')

      disp(f)

      ans=ztrans(f)

      disp('z[n]')

      disp(F)


      Output:

      Here, you can see we have used the pre-defined function of z transform given as:

      ztrans(x)

      With the help of the z transform, you can solve any equation or expression that you want. 

      Notice that we have used a display function in the code. You must know that z transform can also be done in MATLAB without using the function. 

      Display function in MATLAB

      The display function is used to label the numerical output. It does the same work as the xlabel and ylabel in the graphical window of MATLAB. Moreover, this function is also used to call the value that we have specified before using it and to display the results directly. The syntax of the display function is

      1. disp(x)

      2. disp(‘x’)

      Where,

      • To display the string value, we use inverted commas around the value. 

      • To call the value of x, we simply use it as it is. 

      • Never use this function with a capital D or any other change in the spelling, otherwise, you will get the error. 

      Have a look at another example of the z transform in which we added two trigonometric functions and found their z transform.

      Code:

      syms n;

      f=sin(2*n)

      ans=ztrans(f)

      g=cos(3*3.14*n)

      ans=ztrans(g)

      Output:

      Zaros and poles of z transform

      When you study this particular topic of z transform, you will hear some terms named as zeros and poles. These are the simple topics while learning z transform and usually, are used in the numerical problem. Consider the following equation:

      Zeros: while solving the equation with the fraction, the numerator contains the M roots corresponding to the zeros. In the equation given above, q represents the zeros.

      Poles: When you are solving the fractional equation by z transform, the N roots in the denominator are called the poles. Here, these are represented with the letter p.

      While solving the z transform, we make a circular representation to solve the equation, just like we did while we were learning ROC. Poles are represented at the y-axis, and zeros are represented at the x-axis.

      Inverse z Transform

      As you can guess from the name, the inverse z transform is used to convert the results of the z transform into the form before the z transform. There are different methods through which the calculations of the z transform are inverted from an equation. 

      1. Long division 

      2. The partial fraction method of inverse z transforms

      3. Residue method

      4. Power series of inverse z transform

      Long Division Method 

      This method is applicable when:

      • There is a ratio of two polynomials

      • The polynomials can not be factorized

      To apply inverse z transform with this method, the division process of numerator with denominator is carried out. The resultant equation is then passed through the procedure of inverse z transform and we get the results. It is a complex method. 

      Partial Fraction Method of Inverse z Transform

      This is the method that involves the rules and procedure of partial fraction (we have received it in the previous lecture) and after that, the inverse z transform is applied. 

      Residue Method

      There are different names for this method including the inversion integration method and contour integral method. For this method, we have to follow the equation given below:

      The inverse z transform is obtained by summing up all the residues of this equation from the poles point of view.

      Power Series of Inverse z Transform

      In the end, this is the simplest and easiest way to find the z transform. In this method, the equation is expanded and we get the series of ascending powers. After that, the coefficient of z^-n is the required result. 

      Inverse z transform in MATLAB 

      To apply the inverse z transform in MATLAB, we use the following formula:

      iztrans(x)

      For convenience, we have put the process of z transform and the inverse in the same code. 

      Code:

      syms n;

      f=sin(2*n)

      F=ztrans(f)

      G=iztrans(F)

      Output:

      You can clearly see that we got our required result easily. This type of transforms is used when the data is being transferred to different networks. There are many applications of this transform and you will learn about them in the next section. 

      We have started the discussion of another transform named the z transform that is somehow similar to the Laplace transform that we have learned in the previous sessions. Z transform is a useful mathematical tool and we studied the ROC, procedure, and the inverse method of z transform. We also saw some examples in MATLAB. In the next lecture, we are going to learn some other basic information on the same topic.

      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