Lab 1+2 Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

RMIT Classification: Trusted

RMIT Vietnam

School of Science Engineering and


Technology
OENG1207 – Digital Fundamentals
Laboratory Experiment 1
Introduction to MATLAB

"I declare that in submitting all work for this assessment I have read, understood and agree to the
content and expectations of the Assessment declaration ."

Lecturer: Dr. Alexandru C Fechete

Student 1 Name: Le Binh Khang Student 1 Number: S4055044

Student 2 Name: Truong Gia Bao Student 2 Number: S4022180

Student 3 Name: Le Phuc Quang Minh Student 3 Number: S4034067

Group: Friday 12:30-14:00

Submission Due Date: 23 Apr by23:59


RMIT Classification: Trusted
Laboratory Exercise 1

Table of Contents
1 Introduction to Experiment 1 .................................................................................. 3

Part 1 - Physics of Projectile Motion ............................................................................ 3

2.1 Task 1: Problem Statement and Determine the Input / Output ........................................ 3

2.2 Task 2: Calculate the Simple Physics for the Scenario ....................................................... 4

2.3 Task 3: Use MATLAB to find Initial Velocity ...................................................................... 5

Part 2 - Change of Initial height .................................................................................. 5

3.1 Task 4: Problem Statement and Determine the Input / Output............................................. 6


3.1.1 Problem statement ...................................................................................................................... 6
3.1.2 Input / Output.............................................................................................................................. 6

3.2 Task 5a: Calculate the Initial height of the 45° launch angle ............................................. 7

3.3 Task 5b: Calculate the Displacement for 35° and 55° launch angle ................................... 7

3.4 Results of all the manual calculations .............................................................................. 8

Introduction to Experiment 2 .................................................................................... 12

Part 1: Design a colour change program ................................................................... 12

5.1 Task1: State the Problem ............................................................................................... 13

5.2 Task 2: Determined the input and output ...................................................................... 13


5.2.1 Input .......................................................................................................................................... 13
5.2.2 Output ....................................................................................................................................... 13

Task 3: Algorithm Explanation .................................................................................. 14

6.1 Task 4: Write, run, and test the algorithm in MATLAB.................................................... 15


6.1.1 Write MATLAB script ................................................................................................................. 15
6.1.2 Testing and Validation: .............................................................................................................. 15

Part 2: User – defined function for the program ........................................................ 16

7.1 Create a user – defined function for the program .......................................................... 16

7.2 Testing and comparing result ......................................................................................... 17

Discussion and conclusion ......................................................................................... 18

Reference ........................................................................................................................ 19

2
RMIT Classification: Trusted
Laboratory Exercise 1

1 Introduction to Experiment 1
The laboratory exercise focused on utilizing MATLAB to solve a physics problem
related to projectile motion, inspired by the legendary daredevil Evel Knievel's Eve
world records in motorcycle jumping which was over 19 cars on February 28th, 1971.
[1] The objective was to calculate the initial velocities and heights required for
hypothetical motorcycle jumps over the Grand Canyon. Furthermore, there will be
exercises regarding to the change of Initial height and how it affects the outcome of
the same problem mentioned above. Through this exercise, we aimed to gain
proficiency in using basic MATLAB functions for problem-solving and visualizing data.

Part 1 - Physics of Projectile Motion


In order to arrive at the parabolic motion of a projectile, if we consider two objects
where one travels horizontally, and the other is engaged in a vertically accelerated
movement, that typifies an object upon which the force of gravity alone casts its
influence. When these two motions combine – vertical and horizontal motions, the
trajectory formed will be parabolic. Under the parabolic motion of the projectile, the
object takes off initially with horizontal velocity where its motion is affected by gravity
force, thus sliding down vertically every second forming a parabolic trajectory.

Figure 1 Diagram of Parabolic Motion of Projectile [5]

2.1 Task 1: Problem Statement and Determine the Input / Output


Problem statement

A motorcycle jumps over the Grand Canyon, with the assumption of a flat ground
surface, the task lies in accurately calculates the distance the motorcycle will travel
during the jump. This necessitates a thorough consideration of factors like velocity,
acceleration, launch angle and potential wind resistance (which in this case will not
3
RMIT Classification: Trusted
Laboratory Exercise 1

count), all pivotal in ensuring the outcome in which the rider land his bike on the other
edge of the cliff successfully.

A precise calculation methodology for estimating the distance travelled by the


motorcycle is the goal of the following tasks.
Input and Output

Input:
Some of the information taken from the Laboratory 1 Guild, the point was where the
Grand Canyon is at its narrowest is at Marble Canyon, air resistant is negligible, and
the centre of gravity remains the same for the whole trajectory. [1]
- Angle of launch q = 45°
- Acceleration due to gravity g = 9.8 (m/s2)
- Displacement: d = 183 (Meters)
Output:
- Utilize the Range formula to determine the minimum velocity required for the
motorcycle to successfully traverse the gap at a launch angle of 45 degrees. The result
should yield a positive value, converted to km/h and that number indicates the lowest
speed needed for a successful crossing.

2.2 Task 2: Calculate the Simple Physics for the Scenario


Note: The manual calculation of the initial velocity in projectile motion involves the
usage of the Range formula to calculate the Initial speed at which an object must be
launched. It considers factors such as the launch angle, displacement, and
gravitational acceleration which are mentioned above.
Step 1 - Add the Range formula:
d = (v02 / g) ´ Sin (2 ´ q)
Step 2 - Simplify the trigonometric expression:
!" × %
+ Change q from Degrees to Radians ( &'(
= π/4), we have

Sin (2 × π/4) = Sin (π/2) = 1


+ Therefore: d = v02 / g

Step 3 – Plug in the given values and calculate v0:

v02 = 183 ´ 9.8


=> v0 = √183 × 9.8

=> v0 = 42.35 (m/s)

4
RMIT Classification: Trusted
Laboratory Exercise 1

Step 4 – Convert from m/s to km/h:

42.35 ´ 3.6 = 152.46 (km/h)

2.3 Task 3: Use MATLAB to find Initial Velocity

Figure 2 Part 1 final result calculated using MATLAB

In analysing the initial velocity for a motorcycle's jump, MATLAB and manual
calculation yielded subtly different results: 152.45 km/h and 152.46 km/h respectively.
In the manual calculation method, rounding the initial velocity to 42.35 m/s before
converting it to km/h introduces a slight difference in the final result, contributing to the
observed discrepancy.

Part 2 - Change of Initial height


In Projectile Motion, the change in initial height can affect several aspects of the
trajectory and behaviour of the projection
process: Range, time of flight, maximum
height, impact velocity, trajectory shape.
[2] The second part of Laboratory 1 will
thoroughly explore how the change in
initial height affects the range of the
projected object, while maintaining a
predetermined projection speed.
Figure 3 Diagram of Parabolic Motion of
Projectile with a non-zero Initial height [2]

5
RMIT Classification: Trusted
Laboratory Exercise 1

+ Equations of displacement in x and y for Projectile Motion with Initial


height different than zero

When considering projectile motion with an initial height different from zero, the
equations governing the motion become slightly modified. Here are two of the key
equations for the displacement:

Horizontal Displacement x = v0 ´ t ´ Cos (q)

&
Vertical Displacement y = H + v0 ´ t ´ Sin (q) - ) ´ g ´ t2

3.1 Task 4: Problem Statement and Determine the Input / Output

3.1.1 Problem statement


Designing an efficient projectile motion system with an initial height different from zero
requires addressing various complexities. This entails analysing the trajectory of the
projectile considering factors such as the time of flight, vertical displacement from the
ground. The information on launch angle, initial velocity, and gravitational acceleration
is given beforehand.

3.1.2 Input / Output


Information sourced from Laboratory 1 Guild. Noted that air resistance is insignificant,
and it is assumed that the center of gravity remains constant throughout the entire
trajectory.
Input
- Angle of launch (3 different scenarios need to be addressed): q = 35° / 45° / 55°
- Acceleration due to gravity g = 9.8 (m/s2)
- Displacement: d = 183 (Meters)
- Initial velocity: 125 km/h
Output
- Three key outputs are to be expected: the time of flight, initial height required at 45°.
In the process of analysing the projectile motion at launch angles of 35° and 55°, find
the displacement achieved by both angles. Furthermore, show the result as a plot and
determine what angle provide the greatest distance out of the three. All the results

6
RMIT Classification: Trusted
Laboratory Exercise 1

should be positive numbers, converted into seconds and meters for variables “t” and
“d, H” respectively.

3.2 Task 5a: Calculate the Initial height of the 45° launch angle
Note: Initial velocity reduced to 125 km/h
Step 1 - Add the Horizontal Displacement equation:
x = v0 ´ t ´ Cos (q)
Step 2 - Plug in the given information and find variable Time:
+ Change Initial velocity from km/h to m/s (125 / 3.6 = 34.72 m/s)
!" × %
+ Change q from Degrees to Radians ( &'(
= π/4)

=> 183 = 34.72 ´ t ´ Cos (π/4)


&'*
=> t = *!.,) × -./ (1/!)

ó t = 7.45 (Seconds)
Step 3 - Add the Vertical Displacement equation:
&
=> y = H + v0 ´ t ´ Sin (q) - ) ´ g ´ t2

Step 4 - Plug in the given information and variable Time to find Initial
height:
0 = H + 34.72 ´ 7.45 ´ Sin (π/4) - &) ´ 9.8 ´ 7.452
=> H = 89.06 (Meters)

3.3 Task 5b: Calculate the Displacement for 35° and 55° launch angle
Note: Keep the Initial velocity at 125 km/h and Initial height at 89.06 meters
Step 1 - Add Vertical Displacement equation:
!
y = H + v0 ´ t ´ Sin (q) - ´ g ´ t2
"

Step 2 - Plug in the information and find all the necessary numbers (at a
launch angle of 35°):
+ Change Initial velocity from km/h to m/s (125 / 3.6 = 34.72 m/s)
*" × %
+ Change q from Degrees to Radians ( &'(
= 7π/36)
&
=> 0 = 89.06 + 34.72 ´ t ´ Sin (7π/36) - ) ´ 9.8 ´ t2

=> - 4.9 ´ t2 + 34.72 ´ t ´ Sin (7π/36) + 89.06 = 0

7
RMIT Classification: Trusted
Laboratory Exercise 1

+ The equation above is quadratic equation in the form at2 + bt + c = 0, where a = -4.9,
b = 34.72 ´ Sin (7π/36), c = 89.06. Therefore, a quadratic formula can be used:
45 ± √ 5^)4 !9:
t= )9

+ Calculate b at 35°:
b = 34.72 ´ Sin (7π/36)
=> b = 19.92

Step 3 - Utilize the quadratic formula above and the flight time of the 35°
angle:
45 ± √ 5^)4 !9:
t= )9

4&;.;) ± < &;.;)! 4 ! × (4!.;)× ';.(=


=> t= ) × (4!.; )

=> t1 = 6.76 (Seconds)


=> t2 = - 2.69 (Seconds) (Invalid because time must be positive)

Step 4 - Apply the same method to find the flight time of the 55° angle:
Note: b = 34.72 ´ Sin (11π/36)
t1 = 8.059 (Seconds)
t2 = - 2.255 (Seconds) (Invalid because time must be positive)

Step 5 - Find Displacement for both angles using the Horizontal


Displacement equation:
+ Add the Horizontal Displacement equation:
x = v0 ´ t ´ Cos (q)
+ Scenario 35° angle: Theta is 7π/36 Radian, Time is 6.76 Seconds:
x = 34.72 ´ 6.76 ´ Cos (7π/36)
=> x = 192.26 (Meters)
+ Scenario 55° angle: Theta is 11π/36 Radian, Time is 8.06 Seconds:
x = 34.72 ´ 8.06 ´ Cos (11π/36)
=> x = 160.51 (Meters)

3.4 Results of all the manual calculations


+ Total time to travel 183 meters with a speed of 125 km/h and 45° launch angle: 7.45
(Seconds)
+ Initial height of the 45° launch angle: 89.06 (Meters)
+ Displacement of 35° angle: 237.82 (Meters)

8
RMIT Classification: Trusted
Laboratory Exercise 1

+ Displacement of 55° angle: 162.24 (Meters)

3.5 Task 6: Use solve problem on MATLAB


The MATLAB code for calculating the initial height of a motorcycle jump at a 45
degrees angle, as well as the displacement at 35 and 55 degrees angles, showed
superior accuracy compared to manual calculations. Although there are small
differences due to rounding errors, the results are in close agreement with those
obtained manually.

Figure 4: MATLAB Part 2 calculation outputs

Figure 5 A plot describing the trajectory of the bike in 3


different angles.

9
RMIT Classification: Trusted
Laboratory Exercise 1

We create a MATLAB plot to compare the displacement of a motorcycle at launch


angles of 35, 45, and 55 degrees. The plot clearly showing that the 35-degree angle
results in the maximum range compared to the other angles. This insight is crucial for
optimizing motorcycle jumps, as achieving the greatest distance is essential for
successful stunts.

Conclusion
In summary, Experiment 1 dive into the complex physics of projectile motion,
specifically exploring the effects of changes in initial altitude on projectile trajectory.
Through meticulous hand calculation MATLAB testing, we discovered the profound
This experiment not only deepened our comprehension of fundamental physics
principles but also highlighted the practical implications for various real-world
applications.

10
RMIT Classification: Trusted
Laboratory Exercise 1

RMIT Vietnam

School of Science Engineering and


Technology

OENG1207 – Digital Fundamentals


Laboratory Experiment 2
Image Colours

"I declare that in submitting all work for this assessment I have read, understood and agree to the
content and expectations of the Assessment declaration ."

Lecturer: Dr. Alexandru C Fechete

Student 1 Name: Le Binh Khang Student 1 Number: S4055044

Student 2 Name: Truong Gia Bao Student 2 Number: S4022180

Student 3 Name: Le Phuc Quang Minh Student 3 Number: S4034067

Group: Friday 12:30-14:00

Submission Due Date: 23 Apr by 23:59

11
RMIT Classification: Trusted
Laboratory Exercise 1

Introduction to Experiment 2
In the field of photography, colour substitution techniques play an important role in the
creative process. One of the most used methods for representing colour in digital
media is the RGB (Red, Green, Blue) colour space. In this system, colours are created
by combining different intensities of red, green, and blue light. Each pixel on a digital
display is composed of these three primary colours in different proportions, create a
spectrum of colours. From changing the colour of objects in photos to performing
chroma keying in video, the versatility of colour replacement methods will be
demonstrated through MATLAB.

Part 1: Design a colour change program


In this part of the laboratory experiment, we are requested to design a simple colour changing
program. The image provided for this exercise called “coloredChips.png” which is an image
pre-existing collection in MATLAB and accessible by installing the Image Processing Toolbox.
The image shows multi-coloured chips as shown below. [3]

Figure 6 “coloredChip.png”
The requirement settled for the program was mentioned:

a. Prompts a user to specify a colour they want to change in an image

b. Iterates through the image and changes all pixels of that colour to black

c. Displays the resultant image in a new figure window.

12
RMIT Classification: Trusted
Laboratory Exercise 1

6.1 Task1: State the Problem


The objective of this laboratory experiment is to design a MATLAB program that
facilitates colour replacement within an image. Specifically, the program should prompt
the user to specify a target colour they wish to change within the image, iterate through
the image to identify all pixels of that colour, and subsequently replace those pixels
with black. Finally, the modified image should be displayed in a new figure window for
visualization.

6.2 Task 2: Determined the input and output

6.2.1 Input
- The input required for solving the problem is the 'coloredChips.png' image which as
aforementioned above, could be found in the MATLAB Image Processing Toolbox
library.
- As we import the image to the workspace using ‘imread’ function the matrix
representing the image in the Workspace is of type 'uint8'. [4]
- The matrix has three dimensions, where the first two dimensions represent the height
and width of the image, and the third dimension represents the RGB channels. Each
pixel in the image is represented by three values corresponding to the intensity of
red, green, and blue channel. [4]
- The data cursor in MATLAB is a helpful function. It enables us to get the RGB values
of a single pixel, which is helpful in determining the conditional statement's value
range.

6.2.2 Output
- The output is the modified image where all pixels of the specified colour are
changed to black.
- The modified image should be displayed in a new figure window.

13
RMIT Classification: Trusted
Laboratory Exercise 1

Task 3: Algorithm Explanation


To accomplish the task of changing a
specified colour in an image to black, we
need to design an algorithm that iterates
through each pixel in the image, checks its
colour, and replaces it with black (or white)
if it matches the specified colour. Beside is
a flowchart demonstrating algorithm:

Several important factors were taken into


account when designing the algorithm:

1. Primary colour: Check if the RGB


values of a pixel fall within a certain
range that corresponds to that colour.
For example, for red pixels, the red
channel value is significantly higher
than the green and blue channel values.
2. Secondary colour: For secondary
colours, checks for combinations of
RGB values that are characteristic of
those colours. For example, yellow
pixels have red and green values that
are greater than blue.
3. Conditional Statements: Conditional
statements are carefully set to assess
the RGB values of each pixel in the
image. This helps determine whether a
pixel's colour needs to be changed or
not.
Figure 7 Algorithm flowchart
4. Looping Through Pixels: By using
nested loops, it literate through every pixel and modifies them.

14
RMIT Classification: Trusted
Laboratory Exercise 1

7.1 Task 4: Write, run, and test the algorithm in MATLAB

7.1.1 Write MATLAB script


After designing and algorithm logic for the program to base on, we proceed to MATLAB coding
to create the program. The script allows the users to select a colour from the menu, allow the
user to input again if inputted an invalid colour, replaces all pixels of that colour with black,
and displays the modified image as followed the algorithm.

Figure 8 Program interface


(The script of the program will be submitted separately)

7.1.2 Testing and Validation:


After finalizing the script, it is important to validate its functionality through comprehensive
testing. Our testing includes two key considerations: evaluating the colour-changing function
across various colour options and assessing the program's error-handling capabilities

During the colour-changing test, we tried altering colours to see if the script accurately turned
the right pixels black or white. We tested it with all the colour option to ensure it worked. By
examining the resulting images, we could confirm whether the script successfully changed the
colours as expected. The tested screenshot of other color will be provide in the Appendix.

Figure 9 Changed colour output

15
RMIT Classification: Trusted
Laboratory Exercise 1

In the error handling test, we examined how the script dealt with mistakes. We purposely gave
it incorrect inputs, such as selecting a colour that does not exist. Our goal was to make sure
that the script handled errors smoothly without crashing.

Figure 10 Error Handling capabilities


After conducting these tests, we are confident that the script functions well and performs its
intended tasks effectively.

Part 2: User – defined function for the program


In the realm of programming, user-defined functions (UDF) play a vital role by promoting code
organization, reusability, readability, and maintainability. They are a fundamental building
block for creating efficient and scalable programs.

8.1 Create a user – defined function for the program


In this part of the experiment, we tried to incorporate an UDF in our colour changing program.
The requirement settled for this function is:

Main script User-defined functions

Prompt the user for the colour to change Perform the search and colour-changing
process

16
RMIT Classification: Trusted
Laboratory Exercise 1

Displaying the image Output the resultant image back to the main
script

According to these requirements we proceed to write the MATLAB scripts.

Figure 11 Part 2 - Main script

Figure 12 Part 2 - User-defined function


The main script is named: Lab_Ex2_P2_color_conversion to defecate from Part 1 of the
experiment

8.2 Testing and comparing result


Similar to the testing process of previous part of the experiments, the key function of colour
changing and error handling is tested.

The program is working effectively. The main script and the function script is well connected
to provide a corrected result. As a comparison to the Part 1 program, since both program
have the same parameter of value in the conditional statement and make use of the same
while loop for error handling, the function is exactly the same, which conclude a successful
incorporated user-defined function.

Figure 13 Part 1 Program output


17
RMIT Classification: Trusted
Laboratory Exercise 1

Figure 14 Part 2 Program output

Discussion and conclusion


After completing the program, it is essential to discuss its strengths and weaknesses to
understand its overall effectiveness:

- Strength:
o User-friendly interface: The program provides clear instruction and a menu of
colour.
o Successful incorporated user-defined function separates the main
functionality into a user-defined function and the main script, enhancing
readability and maintainability.
o Error handling: The program includes a default case to handle invalid colour
selections, ensuring smooth operation even in unexpected situations.
o Visual feedback: It displays the modified image in real-time, allowing users to
see the effects of their selections immediately.
- Weakness:
o Inefficiency: Despite generate the correct result however the program shows
imperfection. As the colour changing function is hardcoded by condition the
result is not cover all variations and shade of the selected colour. For
instance: the rim of the chips was not change.
o Inefficiency: The program iterates through each pixel in nested loops for each
colour change operation, which could be computationally expensive for large
images. A more efficient algorithm could be applied.

18
RMIT Classification: Trusted
Laboratory Exercise 1

To conclude, despite our program show some positive aspect, however, due to the limitation
of time and knowledge, there are still room for improvement in future work. Nonetheless, the
completion of the program fulfills the course requirements and learning objectives, marking it
as a successful learning experience.

Reference

[1] RMIT, “OENG1207_Laboratory Experiment 1,” [Online]. Available:


https://rmit.instructure.com/courses/135447/files/36061942?wrap=1. [Accessed 2024].

[2] P. P. w. Solutions, “Projectile Motion Calculator and Solver,” [Online]. Available:


https://problemsphysics.com/physics-calculators-solvers/projectile-motion-calculator-
and-solver.html. [Accessed 2024].

[3] RMIT, “OENG1207_Laboratory Experiment 2,” [Online]. Available:


https://rmit.instructure.com/courses/135447/files/36062001?wrap=1. [Accessed 2024].

[4] “Image Types in the Toolbox,” MATLAB, [Online]. Available:


https://www.mathworks.com/help/images/image-types-in-the-
toolbox.html#responsive_offcanvas. [Accessed 22 04 2024].

[5] Tutoroot, “What is Projectile Motion? – Types, Derivation, Formulae 2024,” 22 10 2022.
[Online]. Available: https://www.tutoroot.com/blog/what-is-projectile-motion-types-
derivation-formulae/. [Accessed 2024].

19
RMIT Classification: Trusted
Laboratory Exercise 1

Appendix

Appendix A : Other changed colour output

20

You might also like