You are on page 1of 13

TE2019 Digital Signal Processing Laboratory

A01339391: Andrés Islas Bravo


A01656127: Juan Pablo Valverde López
Campus Ciudad de México
Lab 1: Introduction to Matlab
School of Engineering and Sciences Date:​ 12/02/2021
Department of Mechatronics

1 INTRODUCTION
MATLAB is a high-performance language for technical computing. It integrates computation, visualization,
and programming in an easy-to-use environment [1]. The purpose of this lab activity is to familiarize with the
essential MATLAB functions used to perform calculations, signal generation and loading and writing audio
data.

OBJECTIVES
1. To identify the principal elements and functionalities of the MATLAB software package
2. To use essential MATLAB functions to perform calculations, signal generation, loading, and writing data.
3. To appreciate MATLAB as a development, simulation and testing environment for digital processing.

The aiming of this first practice is the familiarization with sinusoidal signals over a Matlab environment. In
other words, it consisted in tuning a variety of notes based on their properties as amplitude, frequency and
duration.

2 MATERIALS & METHODS

As this was the first practice involving the use of MATLAB, the only material required was the mentioned
software. Regarding the experiment itself, the generation of fundamental frequencies of a virtual recorder it
is required to define a sinusoidal waveform, whose general expression is:

y (t) = A sin(2π f t + φ) + β

Where A is the amplitude, f is the frequency of the sinusoidal, t is the time vector, φ is the phase, and β
is the offset. The frequency for each musical note, f , can be calculated as:
v
f= λ [Hz]

Where v is the speed of sound in air ( 343 [ ms ] approximately), and λ is the wavelength produced for each
musical note. In order to generate the fundamental frequencies of each note, an evaluation on variables
A, f and timer vector, t (described below) will be performed.
The vector t , from now on time_vect will be characterized as time_vect = f irst : increment : last , translated as
a row vector “ time_vect ” from f irst to last by increment.

3 RESULTS AND DISCUSSION


The amplitude of the sinusoidal waveform was defined with a value of 5, not as the recommended value of
20, because it resulted in a distorted sound in the PC that the experiment was conducted. Since the
proposed sequence of notes were more than 10, the duration of each musical note was reduced to 0.5 [s]
and the interval between each note was 0.55 [s] to assure there was no overlapping.
The sampling frequency was defined as the standard for audio, 44100[samples/second], this value was
used to obtain the sampling period which value was the increment in the time_vect .

p.1 of 13
Figure 1: Extract of the code run in MATLAB, specifying the used values.

[2]
Figure 2: Fundamental frequencies of each musical note.

The proposed sequence of musical notes was replaced with the melody of the famous video game “Super
Mario Bros”.

^E ^E ^E
^C ^E ^G G

^C G E
A B Bb A
G ^E ^G ^A
^F ^G ^E ^C ^D B

^C G E
A B Bb A
G ^E ^G ^A
^F ^G ^E ^C ^D B

^G ^F# ^F ^D ^E

p.2 of 13
G A ^C
A ^C ^D
^G ^F# ^F ^D ^E
*C *C *C

^G ^F# ^F ^D ^E
G A ^C
A ^C ^D
^D# ^D ^C

^C ^C ^C
^C ^D ^E ^C A G
^C ^C ^C
^C ^D ^E

^C ^C ^C
^C ^D ^E ^C A G
^E ^E ^E
^C ^E ^G
G

^C G E
A B Bb A
G ^E ^G ^A
^F ^G ^E ^C ^D B

^C G E
A B Bb A
G ^E ^G ^A
^F ^G ^E ^C ^D B

^E-^C G
G A ^F ^F A
B ^A ^A ^A ^G ^F
^E ^C A G

^E-^C G
G A ^F ^F A
B ^F ^F ^F ^E ^D ^C
GEC

^C G E
ABA
G# Bb G#
G F# G
[3]

The "Middle C" is C4, corresponding to the value specified in ​Frequencies of Musical Notes, A4 = 440 Hz
(mtu.edu)​ [4], The notes that have a “^” are sharper than the notes without it, so an upper scale was used.
All used values can be found in the table below. The full melody produced by the succession of given notes
can be listened on:
https://drive.google.com/file/d/1qtKXp8U2NMkIVbF4UmXTk5MvxZHfmcNH/view?usp=sharing

p.3 of 13
Musical Wavelength Theoretical Fundamental Practical Fundamental Error (%)
Note (cm) Frequency (Hz) Frequency (Hz)
Speed of Sound ( 345 ms ) Speed of Sound ( 343 ms )

C4 131.87 261.63 260.04 0.61

E4 104.66 329.63 327.78 0.56


#
F4 93.24 369.99 367.36 0.71

G4 88.01 392.00 389.63 0.60


#
G4 83.07 415.30 412.75 0.61

A4 78.41 440.00 437.38 0.59

B4 69.85 493.88 491.03 0.57


b
B4 74.01 466.16 463.32 0.61

C5 65.93 523.25 520.22 0.57

D5 58.74 587.33 583.89 0.58


#
D5 55.44 622.25 618.5 0.60

E5 52.33 659.25 655.26 0.60

F5 49.39 698.46 694.36 0.58


#
F5 46.62 739.99 735.62 0.59

G5 44.01 783.99 779.22 0.61

A5 39.20 880.00 874.92 0.57

C7 16.48 2093.00 2081.2 0.56


Table 1: Comparison between theoretical and practical fundamental frequencies

p.4 of 13
C4

Figure 3: Sinusoidal waveform for C 4

E4

Figure 4: Sinusoidal waveform for E 4

p.5 of 13
#
F4

#
Figure 5: Sinusoidal waveform for F 4

G4

Figure 6: Sinusoidal waveform for G4

p.6 of 13
#
G4

#
Figure 7: Sinusoidal waveform for G4

A4

Figure 8: Sinusoidal waveform for A4

p.7 of 13
B4

Figure 9: Sinusoidal waveform for B 4

b
B4

b
Figure 10: Sinusoidal waveform for B 4

p.8 of 13
C5

Figure 11: Sinusoidal waveform for C 5

D5

Figure 12: Sinusoidal waveform for D5

p.9 of 13
#
D5

#
Figure 13: Sinusoidal waveform for D 5

E5

Figure 14: Sinusoidal waveform for E 5

p.10 of 13
F5

Figure 15: Sinusoidal waveform for F 5

#
F5

#
Figure 16: Sinusoidal waveform for F 5

p.11 of 13
G5

Figure 16: Sinusoidal waveform for G5

A5

Figure 17: Sinusoidal waveform for A5

p.12 of 13
C7

Figure 18: Sinusoidal waveform for C 7

Figure 19: Plotting settings

4 CONCLUSION
Taking everything into account, the experiment was successful as the Table 1 shows, the fundamental
frequencies of each used musical note was replicated given the condition, the variables amplitude
determine the “volume” the note had when reproduced. The minor inconsistencies can be attributed to the
difference in the speed of sound in air (343 vs 345) and the pointer in Figures 2-18 so that the fundamental
period could be set and the fundamental frequency found.

5 REFERENCES
[1] Cooperative Institute for Meteorological Satellite Studies (2017). What is MATLAB. Obtained from:
https://cimss.ssec.wisc.edu/wxwise/class/aos340/spr00/whatismatlab.htm
[2] MATLAB. (2021). version 9.9.0.1524771. (R2020b). Natick, Massachusetts: The MathWorks Inc.
[3] Noob Notes (2018). Super Mario Bros. Theme - Nintendo. Obtained from:
https://noobnotes.net/super-mario-bros-theme-nintendo/
[4] Michigan Technological University (n.d). Physics of Music - Notes Tuning Frequencies for
equal-tempered scale, A4 = 440 Hz. Obtained from: https://pages.mtu.edu/~suits/notefreqs.html

p.13 of 13

You might also like