Sie sind auf Seite 1von 18

RMIT Vietnam, School of science and technology

EEET2486 – Signal and Systems 1


Lab experiment #1: Introduction to MATLAB (Review of essential MATLAB)

Lecture: Dr Alexandru Fetchete

Student’s name: Pham Ba Dat Student’s id: s3687451

Student’s name: Tran Trong Tin Student’s id: s3694839

Student’s name: Tran Do Chi Hai Student’s id: s3653997

Submission Due Date: 20/7/2018

1
Contents

Part 1: Revision from first year............................................................................ 5


Task 1: Reviewing of importing and manipulating audio in MATLAB ................ 5
Task 2: Reviewing of importing & manipulating images in MATLAB ................. 6
Task 3: Review of importing & manipulating Excel data in MATLAB ................. 9
Part 2: Generating common signal in MATLAB .................................................. 10
Task 4: Generating the unit-step function in MATLAB .................................... 10
Task 5: Generating a sinusoidal waveforms in MATLAB ................................. 12
Task 6: Generating complex exponentials ...................................................... 14
Conclusion ........................................................................................................ 17
Peer assessment ............................................................................................... 17
Reference ......................................................................................................... 18

2
List of figures
Figure 1: Import audio file into MATLAB ............................................................. 5
Figure 2: Use diff() function to get a different sound from the original................ 5
Figure 3: Import and show the image into MATLAB ............................................ 6
Figure 4: The import image ................................................................................. 6
Figure 5: Import the image into MATLAB and set the conditions ......................... 7
Figure 6: For-loops and if statements .................................................................. 7
Figure 7: Comparing the 2 images after the changes in pixels (switching the blue
with the red pixel................................................................................................ 7
Figure 8: Import the image into MATLAB and set the conditions ......................... 8
Figure 9: For-loops and if statements .................................................................. 8
Figure 10: Comparing the 2 images after the changes in pixels (switching the
blue with the red pixels) ..................................................................................... 8
Figure 11: Import the Excel sheet data into MATLAB........................................... 9
Figure 12: Construct a unit step function using a user-defined function ............ 10
Figure 13: Set time array and create unit-step functions ................................... 11
Figure 14: Testing the user-defined function ..................................................... 11
Figure 15: Graph for the three function............................................................. 12
Figure 16: Create and plots the sinusoids .......................................................... 12
Figure 17: Plot the three sinusoids in subplots .................................................. 13
Figure 18: Graph of the 3 sinusoids function ..................................................... 13
Figure 19: Setting the parameters ..................................................................... 14
Figure 20: Plot the real and imaginary part ....................................................... 15
Figure 21: The real and imaginary part of the complex exponential .................. 15
Figure 22: Graph of complex number ................................................................ 16

3
Introduction
In this lab, we will be revising some of the essential function of
MATLAB.

Basic introduction about MATLAB:

- MATLAB is a multi-paradigm numerical computing environment


and proprietary programming language enveloped
by MathWorks. MATLAB allows matrix manipulations, plotting of
function and data, implementation of algorithms, creation of
users interfacing with programs written in others languages,
including C, C++, and C #, Java, Fortran and Python. [1]
Aim of the lab:

- In this lab we will be looking back at some function which was


showcased in some previous course (either EEET2248 or the
equivalent course EEET2239).
- We will be revising importing & manipulating audio, importing &
manipulating images, importing & manipulating Excel data, and
finally we will be revising the user-defined function for generating
common signals, sinusoidal waveforms, and complex
exponentials.

4
Part 1: Revision from first year
Task 1: Reviewing of importing and manipulating audio in MATLAB
Exercise:

- Importing the audio file into MATLAB using soundsc():

Figure 1: Import audio file into MATLAB

- Using the diff() function to find the derivative of the audio, and we get a higher sound
than the original audio:

Figure 2: Use diff() function to get a different sound from the original

Reflection:

1. How did the sound of the audio differ between the original and differenced version?
- At first we have the original sound of the audio (string.wav) imported into MATLAB and
played using the function soundsc(), then we apply a filter using the function diff(). By
using the diff() function to the audio file (string.wav), we are basically finding the
derivative of the signal which we imported in. And this would result in a distinct audio
which is different from the original.
- The filter which was used to process the sound file was a high-pass filter which amplified
the sound and gives it’s a higher frequency than the original.
2. Describe what is a filter is in the context of electrical and electronic engineering.
- In signal processing, a filter in the context of electrical and electronic engineering is a
device or a process that removes unwanted elements form the signal. [2]
- Different types of filters: FIR Filters, IIR Filters, High-pass and Low-pass, Band-pass, etc.
[2]

5
Task 2: Reviewing of importing & manipulating images in MATLAB
Exercise:

- Use imread() and imshow(x) to import and display the image “lygon.jpg”:
- Imread() is to read the jpg image file, imshow() is to show the image.

Figure 3: Import and show the image into MATLAB

Figure 4: The import image

6
Create a MATLAB script (with if-statements and for-loops) that finds every pixel:

Figure 5: Import the image into MATLAB and set the conditions

Figure 6: For-loops and if statements

Figure 7: Comparing the 2 images after the changes in pixels (switching the blue with the red pixel
7
Reflection:

- Replace the blue colored pixels with the corresponding pixel in the image ‘tartan.jpg’.
- Just similar to the pervious exercise we import the image to MATLAB and set the
condition:

Figure 8: Import the image into MATLAB and set the conditions

Figure 9: For-loops and if statements

Figure 10: Comparing the 2 images after the changes in pixels (switching the blue with the red pixels)
8
 Explain chroma-keying and give examples from references of when this is used in the
entertainment industry.
- Chroma key composting or chroma keying, is a visual effects/post production technique
for composting (layering) two images or video streams together based on color hues
(chroma range). This technique has been used heavily in many fields to remove
background objects or colors of a video or images. [3]
- Some example of the chroma-keying (green-screen effect):
+ Weather forecast broadcasts, where the news presenter is always seen to be standing
in front of a huge CGI map, but actually is a large green screen background.
+ The chroma-keying is also commonly used in the visual effects in the entertainment
industry in movies and video games. For examples the movie Star War is a big user of
the green screen effect for those epic battles in space. In video game, the developers
use the chroma-keying to create a scenario in the game by combining 2 different images
and changing the colors to fit into the theme of the game.

Task 3: Review of importing & manipulating Excel data in MATLAB


Exercise:

- Import the Excel sheet ‘JBHiFi.xlsx’ which contains the stock prices for JB HiFi over one
financial year.

Figure 11: Import the Excel sheet data into MATLAB


9
Reflection:

 Think about some of the other statistical tools MATLAB has and how they could be
applied to this data to extract different information or to visualize this data in
different ways
- Other method that could be used to analyze the data to extract and visualize data:
+ Probability Distribution Objects: Allow you to fit a probability distribution to sample
data, or define a distribution by specifying parameters values.
+ Hypothesis Testing: Test a statistical sample, with the goal of accepting or rejecting
a null hypothesis. The test tells the analyst whether or not his primary hypothesis is
true.
+ ANOVA (Analysis of variance and covariance): a procedure for determining whether
variation in the response variable arises within or among different population groups.
+ Classification: classify new observations from examples of labeled data. To explore
classification models interactively.
+ Statistical Visualization: Show the relationships between variables using bivariate
plots such as grouped scatterplots and bivariate histograms.
+Descriptive Statistics: Compute descriptive statistics from sample data, including
measures of central tendency, dispersion, shape, correlation, and covariance. Tabulate
and cross tabulate data, and compute summary statistics for grouped data.

Part 2: Generating common signal in MATLAB


Task 4: Generating the unit-step function in MATLAB
Exercise:

- Use a user-defined function to construct a unit-step function

Figure 12: Construct a unit step function using a user-defined function

10
Reflection:

- Set a time array and create three unit-step functions

Figure 13: Set time array and create unit-step functions

- Testing our user-defined function.

Figure 14: Testing the user-defined function

11
Figure 15: Graph for the three function

Task 5: Generating a sinusoidal waveforms in MATLAB


Exercise:

- Create and plots 3 sinusoids and plot them on three subplots in MATLAB:
+ Create a time array of length 1 second with a step-sized of 1/44100 Hz and create
three of the following sinusoids.

Figure 16: Create and plots the sinusoids

12
+ Plot the three sinusoids in three subplots in MATLAB.

Figure 17: Plot the three sinusoids in subplots

Figure 18: Graph of the 3 sinusoids function

13
Reflection:

- Identify the three frequencies (in Hz) of these sinusoids:


+ 𝑥 :𝑓 = = 440 𝐻𝑧
+ 𝑥 :𝑓 = = 880 𝐻𝑧
+ 𝑥 :𝑓 = = 500 𝐻𝑧
- For the two phase shift sinusoidal what are the corresponding time shifts (in seconds):
+ 𝑥 (𝑡) = cos 880𝜋𝑡 + → cos[ 880𝜋(𝑡 + )] = cos[880𝜋 𝑡 + ]
×
 The time shift is 𝑠, shifting to the left.
+ 𝑥 (𝑡) = 2.5 cos(1760𝜋𝑡) → 2.5 cos[1760𝜋(𝑡)]
 The time shift is 0, there is no shift.
+ 𝑥 (𝑡) = 3 cos(1000𝜋𝑡 − ) → 3 cos[1000𝜋 𝑡 − = 3 cos[1000𝜋 𝑡 −
×
 The time shift is − , shifting to the right.
- The value of Fs we need to use sounds is 44100 Hz (common sampling frequency)

Task 6: Generating complex exponentials


Exercise:

- Using the same time array from the previous task, create a complex exponential with a
frequency𝑓 = 50 𝐻𝑧.
- Setting the parameters.

Figure 19: Setting the parameters

14
- Plot the real and imaginary part.

Figure 20: Plot the real and imaginary part

Figure 21: The real and imaginary part of the complex exponential

15
Reflection:

- Relations between cosine, sine and exponential functions:

𝑒± = cos(𝜃) ± 𝑖𝑠𝑖𝑛(𝜃) [4]

- From the complex number from task 6: 𝑥 = 𝑒 = cos(𝜔𝑡) + 𝑖𝑠𝑖𝑛(𝜔𝑡) (1)


- From (1) cosine represents for the real part, sin represents for the imaginary part.
- From figure 18, the graph of the real part represents the graph of cosine function.
(𝑦 = cos(𝜔𝑡))
- From figure 18, the graph of the imaginary part represents the graph of sine function.
(𝑧 = sin(𝜔𝑡))
-

Figure 22: Graph of complex number


16
- Because the cosine functions (real part) is represented by horizontal axis. (𝑥 = cos 𝑡)
And the sine function (imaginary part) is represented by the vertical axis. (𝑦 = sin 𝑡). So
the graph will presented itself as a circle with radius equal to 1(𝑟 = 1).

Conclusion
To sum up, in this lab report, for the part 1, we are using the MATLAB for
importing and manipulating audio, images and Excel data. For example, in
task 1, we use the function to generating the sound which is higher frequency
than the original. In task 2, we can change the blue colored pixels with the
corresponding pixel in the image ‘tartan.jpg’. For the part 2, we continue to
use MATLAB for generation the unit-step function, a sinusoidal waveforms
and complex exponentials. For instant, in task 5, to create and plots 3
sinusoids, we have to create a time array of length 1 second with a step sized
is 1/44100 Hz and create three of the following sinusoids. In the task 6, as
same as task 5 we use the time array to create the complex exponential with
𝑓 = 50 𝐻𝑧, after that we plot the real and imaginary part.

Peer assessment
Work assessment Contribution
Writing the report, writing and
Pham Ba Dat – s3687451 fixing the code format. (task 1,2) 33%
Writing, checking the code and
Tran Trong Tin – s3694839 fixing the code format.( Task 33%
4,5,6)
Writing the report, writing and
Tran Do Chi Hai – s3653997 fixing the code format. (task 3, 4) 33%

17
Reference
[1] https://en.wikipedia.org/wiki/MATLAB

[2] https://en.wikipedia.org/wiki/Electronic_filter

[3] https://nevadafilm.com/production-notes-chroma-keying-and-green-screens/

[4] http://mathworld.wolfram.com/EulerFormula.html

18

Das könnte Ihnen auch gefallen