Calculating Air Quality Index from Sensor Data Using MATLAB

Verified

Added on  2023/04/23

|3
|767
|184
Practical Assignment
AI Summary
This assignment provides a detailed solution for calculating the Air Quality Index (AQI) using sensor data in MATLAB. The solution begins with importing sensor data from an Excel file into MATLAB and assigning variables to each sensor reading. Conversion factors are then defined for each sensor. A loop system is implemented to calculate the AQI for each sensor by multiplying the sensor reading with its corresponding conversion factor. The program takes sensor number and location code as input from the user, using switch cases to match the input with the appropriate sensor. Based on the input, the program displays maximum and minimum readings, and the location of the average reading. Finally, the solution includes a graphical representation of the sensor readings using subplots, showing the sensor readings of both location codes. The workspace data can be saved for later inspection, and the plots can be saved as well. The assignment also provides a flowchart illustrating the program's logic.
Document Page
ALGORITHM
In the first step we should load the sensor data as given the
problem in MATLAB, as we have to import data into MATLAB using
matlab import function from the tool bar. what we have to do is
first we will make excel file of sensor data provided, after that we
will import data using import options provided in MATLAB
interface, and after importing that file we can save that file in .mat
format assigning a name to it, For example -We can save imported
data as name sensor data.mat,We can load that data using MATLAB
command “load sensor data.mat”.For each sensor reading, we will
assign variable r1,r2,r3…!with location code.
As given in the problem statement our next step is assigning all
conversion factor for each sensor. example: - for sensor 1
conversion factor is 2.3, for sensor 2 conversion factor is 3, As there
are 6 sensors, so we will take 6 variables for each sensor, we will
assign in Matlab as c1=2.3, c2=2, c3=1….! You can also save those
value into .mat file and can be loaded again in future.
Now, we have to Calculate air quality index for a given sensor: -
𝑅𝑛 ∗ 𝑐𝑛
𝑛=0 where R is the sensor reading and c is the conversion
factor. We can create a loop system for calculation of air quality
index of each sensor from n=1 to n=6 and for each n that is sensor
number as r is mmultiplied with its conversion factor as r1*c1,
r2*c3.
Now next step is to take input from the user, for which we will
implement switch cases through which inputs are taken and
matched with sensor number. Input will be the sensor number as
specified in the document.
User will be asked to enter the sensor number then if the sensor
number gets matched(like if someone give number greater than 6,
it should give a error because we have only six sensors) means its
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
valid sensor number with data, than the calculation with within the
specified switch case (example-: if case==1 than output= c1*r1 else
if case==2 than output = c2*r2 and so on) it will proceed further
that it will display maximum reading ,minimum reading ,and
location of average reading otherwise it gets terminated at ending
of program. You can also use if else case for this program also.
For example: - if user enters 1, it will display all maximum reading,
minimum reading, and location of average reading of the first
sensor as these readings will be calculated in the case==1 of the
program.
Second input is the location of the code and if it is matched
program will proceed else terminates.
Now, Next step is the graphical representation of the of the input
that is the sensor reading, as we have two location of code, we will
subplot both output in one figure. Each plot will have specific title
and axis name. Subplot is used to display the sensor reading of both
location code in graphical form to understand it better. For plotting
we can use plot function in the matlab and subplot also.
All these working we can also observe in command prompt.
We can save workspace data into a .mat file for later inspection .
We can also save the plots using write function or using save function of the
tool.
Flow of the program will look like as follows: -
S=sensor data;
R1=value of r1;
R2=value of r2; %and so on
I=input from user sensor number
T= input from user location
If (I==1 && T==r1)
Output =S1*R1
Else if(I==2 && T==r2)
Document Page
Output =S2*R2
. And so on.
You can also write this matlab script as function which takes two values (sensor
number and location) from use and give specific output and tha plots.
Flow chart of the program is as follows-:
FLOWCHART
Import sensor
data
Initialization of
parameters of
conversion factor
Implementation of
switch case for input
Solvation of switch cases
Graphical
representation of
results
Preparation of
data to import
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]