Algorithm for calculating air quality index for sensor data in MATLAB

Verified

Added on  2023/04/23

|3
|767
|424
AI Summary
This algorithm explains how to calculate air quality index for sensor data in MATLAB using conversion factors and switch cases. It also explains how to plot the results graphically. The program takes input from the user for sensor number and location code and displays maximum reading, minimum reading, and location of average reading. The program can be saved as a function and the workspace data and plots can be saved for later inspection.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
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: -

n=0
n
Rnc 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

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
6, it should give a error because we have only six sensors) means
its 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
Document Page
T= input from user location
If (I==1 && T==r1)
Output =S1*R1
Else if(I==2 && T==r2)
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
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]