Professional Documents
Culture Documents
Lab 1 Introduction To MATLAB
Lab 1 Introduction To MATLAB
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.
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.
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 )
p.4 of 13
C4
E4
p.5 of 13
#
F4
#
Figure 5: Sinusoidal waveform for F 4
G4
p.6 of 13
#
G4
#
Figure 7: Sinusoidal waveform for G4
A4
p.7 of 13
B4
b
B4
b
Figure 10: Sinusoidal waveform for B 4
p.8 of 13
C5
D5
p.9 of 13
#
D5
#
Figure 13: Sinusoidal waveform for D 5
E5
p.10 of 13
F5
#
F5
#
Figure 16: Sinusoidal waveform for F 5
p.11 of 13
G5
A5
p.12 of 13
C7
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