Signals and Systems Lab 1
Signals and Systems Lab 1
School of Engineering
EEET2369 – Signals and Systems 1
Prac 1 Report
Lecturer: Dr Jiao Lin
Student Name: Yash Dhukate Student Number: s3898134
Student Name: Giuseppe D’anna Student Number: s3898229
Student Name: Jordan Sayer Student Number: s3905874
Prac Session: Wed 11:30
Submission Due Date:
Part 1: Manipulating Arrays
Introduction:
Collected data from the Australian Bureau of Meteorology has been monitoring the
maximum temperatures, minimum temperatures, and rainfall of Melbourne daily since the
mid-1940s. The data is reasonably complete however, there are some days where the
measurements are missing. The first part of the practical is to determine these days with
missing data and fill them in, then to also create a graph which presents the maximum and
minimum temperatures.
Using MATLAB, the data contained in an excel spreadsheet is imported into a blank script.
With the use of a user defined function, for loops, plot function, hold on and off, the missing
data was filled in and a plot of the maximum and minimum temperatures were displayed.
The user-defined function is created as a tool to be called into the main script and replace the
missing data with valid numerical data. It has also been specified that there are two possible
scenarios where there is data missing. Either one data entry is missing between both sides of
valid numeric data or, there are multiple data points missing one after another. In the case of
only one missing data point, the user-defined function must calculate the average of the two
points on either side of the missing data point. If there are consecutive data points missing,
the closest known data point is assigned to the missing points.
To use the user-defined function it must be called in the main script. Since it is the entire
excel spreadsheet being tested for missing data, the function must be able to check all rows
and columns. Using a for loop, the function can iterate through all data points and
automatically fix these unaccounted-for points then copy and paste the fixed columns into the
original dataset.
When creating the graphs to plot the maximum and minimum temperatures, varying
functions were used. Variables were created to specify the column of the correct data. The
function “plot()” was used to use the data and create a graph as well as using the “hold on”
and “hold off” functions to ensure both maximum and minimum temperatures were graphed
on the same axis.
The use of a for loop is used to iterate through each column of data to find invalid entries and
replace them. This is the most efficient method as it will passively change to the next column
once on is completed. This efficient code is further reinforced with the use of the user-defined
function rather than using more lines of code to check one column, move to the next, then
combine all columns back together.
Fig 1) Raw data from excel sheet. Fig 2) Missing data filled in from
1 missing variable between 2 valid numbers working code
Here, the result of the working code is evident. In figure 1 the raw data is read from the excel
spreadsheet and outputted in a variable display. In line 604, two missing data points are
present (NaN) which have been resolved and can be seen in figure 2. It was required that if
there is a missing data point between two valid numbers, the average of those two numbers
should be substituted for the missing number. In line 603, in figure 2, the NaN has been
replaced by the average of the number on either side of the missing data point (12.35 and 4.4
respectively) which is what is required of the code.
Fig 3) Raw data from excel sheet. Fig 4) Missing data filled in from
Multiple missing variables with 2 valid working code
numbers at either end.
In this scenario, the raw data has multiple data points missing (Fig 3) and it is the requirement
that the closest valid number should be entered for the missing points. In Figure 4, it is
evident that this is achieved. Lines 2318 through to 2329 in figure 4 show that the data entry
18.8 has been used consistently as it is the closest number for each of the missing points.
However, in line 2330 in figure 4, it is noticeable that the entry point is not 18.8 but instead
16.75. This is because an average of 18.8 and 14.7 have been taken. This is because when the
code was iterating through and reached line 2330, the invalid data point was between two
valid entries. Therefore, instead of repeating the closest number, it has recycled the first
scenario of an invalid number being between 2 valid numbers. Thus, an average is used for
line 2330 in Figure 4.
Fig 5) Graph displaying the minimum and maximum temperatures recorded by the
Australian Bureau of Meteorology
Figure 5 displays the graph of the maximum and minimum temperatures recorded in
Melbourne, Vic. On the y-axis, the temperatures are displayed, and along the x-axis are the
dates of each recorded day. The function “legend ()” was also used to display which data
relates to the corresponding colour on the graph. The legend is evident on the top right where
the orange lines are the minimum temperatures recorded and the blue lines are the maximum
temperatures recorded.
Task 2: Rainfall Greater Than 80mm and where the highest value occurs
Introduction:
Using MATLAB, and the data that was imported previously in Task 1, the code goes through
the data to find all the points in the weather where the rainfall was greater than 80 mm. A
new variable data is created from the excel sheet. The third column from this data is then
stored as a variable. The variables maxValue and indexofMax are taken from this column
using the max function in MATLAB and this then stores the max value of the rainfall column
as a variable. The indexOfMax takes the cell that this value occurs at then using the txt file
which contains all the dates we get the variable dateOfMax using the location of
indexOfMax. Using the variable indexOfMax 1 is added to the value as the data variable
ignores the titles of all the columns of the excel sheet. This then prints out the date of the
highest rainfall into the command window of MATLAB. To find the times the rainfall was
above 80mm, the find function in MATLAB was used. This scans the entire rain_fall variable
which contains all the data of the rainfall for the value we set it to which was the data being
above 80mm. Then using the index of the points where the rain was above 80mm the date
was gotten by getting those points and + 1 to them as we had to find the dates in the text file
this process was also used in finding the highest rainfall amount.
Fig 8) Screen shot of the excel spreadsheet showing the highest rainfall
Fig 9) The dates of all the times rainfall were greater than 80mm
Fig 10) Excel spreadsheet data showing all dates of the rainfall being above 80 mm
The graph in figure 6 shows the rainfall that occurred during the time period. On the x axis of
this graphs displays the amount of rainfall in mm. This was set using the “xlabel” function in
MATLAB. The results of the graph show that the code has worked and done what was
needed of it and that was to represent the rainfall data in a graph. Figure 7 also shows the date
of the highest rainfall which was seen on the graph from Figure 6. Figure 8 verifies the data
obtained from the code which was the date of the highest rainfall which was 188 mm
occurring on the 8th of April 1977 matches which the text output from MATLAB which was
8/04/1977. Fig 9 shows the MATLAB code outputting the dates where it found that the
rainfall was higher than 80 mm which matches out from the excel spreadsheet data which can
be seen from Fig 10.
Introduction:
Part two of Practical 1 is tasked with storing an image within MATLAB and requiring that all
red colours within the image to be changed to green. The program should then be able to
output the original and newly updated image.
The .bmp image file is saved to a variable (“rgbImage”) and stored as a 3-Dimensional matrix
with the dimensions 512x512x3 (512 rows, 512 columns and RGB layers). The difference
between an image stored as a 2D matrix and a 3D matrix is that the 2D matrix is only
concerned with 2 dimensions (x and y) whereas a 3D matrix has 3 dimensions where the
extra dimension is depth. 3D matrix will contain red, green and blue channels to create an
RGB image.
In order to achieve a complete code whereby the colours of an image are changed, for loops
and if statements are used. The for-loops within the code iterate through each row and
column of the pepper image. The Pixel variable is then created which is the rgbimages rows
columns and third dimension which controls the blue, red and green colours. For each of the
colours, a variable is assigned to each one of these colour matrixes. Then it then checks if the
maximum pixel file is equal to the red pixel and if it is, it switches the green pixel values to
the red pixel values. This makes all the red colours turn into the green by changing the value
each pixel has in the 3D matrix. The code then adjusts these values to change how bright the
colour is trying to make it seem more lifelike. The images are then plotted together using
subplot and the imgshow function displays the image. They are then given are title using the
title function.
Fig 11) The output images obtained by the code. On the left, the image displays the original
image where there are red and green colours present. On the right, the image shown is the
image after the code has changed all traces of red to green
A main limitation of the code would be that the colour does not seem lifelike and instead
makes the pepper look like plastic (see right image in figure 11). This is due to the natural
colour of food not being all one specific colour but instead a range of shades of the one
colour. In this practical, the code is not able to change the red colours to green in this way,
instead it was able to set the pixel to a value ranging from 0 to 255.
Another limitation would be that some traces of red may remain in the edited image. This is
due to switches between the red pixels to green values as it may be left red due to the red
pixel colour value being higher than the green. Since we are not explicitly setting the value of
each pixel, traces of red pixels can still appear due to the values of the switched pixels. This
can mainly be seen on the stalk of the peppers in figure 11.
Conclusion:
Through the completion of this practical, the understanding of manipulating arrays, importing
images and converting the colours of pixels have been further enhanced. Using user-defined
functions, indexing functions and for loops, missing data within a dataset were able to be
replaced. This further reinforced the idea of manipulating arrays to change the contents
within the array and this assisted the execution of plotting the data onto graphs. By using
varying functions to help plot graphs, two plots were able to be created to display the new
data from inside the dataset that previously had been missing data points. Moreover, the
understanding of indexing and loops from the previous tasks aided the achievement of
creating a code that was able to change the colours within an image to a completely different
colour.
References:
[1] G. Hayes, "MATLAB Answers", mathworks, 2022. [Online]. Available:
https://au.mathworks.com/matlabcentral/answers/126197-for-loops-lengths-size-command.
[Accessed: 16- Mar- 2022].
[2] negi, a., 2022. MATLAB Answers. [online] mathworks. Available at:
<https://au.mathworks.com/matlabcentral/answers/297843-can-anyone-please-explain-the-
meaning-of-for-m-1-size-x-1-for-n-1-size-x-2-in-the-program-plea> [Accessed 17 March
2022].
[3] Eddins, S. and Shure, L., 2022. Matrix Indexing in MATLAB. [online] mathworks.
Available at: <https://au.mathworks.com/company/newsletters/articles/matrix-indexing-in-
matlab.html> [Accessed 20 March 2022].