The article will cover essential aspects of fluid statics and pressure forces applied to the fluid. The article will start with the absolute pressure gauge and the variation of pressure with depth in different gravitational field manometers and barometers, respectively. Then I will explain the forces that deal with fluids, such as hydrostatic force, buoyant force, etc. So, dear friends, without wasting any time, let’s start.
The definition of pressure according to fluid mechanics is as follows:
Pressure is the normal force applied by a fluid per unit area.
The units of pressure Pascal is too small to deal with in practical cases. For instance,
Kilopascal: 1kPa=103Pa
Mega Pascal: 1MPa=106Pa
The three common pressure units used are standard atmosphere bar and kilogram-force per square centimeter.
1bar=105Pa=0.1MPa=100kPa
1atm=101,325Pa=101.325kPa=101325 bars
1 kgf/cm2=9.807 N/ cm2=9.807×m2=9.807×104Pa
=0.9807bar
=0.9679 atm
The unit of pressure in the English system is pound-force per square inch (psi or lbf/in2)
The actual pressure at a given position is called absolute pressure. The pressure is measured relative to an absolute vacuum or absolute zero pressure.
The difference between the absolute and local atmospheric pressure is called gage pressure.
The pressure below the atmospheric pressure is called vacuum pressure.
All three of these pressures are interrelated with each. Other, and this is visible with the formulae as mentioned below:
Pvac=Patm-Pabs
Pgage=Patm-Pabs
The following diagram shows the relation of the pressures from the below-mentioned diagram:
We all know there is no fluid pressure change at rest and in the horizontal position. This phenomenon can further be elaborate on a few points:
Assuming a thin layer horizontally of fluid followed by force balance at any point. The pressure increases as the depth increase as there are more layers of fluids, and these layers are being balanced by the pressure increasing.
An example can explain the whole phenomenon.
Toto show how pressure changes with the change in depth. We assumed a rectangular fluid element, as shown in the diagram.
The length, width, and heights are mentioned on the diagram.
The pressure of the fluid is constant, whereas force balance in z direction vertically will be:
∑Fz=maz=0
P2△x-P1△x-ρg△x△z=0
Now, we will divide the above equation with delta x △xand will get the below-mentioned equation:
△P=P2-P1=ρg△z=sz
Here, one of the most important things is that the s is the specific weight of fluid.
The final statement to be noted is that there is an increase in pressure linearly with an increase in depth.
It is essential to note that the pressure force applied by the fluid is always normal at some points to the surface.
As pressure is a scalar quantity, sometimes it seems to be vector one. The pressure will be the same in any fluid at any point. To prove this point, let us discuss a scenario.
Let us consider fluid element (a wedge shape/ right-angled triangle) at equilibrium.
The mean pressures at three surfaces are mentioned as P1, P2, and P3, respectively.
The diagram shows the points clearly.
Here, the value along the pressure is the surface area.
According to Newton’s second law, the force in the direction of x and z is as follows as △y=1:
∑Fx=max=0 P1△z-P3Isinθ = 0 (1)
∑Fz=maz=0 P2△x-P3Icosθ-12ρg△x△z = 0 (2)
Here, the value of w is the weight of the fluid, and the value is as follows:
W=mg
W=ρg△x△z/2
The value of △x and △z are as follows:
x = I cos θ
△z=I sinθ
So, by substituting all the values in equations 1 and 2 and then diving equation 1 with △z and equation 2 with △x then, the final result will be:
P1-P3= 0 (3)
P2-P3-12ρg△z=0 (4)
Here, in equation 3 △, z drops to 0, and the final result will be:
P1=P2=P3=P
Numerous devices are used to measure fluid pressure and work on different principles. These devices are explained below briefly.
The definition of a manometer is explained as follows:
A manometer is a device in which fluid columns measure pressure differences.
The important key points about the manometer are explained below:
the manometer is used to measure small or moderate pressure differences.
If pressure is at a specific position inside any gas tank, then the pressure anywhere in the tank will be the same. But here important point to be noted is that it is for gases only as their gravitational effect is negligible.
The basic diagram of the manometer is shown as follows:
As we can see, two points in a basic barometer and a height h. So the pressure at point 1 will be the same throughout the tank so that P1=P2 and the pressure will be by the equation:
P2=Patm+ρgh
Here, h is the height of column fluid, which is in static equilibrium, and as we can see, the column is exposed to the atmosphere.
is the density of the fluid, and Patm is the atmospheric pressure.
Here, one important point to be noted is that the height of the tube is independent of the area of the tube.
The definition of the barometer is as follows:
A barometer is a device that is used for the measurement of atmospheric pressure.
The following are some important key points related to the barometer:
The structure of the barometer is the inversion of a tube filled with mercury in a container, which is exposed to the atmosphere.
The diagram shows the structure of the barometer;
Toto calculates the formula of the atmospheric pressure; we will follow the above diagram. As you can see, there is a point B, so this B equals atmospheric pressure. Point C inside the tube is assumed to have zero pressure as there are only mercury vapors above point C, and pressure above that point is low compared to the atmospheric pressure, so for ease, the pressure is taken to be zero. The formula of pressure is as follows:
Patm=ρgh
There are many other pressure-measuring devices that are in use in our daily life, and they are briefly explained as follows:
Bourdon Tube is a pressure measuring device consisting of a hook like a hollow metal tube that is connected to a dial indicator. There is a fluid inside the tube that is pressurized. When this fluid is being pressurized up to a point then the needle that is on the dial is deflected. The needle is read to zero when the tube is exposed to the atmosphere.
There are special types of pressure detectors that can convert the pressure effect into electrical energy and they are called pressure transducers.
When the mechanical pressure is created when the electric potential is applied to a crystalline form. Such kinds of devices are called Piezoelectric transducers.
In the introduction, I will extensively explain the property r and how to impact them are so. Let us start. Then I explain properties that are related to fluid flow.
First of all, I will start with the word Property. The definition of property is as follows:
The word property is defined as any characteristic of the system. There are two main types of the property named intensive and extensive.
Example
The examples of property are as follows
Temperature -T
Pressure - P
Mass – m
Following is a brief explanation of the types of properties.
The intensive properties are the ones that are independent of mass, temperature, density, and pressure. Therefore, they are presented in lowercase letters. But here stands an exceptional case, i.e., the temperature and pressure are only denoted with uppercase letters.
The examples of intensive property are as follows:
Velocity - v
Specific Internal Energy - u
Temperature - T
Charge Density - ne or ρ
Molality - m or b
The extensive property is the ones that depend on the size or extent of the system. They are presented by the uppercase letter, but here is an exceptional case for the mass presented by a lowercase letter.
Extensive properties are usually derived, so the following are some examples.
Total Energy
e= E/m
Specific Volume
v=V/m
The specific property is the ones that depend on that are derived from either extensive or intensive ones.
One of the simple examples of a specific property is the density of water; as we know, it is an intensive property. So the extensive property (derived ones) is the mass of water volume divided by the volume. Here both the mass of water and volume are extensive properties.
The term continuum is related to matter in this way: the matter is made of atoms, and their distance and compactness vary from state to state. As in solids, atoms are closely packed, whereas, in liquids, there is some distance. However, in gases, the atoms are spaced widely. So in the continuum, the matter is defined as continuous and homogenous with no holes.
The primary purpose of using a continuum is to treat properties as a point function, and there are no jump discontinuities as the properties vary in space continually. This only applies when the system size is large compared to the space in molecules. It is practically applicable in almost every case except exceptional cases.
At the start of the discussion, I discussed the properties such as intensive and extensive observed during the fluid flow. Now some more properties play a distinct role in the fluid flow and their importance. So without wasting any time, let’s start.
The density is defined as;
Density is mass per unit volume.
ρ=m
It is defined as
The specific density is the reciprocal of density, i.e., volume per unit mass.
υ=Vm
There are numerous factors on which the density depends. The most important of all is the temperature and the pressure, which change the nature of the substance.
In gases, an increase in pressure will decrease the temperature and vice versa.
Compared to gases, solids and liquids are incompressible, so an increase or decrease in pressure is negligible.
In solids and liquids, the temperature is an essential factor that changes the density compared to the pressure. For instance, at the pressure of 1atm, the density of water changes from 998kg/m3 to 975kg/m3. So the difference is about 2.3 percent which is negligible in many cases.
The definition is as follows:
The density of the substance is relative to the density of the well-known substance.
SG=H2O
As relative gravity is a dimensionless quantity, so the SI unit of it is as same as the density one, i.e., kg/L or g/cm3 (0.001 times density in kg/m3)
Specific Gravity of Substances
The following is the list of some substances with specific gravity at 0˚C.
Substance |
SG |
Blood |
1.05 |
Air (at 1 atm) |
0.0013 |
Wood |
0.3-0.9 |
Gasoline |
0.7 |
Gold |
19.2 |
Seawater |
1.025 |
Ethyl Alcohol |
0.79 |
The definition of specific weight is as follows:
The weight of a unit volume of a substance is known as specific weight.
s=ρg
The definition of vapor pressure is as follows:
Vapor pressure is the pressure applied by the vapor of a pure substance at the state of equilibrium with its liquid at a given temperature.
Some important key points related to the vapor pressure are as follows:
It is presented by Pv.
Vapor pressure is as same as saturation pressure Pv.=Psat.
Sometimes, vapor and partial pressure are considered one thing, but they have two different definitions and applications.
Increase in temperature increases the vapor pressure.
The following table shows water saturation or vapor pressure at different temperatures.
Temperature ˚C |
Saturation or Vapor Pressure kPa |
-10 |
0.260 |
-5 |
0.403 |
0 |
0.611 |
5 |
0.872 |
10 |
1.23 |
15 |
1.71 |
20 |
2.34 |
Some important terms are related to vapor pressure, and they are named saturation temperature and saturation pressure, respectively.
Saturation pressure is the pressure at which changes in the state of a pure substance occur at a given temperature. It is represented by Psat.
Saturation temperature is the temperature at which changes in the state of a pure substance occur at a given pressure. It is represented by Tsat.
The definition of partial pressure is as follows:
Partial pressure is the pressure of gas or vapors with a combination mixture of gases.
Some important key points related to partial pressure:
Partial pressure of water vapors has some atmospheric pressure, and the value is 0.3.
The absence of liquid equalized or less than the partial pressure of vapors to the vapor pressure.
At the state of equilibrium, the presence of partial and vapor pressure in the system then the system is saturated.
In open lakes, the evaporation rate is managed by the vapor and partial pressure differences.
As we know, vapor bubbles in the liquid collapse when they are moved or swept from low regions. The result is the production of high-pressure waves that creates destruction. The reason for explaining this is that the phenomenon is related to cavitation, and the vapor bubbles formed are called cavitation bubbles. The phenomenon mentioned above is called cavitation as it is the leading cause of destruction and causes performance to drop off.
Some important key points related to cavitation:
In designing hydraulics pumps and turbines, this phenomenon (cavitation) is prioritized
In flow systems, cavitation is not considered as they result in poor performance, turbulence and noise.
For checking whether cavitation is present in the flow system or not, cavitation is observed by a unique tumbling sound.
We are well known for the term that energy cannot be created nor destroyed but can be transformed from one form to another. There is various form of energy that we observe in our daily life.
So I will recall some of the vital energy that is used during the fluid flow:
The basic concept of kinetic energy is that anybody or system (comprised of energy) is in motion relative to the reference frame and is said to have kinetic energy.
K.E = 12v2
Here, v stands for the velocity of the system or body relative to the reference frame.
The potential energy is the energy possessed by the body or system due to elevation in the gravitational field.
P.E =gz
Here, g represents the gravitational acceleration, whereas z represents the elevation of the system or body concerning the reference position.
Thermal energy is the energy that is related to the temperature. So it is defined as the energy in the system responsible for temperature.
Q=c ∆T
Here ∆T represents the temperature difference, whereas c represents the specific heat.
After discussing all the energy, one important term related to fluid flow is the Enthalpy. So let us discuss enthalpy.
The enthalpy is the combination of internal energy and the product of volume and pressure. The enthalpy value is calculated with the help of pressure, temperature, and volume, respectively. The energy conservation law says that internal energy changes equal heat transfer. The enthalpy change is assumed to equal the heat transfer if the work changes the volume at constant pressure.
H=E +PV
Here, H is the enthalpy, E stands for internal energy, P stands for pressure, and V stands for the system volume.
The sum of all the energy of flowing fluid is called total energy.
eflowing=K.E+P.E+Enthalpy
eflowing=h+V22+gz
There is an expansion in fluids when they are heated, and they contract when they are cooled. This means that temperature and pressure are two essential parameters responsible for contraction and expansion. The temperature and pressure also change the volume or density of the fluids. But volume or density varies differently from fluid to fluid. So, two properties are related to the volume or density changes to the change in pressure. And they are named Bulk Modulus of Elasticity and Coefficient of volume expansion.
So let’s explain these two properties without wasting any time.
There is a similarity in solids’ and liquids' expansion and contraction principles. So, the definition of the bulk modulus is as follows:
Bulk Modulus of Elasticity is a property that is the ratio of change in pressure relative to the volume.
κ = -v(Pv)T= ρ(P∂ρ)T (1)
The formula can also be presented concerning the finite changes, as shown below.
κ≅ -∆P∆vv≅-∆P∆pp
Here ∆vv and ∆pp are dimensionless.
The unit of κ is psi or Pa.
Here, the temperature is kept constant, so the bulk modulus of elasticity presents the change in pressure to the change in volume and density of the fluid.
The above equation proves that the incompressible substance coefficient of compressibility (Bulk modulus of Elasticity) is infinite.
Increase in pressure decreases the volume.
The negative sign indicates Pv is a negative quantity, whereas the bulk modulus value is positive.
An important key point related to Bulk Modulus of Elasticity:
Bulk modulus of elasticity is also known as the coefficient of compressibility or bulk modulus of compressibility.
If the value of bulk modulus is significant, then firstly, the fluid is incompressible, and then a large amount of pressure is required for a small amount of fractional change in the volume.
When the equation is being differentiated, then
From the equation, it is evident an increase in one quantity decreases the other and vice versa. From equation 1, we will differentiate the ρ=1/v, and we will get dρ=-dv/v2. So after cancellation, the final result will be:
dρ=-dvv
The inverse of the coefficient of compressibility is called isothermal compressibility.
The formula is as follows:
α=1=-1v(∂v∂P)T=1(∂ρ∂P)T
It is observed that there is a drastic change in liquid density when it is increased or decreased. A property named coefficient of volume expansion is responsible for the fluid density difference at constant pressure and variable temperature.
𝛃=-1v(∂v∂T)P=-1(∂ρ∂T)P
The coefficient of volume expansion is represented by beta.
At the infinite changes, the formula is shown below:
-∆vv∆T=-∆pp∆T
Here, the pressure is kept constant.
Important key points related to the coefficient of volume expansion:
Increase in temperature increases the value of as they have a direct relationship.
∆T represents the temperature difference in the equation.
If we define viscosity, the most reasonable and appropriate term will be resistance. When the fluid flows, there exist layers of viscosity at that point. There are intermolecular forces in fluid when the fluid is more viscous. So the definition of viscosity will be:
Viscosity is a property that represents the internal resistance of a fluid to motion.
One of the best examples is the pouring of honey. As you observe, honey is dense and very has strong internal resistance.
η=2ga2(∆ρ)9v
We assume a sphere that is dropped onto the fluid, and then the fluid’s viscosity is measured.
Here ∆ρ is the density difference between the fluid and surface
a is the radius of the sphere
G is the acceleration due to gravity
Important key points related to viscosity:
When one layer moves adjacently to the other, some friction exists, which we named viscosity. The layers are moving at some distance and are named dy. The velocities of the fluids are u and u+du, respectively.
The graphical presentation of the layer velocity versus the distance is shown below.
The graph will explain the trends of velocity and distance. As mentioned, two layers are moving adjacently to each other, so the layer that is on top imposes shear stress on the lower layer, and the lower layer, in response, causes shear stress on the upper one.
There are two primary types of viscosity, and they are explained briefly as follows.
Following are some essential key points related to kinematic viscosity:
Kinematic viscosity is the ratio between dynamic viscosity and fluid density.
The formula of kinematic viscosity is as follows:
υ=
Here υ is the kinematic viscosity η is the absolute or dynamic viscosity, and ρ is the density of the fluid.
When the temperature decreases, kinematic viscosity also decreases.
Following are some essential key points related to dynamic or absolute viscosity:
Dynamic viscosity is the ratio of shear stress to the shear strain of motion.
Dynamics viscosity helps in the interaction of the molecules dealing with mechanical stress.
I hope you enjoyed reading the article and have an extensive overview of the fluid-flowing properties. Thanks for reading.
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | Raspberry Pi 4 | Amazon | Buy Now |
Greetings, and welcome to the next section of our Raspberry Pi 4 tutorials. In the last section, we discovered how to set up and run our self-host bitwarden on our Raspberry Pi. We learned how to set up admin panels and perform a wide range of actions, such as limiting the creation of new accounts and users for security purposes. However, in this guide, we will discover how to configure a PS3 or PS4 joystick with our raspberry pi and set up and run Xbox cloud gaming on our Pi 4.
Raspberry pi 4
SD card
Power supply
Ethernet cable or wifi
Xbox controller
Xbox game pass ultimate subscription
USB keyboard
USB mouse
HDMI cable
Through a service called Xbox Cloud Gaming, users may play a wide variety of games without having to download any software onto their devices. Here, we'll use Microsoft's Xbox Internet Gaming service to transmit these programs to your Pi 4. A membership to Xbox Gaming Pass Ultimate is required to use this feature. Xbox Gaming Pass is required for this streaming service, but the subscription unlocks a wealth of video game apps.
Incorporating Xbox internet Game streaming on Pi 4 is a breeze with the help of the Chromium internet browser. Remember that there will be some delay in responding to your inputs, but don't let that deter you from playing most games. As a bonus, this guide will show you how to convert your Raspberry Pi running the "light" version of the Xbox One operating system into a dedicated cloud gaming computer for the Xbox One.
Regarding game streaming services, Xbox internet Gaming isn't the only option for your Pi 4. Games can also be streamed to your Pi 4 using Google's Stadia program. Alternatively, you can use a streaming service like Steam to play your games on the go. To play games via Xbox Cloud, you'll need to be in a region where it's available.
You must fulfill a few prerequisites before you can begin using Xbox internet Gaming on your Pi 4. Here, you'll learn how to update your Raspberry Pi and set up the Chrome internet browser we'll need to connect to the cloud game platform. These instructions have been designed with Pi OS Lite compatibility in mind. The "Lite" version of Xbox internet Gaming will require additional effort.
To move on, we must ensure that our Raspberry Pi is up-to-date with the latest software. The software has to be updated so that we get the most incredible possible performance with the Xbox internet Gaming platform. You can upgrade your Pi's software to the most recent version using the following two instructions.
sudo apt update
sudo apt upgrade -y
After the update is finished, we can add any other software to our pi four that is required for Xbox internet Gaming. We'll primarily be using the Chrome internet browser, which can be obtained by running the instruction below.
sudo apt install chromium-browser xserver-xorg x11-xserver-utils xinit openbox bluealsa unclutter
We'll install just the bare minimum of software to get Chromium up and running on pi 4 OS Lite. Having a controller linked to your pi 4 is the next step. Most Xbox Cloud Gaming titles necessitate the usage of a controller. Despite the inclusion of third-party controller functionality, the Xbox joystick remains the superior option. And if you want to know which controllers work with their internet gaming platform, you can find that information in their official docs. Another option is to use a PlayStation joystick with Pi 4, and we will show you how to do just that.
You may have discovered that using a PlayStation joystick with a Raspberry Pi is not a walk in the park. This tutorial is written in the hopes of making the whole thing easier.
Here at the pi 4 Wiki, we have a comprehensive tutorial for connecting and setting up Ps controllers of all generations. We walk you through installing the six-pair program for PS3 controllers and configuring your joystick to work with your pi four and any Bluetooth-enabled device. The procedure of connecting a PlayStation 4 joystick to a Raspberry Pi via Bluetooth is detailed here, and alternate methods are provided in case your joystick is incompatible with the default implementation of Bluetooth. The pi 4 is compatible with various game controllers, including Xbox joysticks.
It's not easy to get a Ps3 controller working with a pi 4. If you want to use it wirelessly, we'll walk you through the setup process from start to finish. The wired PS3 joystick should function as simply a plug-and-play accessory. When using a PlayStation 3 controller, all of its functions must work correctly, and Sixad does just that. If you want to use a USB micro cable to connect the joystick to the pi 4, you should get one before you start this part of the pi 4 PlayStation tutorial. The configuration of the PS3 joystick for communicating with Wireless controllers is necessary for this.
The first step is to install a library, which will allow us to compile the six-pair code. The libusb-dev library enables the software to communicate with USB storage devices.
sudo apt install libusb-dev
Now that we have the necessary package loaded, we can get the six-pair script and set up a folder to store it.
mkdir ~/sixpair
cd ~/sixpair
wget http://www.pabr.org/sixlinux/sixpair.c
Now that we have the six pair code on our pi 4, we can build it with the help of the command below. Use this command to initiate a compilation using the GCC compiler.
GCC -o sixpair sixpair.c -lusb
Now that Sixpair has been compiled on our pi 4, we can connect our PS3 joystick to the RPi through its USB micro port. After connecting the joystick, use the following command to start six pair. So that our Wireless device can communicate with the joystick, Six pair will modify its settings.
sudo ~/sixpair/sixpair
If the six-pair program has successfully re-paired your PS3 joystick with your RPi's Wireless dongle, you will see the output in the terminal interface that looks like the example below.
After these modifications, you can disconnect the Playstation 3 joystick from the Pi 4; we won't need it plugged in through USB again unless you upgrade your Wireless adapter. You can either use the bluetoothctl program to communicate to the Playstation 3 joystick or compile and install sixad to manage the connection. We think you should give Wireless a shot because it works well with other wireless devices. Read on to learn more about utilizing Bluetooth to link your PlayStation 3 joystick. If you'd rather learn how to connect the joystick with SIXAD, you can do so below.
Now that the Playstation 3 joystick has been prepped for use with the Pi 4, we can proceed to pair the two devices. The first step is launching the Bluetooth setup tool on pi four by entering the command below.
sudo bluetoothctl
Our Bluetooth setup tool is now active, and we can turn on the agent and tell it to use the default agent. To do so, simply enter the two instructions below.
agent on
default-agent
Following the successful execution of the preceding command, the program will begin scanning for new wireless devices, allowing us to locate them.
scan on
Any nearby wireless device will immediately become visible in the command prompt. Put these out of your mind for the time being and focus only on the Playstation 3 controller. The controller may now communicate with the pi four by holding the Ps button. The terminal's command line will begin to fill up shortly.
The MAC address will show in a format similar to the following; be sure to write it down. It's the string of words delineated by colons.
A MAC address has just become available, so write it down. Now that you have the MAC address, you may put it to use in the subsequent command. By issuing the command below, we hope to establish communication with the gadget and retrieve its unique identifier. You may need to retry this command several times before it works if you've tracked down a MAC address, substitute "YOUR MAC ADDRESS" with it.
connect YOUR_MAC_ADDRESS
If your Ps3 joystick stops attempting to connect, please check the status and hit the Playstation key again. If the following text shows in the cli, the connection was established successfully. We can go on to the next phase now that we have the UUIDs.
We need the MAC address to add the device to our Bluetooth-approved approved list. This enables the controller to connect with the Raspberry Pi without human intervention. We can accomplish this by inputting this command into our Pi 4. Be sure to change "YOUR MAC ADDRESS" to the address you uncovered.
trust YOUR_MAC_ADDRESS
After adding your Playstation 3 controller to the authorized list, the terminal should read as follows.
We may now exit the Bluetooth settings tool on the Pi 4 since the Playstation 3 joystick has been successfully paired with the Pi 4. Type the following commands or press CTRL + D to exit the program.
Quit
The RPi can be restarted at this point. This is done to verify that our system performs as expected during testing. To force the Raspberry to restart, type the command below.
sudo reboot
After rebooting the Pi 4, you can verify that your joystick appropriately communicates with the device by pressing the Playstation button. The controller's lights will momentarily blink when it connects, but subsequently, assuming everything went smoothly, only one morning will stay on.
We need to install some prerequisite software on our RPi before we can begin compiling and configuring SIXAD. libusb-dev and libbluetooth-dev are required for compiling the sixad program and are essential libraries. Libusb-dev is a collection of source code that enables us to communicate with USB devices connected to a computer. To communicate with the Wireless stack in an OS, Libbluetooth-dev supplies the necessary code. In sixad's setup, this is what monitors for the presence of a Playstation 3 controller when it is plugged into the Pi 4.
sudo apt install git libbluetooth-dev check install libusb-dev
sudo apt install joystick pkg-config
Since we have everything we need, we can download the SIXAD repo from Retropie. We're using Retropie's fork because it includes some bug fixes and has been validated on the Pi 4. You can download the GIT repo onto our Pi 4 using the two commands below.
cd ~
git clone https://github.com/RetroPie/sixad.git
Now that we have the repo downloaded to our Pi 4, we can begin compiling. The following two instructions are all that are needed to compile SIXAD. The first line of code changes directories, and the second line of code builds the program by executing the makefile.
cd ~/sixad
make
Compiling the sixad code was the first step, but there are still a few things to accomplish before we can put it to use. The first step is creating a directory in which sixad stores all its user profiles. Create a new folder by running the command below.
sudo mkdir -p /var/lib/sixad/profiles
Let's finish by launching the checkinstall package we set up in the previous section. This program just verifies the current installation and, if necessary, executes the "make install" commands.
sudo checkinstall
During installation, you may be prompted to provide information or confirm selections; however, you can safely skip them and hit ENTER to proceed. Following completion of the installation, the following lines should show at your terminal.
The command below will launch sixad on your Raspberry Pi after completing the installation process.
sudo sixad --start
You should be prompted to push the Playstation key on your joystick to ensure proper operation. Connect the joystick to the Pi immediately.
Since we have sixad functioning, we need to set it the default loader at startup so we can always use our Playstation 3 joystick. The command below will insert sixad into the RPi's boot procedure.
sudo update-RC.d sixad defaults
The Ps4 controller can be used with the Pi 4 in various ways. There are a few of these that are easier to handle than others.
To connect your PlayStation 4 joystick to your Pi 4, the Sony Bluetooth Adapter is your best bet. Especially considering that, in theory, the dongle should work immediately upon removal from its packaging and connect with any of the approved Playstation 4 controllers.
To use Bluetooth, you'll need a Pi 4 or a USB wireless adapter in addition to the certified Sony Wireless adaptor. Although this solution should work for most Playstation 4 controllers, some users have reported success with a userspace gamepad driver named ds4drv. If you have already installed the SIXAD utility, you will need to remove it before you can use your Playstation 4 joystick with the Pi 4.
To use your Playstation 4 joystick, simply plug it into a USB port on your computer using the same USB connection you used to connect to your Playstation 4. The Playstation 4 joystick should automatically connect via USB and work without additional setup.
The next instructions are only necessary if you have followed the tutorial on pairing a Playstation 3 controller with a Pi 4 via Bluetooth. In that case, you can skip this part of the process to uninstall SIXAD.
The PS4 controllers cannot pair or function appropriately with SIXAD installed, so they must be deleted. Simply running the command below on Pi 4 will remove the compiled and configured sixad program we discussed in the PS3 part.
sudo dpkg -r sixad
Before setting up the rest of the system, let's double-check that our Pi 4 has the most recent updates by issuing the instructions below.
We will now start connecting our Playstation 4 controller to the Pi 4. The Bluetooth CLI utility will be used throughout this tutorial. Start up your RPi by entering the command below.
sudo bluetoothctl
After starting the bluetoothctl utility, we may activate the client and return it to its default settings by entering the commands below.
agent on
default-agent
We may now begin scanning for devices after activating the agent. Scanning must be started so that our controller appears when we initiate synchronization.
scan on
Now is the moment to simultaneously hit the "Share" key and the Playstation button, as depicted in the following diagram. Continue holding them until the joystick's light begins blinking.
If you see the output in the cli similar to what is shown below, jot down the MAC address. If you take the hex value after the ':' symbol, you have the MAC address.
If your joystick is still blinking, enter this command as soon as possible. When entering the MAC address, ensure to replace "YOUR MAC ADDRESS" with the actual value. It establishes communication with your Playstation 4 controller when you enter this instruction. Press the "Share" and "PS" keys to make the joystick stop blinking.
connect YOUR_MAC_ADDRESS
The following will display in the terminal window if the connection is successful.
So that the PlayStation 4 controller may instantly link to the Pi 4, we must now include our MAC address in the authorized list.
trust YOUR_MAC_ADDRESS
Now that the Wireless dongle on the Raspberry Pi recognizes the Playstation 4 joystick, we can exit the program by typing "quit." The next step is to verify the joystick's functionality.
Even though the joystick feature may already be present in your Raspbian distribution, let's install it. This set has the software we need to ensure our joystick is functioning correctly. You may get the program installed on your RPi by executing the following Unix command.
sudo apt install joystick
Once the joystick library is installed on your Pi 4, you can check js0 and retrieve its values by using the command below.
sudo jstest /dev/input/js0
Changing values whenever you move and push buttons on the joystick indicates that your Playstation 4 joystick is ready to use. However, you may need to resort to the userspace drivers if your joystick stubbornly refuses to function. Finally, after getting the joystick set up, we can move on to installing the cloud on the pi four os Desktop.
Gaming on the go with Xbox internet Gaming is a breeze with the Pi 4 OS Desktop and Microsoft's cloud service. Instead of devoting your computer solely to Xbox internet Gaming, you can use the desktop OS of pi 4. Chromium and iCloud can be accessed with the click of an icon and by entering the relevant URL, as shown below.
To access the internet with your RPi, launch the Chrome browser on the desktop. To access this, select the globe icon in your screen's upper right corner.
Open your internet browser and head to the Xbox internet Gaming website. To access this in Chrome, enter the following URL into the URL bar.
https://xbox.com/play
You'll need to sign in with your Xbox credentials if you haven't already done so from your Pi 4. You can access the login page by clicking the "Sign in" button.
You may see a "your browser is not supported" message after signing in. No need to panic; the XCloud server is compatible with the Chromium internet browser we are using on our Pi 4, so there's no need to switch browsers. To close this panel, click the "X" in its upper right corner.
Simply clicking on an Xbox game will begin streaming it to your Pi 4. Any gamepad, keyboard, or joystick can be used to navigate this interface.
There is a notice on the XCloud platform that says your streaming experience might not be ideal. Once you've selected a game for streaming to your Pi 4, you can keep playing by selecting the "CONTINUE ANYWAY" option.
You have now installed and configured the Xbox Internet Gaming platform to run on your Pi 4. Now that you know how to handle the joystick, you can have a blast playing the video game.
There are a few extra hoops to jump through to get the Xbox Internet Gaming platform working on a Pi 4 OS Lite device. After completing these procedures, your Raspberry Pi will automatically log you in and begin running Chromium.
If you wish to access Xbox Internet Gaming as soon as you turn on your Pi 4, you'll need to take the following settings. Skipping these will result in a login prompt for the "pi" user before you can use the internet browser.
We utilize the "Pi 4 Config tool" to set up our RPi so that it automatically enters the console at bootup, skipping the usual login process. The following command can be used to activate this utility on your gadget.
sudo raspi-config
Use the ARROW keys to move around the available options. To choose the highlighted item, use the Enter button. Starting with the raspi-config utility, select "System Options" from the drop-down menu. Select it by pressing the Enter button since it is the first choice.
You'll find "Boot / Auto Login" under "System Options" in the panel. Selecting this menu item may instruct the OS to log us into the console automatically.
The "Console Autologin" option comes next and must be chosen. If you select this, the Pi 4 will bypass the login screen and go straight to the console, where you can utilize the "pi" account.
Having made this selection, the RPi Config Wizard can be exited with the ESC key. When prompted, choose "Yes>," and then click the Enter button to restart the computer.
Once the RPi is set up to enter the console at startup, the "autostart" file can be edited to initiate the Chrome internet browser. In addition, we need to edit the ".bashrc" file by adding a single line to ensure that the window utility Chromium needs to run launched automatically after the operating system has loaded.
So, let's begin by editing the "autostart" script in the "/etc/xdg/Openbox" folder. We'll use the nano editor to make the necessary changes to this script.
sudo nano /etc/xdg/openbox/autostart
Please copy and paste the lines below at the very end of this script.
xset s off
xset s noblank
xset -dpms
unclutter &
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences
chromium-browser --disable-infobars --enable-features=OverlayScrollbar --kiosk 'https://xbox.com/play'
Our screensaver disable commands are located on the first three lines. We employ unclutter to conceal it merely as an alternative to entirely deactivating the mouse. This is helpful because we'll frequently use the mouse for things like logging in. Finally, we start Chrome on the RPi in kiosk mode, redirecting the browser to the Xbox Internet Gaming site.
After you've added these commands, save and exit the file. The final step is setting the Pi user's bash account so that the terminal automatically launches the window manager.
nano ~/.bash_profile
This line has to be added at the very end of this document. This line will check whether it is the first time starting the terminal and if so, it will set the "$DISPLAY" property. When these prerequisites are met, the "startx" statement will be executed to launch the window manager.
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx
When you're finished adding that line, save and exit the file. If we want to use Chromium immediately, rather than after an RPi reboots, we can launch the window manager directly. When you launch the window manager now, Chrome will also launch because you modified the "autoboot" script earlier.
Startx
Be sure you're typing this command into the terminal of your Pi 4 itself. If you try to use it with SSH, you will be disappointed. If you choose, you can force a restart of your RPi by executing the command below.
sudo reboot
Once the RPi and Chrome have been set up, Xbox Live Games can be accessed. Your Pi's internet browser should automatically launch to the Xbox Game Pass portal.
To use Xbox Internet Gaming for the first time, you'll need to sign in using your Xbox credentials. To access the login page, please click the image below. In any case, the "Sign In" button on this page will get you started with the login procedure if you didn't notice it before.
After logging in, you may notice a message indicating that your browser isn't supported. Since this is a Chromium-based internet browser, the "X" in the corner can be used to close the current window.
We can now play games on our Pi 4 by streaming them through Microsoft's Live service with Xbox Game Pass. Make sure the controller is plugged into the Pi before choosing a game. Xbox Cloud platform also allows you to use your controller for menu navigation.
Here's a notification to let you know that the internet browser you're using isn't supported, which will appear whenever you try to play a video game that requires it. Selecting "CONTINUE ANYWAY" will allow you to disregard this notice safely.
We can play "Phoenix Point" through the Xbox Internet Gaming service, broadcast directly to our Pi 4 in the image below. The stream may not appear where you expect it to when it first begins. However, once play begins, things should correct themselves.
Now you should be able to play Xbox games through the internet on your Pi 4. Because it is included with Xbox Game Pass, Xbox internet Gaming allows you access to various games. To a large extent, this video game streaming platform runs smoothly on the Raspberry Pi 4. There may be spikes in latency now and then, but if you play video games that don't necessitate pinpoint controls, you can probably overlook them. The following tutorial will teach how to utilize Raspberry Pi 4 as a radio streaming and broadcasting device.
Hey peeps, welcome to The Engineering Projects. We are talking about matrices, and if you want to learn them from scratch, you must go to the introduction to matrices in MATLAB. Today, we are learning how to perform different arithmetic operations on matrices. You will also see some interesting commands that are only applicable to the matrices. Here, it is important to notice that in MATLAB, the matrices are performed in the command window and there is no need to have the programming skills to perform them. Even if you are new to programming, you can easily perform the operations in MATLAB. We’ll discuss different basic operations on the matrices and will also perform each of them in MATLAB. Most of them are urinary operations and some of them are binary. Here is a small glimpse of today’s topics:
What is a matrix?
What are some basic operations of matrices?
What is an identity matrix?
How can we use the simple commands of MATLAB to perform complex and time-taking calculations with matrices?
We all know what matrices are matrices. Yet, it is important to learn the basic definition of the matrices because this will create a map of how the basic operations on the matrices are performed. So, a matrix is defined as:
“A matrix is a two-dimensional array with entries of the same kind in the form of real or complex data, and it takes the shape of an ordered rectangular array surrounded by a square bracket.”
The thing to notice here is, that the data present in the matrices are of the same kind and therefore, we can perform a simple operation on each of the entries by simply applying it at once to the whole matrix.
Now, have a look at the basic operations on the matrices.
There are several operations that can be performed on the matrices. Some of them are unary operations ( those operations that require only one matrix for the application) and most of them are binary operations that require two matrices for the performance. When you observe different types of each of them, we are going through the definition of each of them, and at the end, you will also practice each of them in MATLAB. So, have a look at the definition of each of them.
Yes, as you can guess, addition is a binary function, and you need two matrices to perform the addition of the matrices. The addition of the matrix takes place when both of the matrices have the same number of rows and columns. Each entry is added to the corresponding entry of the other matrix, and in this way, we get the resultant matrix with the same number of rows and columns.
One must keep in mind that addition is a commutative operation, which means if we have two matrices named A and B, respectively, then the addition process follows the rule given below:
A+B=B+A
All other rules are the same as the simple addition, but here, the equal number of rows and columns of the matrix is an additional rule that must be followed.
As with the addition, the subtraction of the matrices is a binary operation, it requires the same order of both the matrices and does not follow the commutative rule. It means:
A-B!=B-A
And that makes sense. During the subtraction of B from A, the element on B at a particular location is subtracted from the element present on the corresponding entry of A. So, if the value of this particular element is less than the element subtracted from it, we get the answer in minus. Therefore, subtraction is not commutative.
The multiply operation in the matrices is somehow a little bit different from the normal multiplication. Two types of multiplication occur in the matrices:
Multiplying the whole matrix with a scalar
Multiplying two matrices
Multiplying a single number with the whole matrix is called scalar multiplication. If we are multiplying a number k with the matrix, the multiplication of k with the matrix provides us with a resultant matrix that has each entry having the value k times more than before multiplication.
On the other hand, when two matrices are multiplied, the key point to remember is:
During the multiplication of two matrices A and B, the number of rows of matrix A must be equal to the number of columns of matrix B; otherwise, the multiplication is impossible.
Hence, if you are asked to multiply the matrices, this must be the first condition that you check. So, here is the procedure of matrix multiplication.
Check the number of rows and columns of matrices A and B.
Multiply each element of row 1 of matrix A with the column of matrix B.
Add all the results of this multiplication together.
Now, repeat the same procedure with the other rows of matrix A with the columns of matrix B.
In the end, you will get the resultant matrix that has the same number of rows as matrix A.
Therefore, the multiplication of the matrix is non-commutative and therefore we can say:
AxB!=BxA
This will be more clear when you learn the example in the next section.
The solutions to the operations that we have mentioned above are time taking and require a number of steps to be followed. The same results, but in a better manner, can be obtained with the help of MATLAB. Just follow the steps to perform these operations in MATLAB.
Fire up your MATLAB software.
Go to the command window.
Start writing the following code to make a matrix A in the command window:
A=[ 2 5 8; 1 8 2; 4 6 9]
The resultant matrix will be shown on the screen.
Now write the following code just below the matrix formed before:
B=[1 5 2; 4 8 9; 2 7 3]
The same result will be shown for matrix B.
Now, to perform the addition of matrix A and B, write the following command in the command window:
A+B
It will show the results.
Now write A-B.
You will get the results.
If you are performing all the operations according to the instructions, your screen will look like the following image:
For the multiplication of both types, there are different commands. For the scalar multiplication, we are using the simple command given next:
2*A
It will provide us with a matrix that has two times the values of matrix A.
For the multiplication of two matrices, the command A.*B is used. Here, the question arises why we are using the dot in between the A and B. Have a look at the results of the different types of multiplication. We have mentioned the results when we used this command and a simple command of multiplication as A*B.
Both types have different results. It is because using a dot between the A and B tells the compiler that we want the multiplication of each element with the other, and in this way, the authentic procedure for the multiplication is used as we have mentioned above in the multiplication section.
Similarly, we are testing the same condition while we want the square of the matrix. We all know that a square means that each and every value is multiplied by itself. On the other hand, if we simply apply a formula to multiply value 2 with the whole matrix, we’ll get the double of each value but not the square. Let’s see this in action in MATLAB.
You can clearly examine the difference between all the values. If we want to have the square of each element of matrix A, we have to use the third command with a dot between the matrices' names.
In the discussion in the previous lecture, when we were talking about the types of matrices, we mentioned a type called the identity matrix. It is the matrix that has the arrangement of elements in such a way that only diagonal values are 1, and all the other values in the matrix are zero. It is an interesting type of matrix, and when talking about the procedure for having an identity matrix in MATLAB, it is more interesting. The following command is used to make an identity matrix:
eye(x,y)
Where,
x=number of columns
y=numbers of rows
So basically, we are just telling the size of the matrix and MATLAB provides us with the result in a second, according to our wish. It may seem that it is a less common type of matrix, but that is not true. For many calculations, where the long and time-taking data is to be converted into a relatively simple identity matrix is used. It is also useful in systems where only binary data is used for calculations. There are some other uses of the identity matrix, but we are not going to discuss them because they are out of the scope of this lecture.
Let’s see this in MATLAB:
MATLAB provides us with great ease in dealing with the matrices and we can use them to easily get quick and easy access to our data. So go to the command window of your MATLAB again and run the following commands on it. It's fun. To compile all the things into just one table, we have added the commands that have been discussed in the early sections of this lecture.
Command |
Description |
A=[1 3 6; 4 8 2; 6 11 3] |
It forms a matrix with the name A which has three rows and three columns with the same entries mentioned in the bracket. |
A(2,1) |
It provides us with the elements present in the second row and third column. |
size(A) |
It shows us the size of matrix A, which is the number of rows and columns, respectively. |
length(A) |
It is used to know the maximum number of rows or columns. It provides us with only one number, either of the rows or columns, which has the maximum value among two. |
A(:) |
It is the way to convert the whole matrix into a single column with all the entries one after the other in a vertical manner. |
A(:,2)=[ ] |
It is used to delete the 2nd column (or any other that is specified) and show the resultant matrix. |
A(1,:)=[ ] |
It deletes the first row and second column, then provides us with a matrix having the remaining entries. |
ones(2,4) |
It results in a matrix that contains two rows and four columns, but all the entries are one. |
A’ |
It is used to get the complement of the matrix A. |
These are some very basic commands that are related to the information that we have provided you till now. A great number of commands are also associated with the matrices in MATLAB, and we are going to discuss most of them in our discussion, but it is not possible to cover all of them in a single lecture.
Thus, today we learned a lot about matrices. We have observed some very basic but specific actions that are only possible when data is in the form of matrices. It was interesting to know that we could easily perform long calculations in MATLAB with the help of simple commands in no time. We have seen some interesting commands in MATLAB with detailed descriptions. We have also examined the output at each and every step. There are some other functions of MATLAB that help us get the results of complex commands in seconds. You must practice more by changing the elements or the numbers of rows and columns and check what results from you get with the same commands. In our next lecture, we have a lot of information about matrices.
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?
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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:
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.
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.
In MATLAB, to solve the linear equation, we use this pre-defined function as it works in two ways:
LU factorization with partial pivoting when in equation AB=X, A is a square.
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.
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.
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?
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.
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.
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.
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.
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:
Replace the n with t for the best representation.
Replace the stem function with the plot function.
In this way, you will get the same graph, but the slope will be smooth.
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:
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.
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:
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.
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.
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.
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.
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.
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.
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.
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.
Hey readers, welcome to another interesting lecture of this series in which we are studying signals and systems. In the present lectures, we are learning the details about the responses of LTI systems, and today, you are going to learn the step response. We also talked about the impulse response and frequency response, and therefore, this lecture will be easy for you to understand because it is, somehow, related to the impulse response. If you are new to this concept, do not worry because there will be a revision of important points side by side. Have a look at the list of today’s concepts:
What is an LTI system?
How do you define the step response of an LTI system?
What is the code to run the step response of signal in MATLAB using different functions?
How can you find the detail of the graph of the step response?
What is the difference between step response and impulse response?
We are going to learn each of them in detail so that if you know any of these already, you may have a revision about the topic.
We all understand that a system is something that receives input at one end and produces output at the other end after performing specific operations on the input. We define the LTI system as follows when discussing it:
The term "linear time-invariant system," or "LTI system," refers to a system that simultaneously possesses both linearity and the time-invariant property.
So, keeping this in mind, we are going to discuss the whole concept of a step response in the LTI system. Refresh the definition of convolution in your mind so that it says convolution is the process in which two signals are overlapped in such a way that they form a third signal. So, keeping in mind the above image, we can use this concept to define the step response of the LTI system.
First of all, let us clear that step signals are the one whose values always lies in just positive time and for the negative time, these signals does not have any value. The unit step signals are usually denoted as u(t). So, mathematically, we can say the step step signals are formed with the value only when t> = 0, and for t<0, signals do not exist. In this way, we get the signal at the right area of the graph, that is, the positive side values of the time. By the same token, the step response is the behavior of the LTI system when the input is provided in the form of a step signal and the output then depends upon the integral of the impulse response of that LTI system. We’ll see the proof of this statement in just a bit, but prior to that, have a look at the definition of step response:
“The step response of an LTI system is obtained when the input provided to the system is unit step and, therefore, the output also has similar characteristics.”
Using all this information, we can derive the formula for step response:
s(t)=h(t)∗u(t)
Where:
s(t)= step response
h(t) = impulse response
u(t)=unti step response
Then,
S(t) = H(t). U(t)
S(t)=(1/t).U(t)
Now, applying the inverse Laplace transform to the equation given above, we get:
s(t)=∫h(t).d(t)
So this is the final formula that is used to calculate the value of the unit step function in an LTI system. You must know that here h(t) is the impulse response of the system that we also have read in detail in the previous session. You can have stronger concepts if you examine the example that we are going to discuss in the next section.
Code
num=[9];
den=[6 1 8 7];
a=tf(num,den);
step(a,0:0.1:8)
xlabel('n /The Engineering Projects.com')
ylabel('amplitude')
grid on
title('Step Response of LTI System')
Output:
There are some functions that are used here but are new to you. So, have a look at the details of each of them and then try to understand the code.
It is an important function in MATLAB that gives us the facility to have the same results by using this function instead of using many lines of code. Using this function, we can represent the numerator and denominator in polynomial form. The syntax of this function is
y=tf(num, den)
where num and den are specified before using this function. These are the numerator and denominator in descending power of s and are in the form of a polynomial. For example, in the code given above, the equation we used is
9/6(s)^3+1(s)^2+8s+7
Before the introduction of this function in this series, we used different and relatively complex calculations in the code to achieve the same results. In short, this function has made our work simpler.
MATLAB has a built-in function step that is used to get the step response of an LTI system. The syntax of the step function is given as:
step(x,y)
Where
x = the equation whose step function is required.
y = the time interval of the step function.
Usually, the equation is in the form of a polynomial and it is pre-defined when this function is called. You can also use the variable in which the time interval is stored before using it. Yet, we have used the exact time interval so that you may have the concept of doing so.
First of all, we have declared the values of the polynomials of the numerator and denominator and stored them in the variables num and den, respectively.
We have used the transfer function to convert these values into a polynomial equation and then saved the result into the variable a to use later.
Next, we used the step function and put all the required values in it.
Notice that we have not used the stem or plot function to represent the results in the graphical format. We have just used the labels on the graph. It means the step function itself provides you with the information in a graphical format.
Another thing to notice is the visibility of the text “Second” on the time axis of the graph. We have not used it in the x-label but it is automatically defined in the step function.
Here is an interesting thing about the step response. You can directly examine the graph by following some simple steps.
Write the code in the editor window.
Run the code
Provide the path and save the program.
A graph will appear as shown in the code given above.
To examine it clearly, left click on the graph.
Different options will appear on the screen. Hover the mouse over the characteristics.
You can tick the feature on the graph you want and can choose more than one at a time.
Once you follow the step given above, you will get the details according to the graph. A great overview of the graph is given in the image given below:
Let’s understand what is going on the each step and why these terms are labeled so.
In the graph of step response, overshoot is the area that shows the highest bump in the graph. Basically, it shows that values that are shot over the targeted values, which is why it is named so. At its start, the values indicate the values are exceeded to their steady state and at their end, the values indicate the transition from different values.
The rise time in the graph of the step response is the area that indicates the time required by the step response to reach 10%-90% of the final value to bring the system to a condition called overdamped. It also indicates the time limit when the system takes the time to reach 0%-100% to meet the underdamped condition.
The peak time of the step response is the specific value of time in the graph of step response when the overall response of the system reaches its maximum position. Usually, you can see that it is the peak value of the graph.
The response's settling time is the amount of time needed to calm oscillations and maintain a 2% to 5% error (or tolerance) band from its final value.
So, in this way, you can understand what is going on in the step response. It is a common question how the step response is different from the impulse response because the basics of both of them are similar and why do we find both of them in the signal?
Many times, when dealing with the signal, people are confused between these two because of the similarity in the system and some other resembling features. Therefore, we have made a comparison between these two, and here are some important points about them.
Impulse Response |
Step Response |
It is the derivative of the step response with respect to time. |
It is integral to the system with respect to the time of impulse response. |
The impulse response shows the behavior of the system when it gets a sudden start and it also provides information about the time at which this behavior will be experienced. |
It provides information about the system when a person wants to know the behavior of the system or if the signal lasts for a long time in it. |
The impulse response shows the values that are at a higher level at the start, but with the passage of time, it shows the smooth path that lasts for a long time, and we get a smooth result. |
It is the sudden change in the values of the system. It is the straight-up change in the values of signals, and if we plot the values of step response, we get a stair-like structure. |
There are several cases where it is more useful to have the step response over the other types of response. Some of the major reasons are listed below:
The step response is used because it does not require information about the dynamics of the system; hence, it can be run with the help of less information.
If we have the values of the step response, we can find the impulse response by simply differentiating the step response. In this way, we can solve the system even if we do not know the initial condition.
It is important to notice that integration has noise rejection characteristics, and we have discussed before that step response is the inherited integral of the impulse response.
In this lecture today, we have read a large piece of information about the step response. To have a solid foundation for the topic, we have to refresh the concept of the linear time-invariant system and the step signal in our minds. Moreover, we have also seen the example of step response in MATLAB. For a clear idea, we also read a detailed description of each function used in the code, and then we read about the flow of the program in MATLAB. In the end, we read the details of different terms used during the examination of step response and also differentiate between step response and impulse response. In the next lecture, we will learn more about MATLAB and signals. To learn more, be with us. Till then, have a nice day.
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?
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:
Magnitude
Phase
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.
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.
Responses are the types of behavior or results that a system represents. There are two types of responses in the LTI systems:
Transient response
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.
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.
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.
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.
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:
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.
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.
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.
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:
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.
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.
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.
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
Discrete-time signals
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
Impulse Response
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.
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.
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
Z transform
Fourier transform
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:
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 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 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.