Anda di halaman 1dari 4

Math in Music: Christmas Medley using MATLAB

Anton Mark Z. Casia1, Russel Miles Diaz Ng2, Franzel John Y. Lawas3, Jose Leander R. Velasquez4
Department of Electrical and Electronics Engineering
University of San Carlos
Talamban, Cebu City, Philippines
1
strikefrdm23@gmail.com, 2russdiazng@gmail.com, 3leznarf13@gmail.com, 4bazingaleander@gmail.com

AbstractMATLAB is a powerful language and interactive


environment. It stands for MATrix LABoratory which basically
means it is based on vectors and matrices as foundations of its
operations. Little did people know especially beginners in this
software that is also possible to create music from scratch using
this software. This project aims to create music the MATLAB
way. This paper focused on explaining how feasible it is to create
music through codes by integrating them with established fix
values of frequencies that corresponds to a specific note.
Keywordscomponent; formatting; style; styling; insert (key
words)

I. INTRODUCTION
Music has been a part of humanity ever since the beginning
of time. Some already view music as a necessity to their day to
day life. Many have wondered what the definition of sound is.
What is sound? What is music? Sound is defined to be the
vibration that travels through a medium, most commonly the
air, produced by regular and continuous vibrations that can be
heard by humans and animals alike. There are many
importance of sound to human life. Sound is the main form of
communication for humans and animals alike with the use of
various speeches where both parties can both understand and
comprehend.
Sound also covers a very wide scope of subjects or areas in
the field of science and technology. The study of sound is
known to be acoustics. Acoustics a branch of physics that deals
with the study of sound waves, its properties and the influence
it brought in our daily lives. Many technological breakthroughs
that have been proved beneficial to mankind are achieved in
the field of acoustics. Depth measurement with the use of
sound waves is presented by SONAR (Sound Navigation and
Ranging) technology. Some important examples are
chromatography, sterilization by the use of ultrasound, and
enhancing cell growth by the process of sonication.
Sound waves are discovered to be of varying frequency.
Frequency is defined to be the number of occurrences of a
repeating event per unit time. It is also said to be the reciprocal
of the unit period which is the duration of time in one cycle or
also known as the interval between beats. In short, frequency is
the amount of repeating vibrations in an object. Since the voice
of an individual person varies in frequency, it is classified into
how high the pitch or a high frequency note.

II. READING MUSIC SCORE SHEETS


Transcribing a music score sheet is a difficult task even for
an experienced musician. One must expend his whole
creativity into pouring his passion into his work. A music score
is a written or printed form of musical composition where
different symbols of importance are placed in different parts of
the staff. Different symbols in a music sheet represent certain
beats, timing, rhythm and many others. Important parts found
in the music sheet are explained in the section below.
A. Staff
The staff comprises of five lines and four spaces. Each of
those lines and each of those spaces speak to an alternate letter,
which speaks to a note. Those lines and spaces speak to notes
named A-G, and the note succession moves one after another
in order up the staff.
B. Notes
Notes indicate what part of the staff that will be played and
the duration for it to be played.
C. Key Signature
Key marks are demonstrated by two images, the # sign and
the lower case b. The # sign stands for sharp notes and the
lower case b remains for level notes. The arrangement and the
amount of images advise the entertainer which musical key to
perform.
D. Tempo Marks
Tempo marks Tempo marks are truncations of Italian
words that demonstrate how quick or moderate to play the
music and what feeling to incorporate. For instance, mp
implies mezzo-piano. This means tolerably delicate.

Fig F1. A Sample Music Score Sheet

III. IMPLEMENTATION IN MATLAB


MATLAB, with its broad and high-level programming
application, has the ability to produce sounds given the correct
frequency and duration. Because sound and frequency are
extremely correlated in deep roots, the score sheet that was
chosen and modified has to be converted from music notes and
rests to frequency and duration. To be able to easily convert the
music notes without calculations, we used this Note Frequency
Table in table T1.
Reminding again that rests represent 0 Hertz. After tallying
the frequencies, the duration was also taken into consideration.
Also, to be able to easily convert the music notes without
calculations, we used this Note Duration Table in table T2.
A chord is not that complicated too, in a sense that when a
chord is played three notes are played altogether. But we only
took the dominant note among the three notes. This dominant
note will be played oftentimes compared to the normal note
that changes after every beat.

Fig F2. Code on Loading Note Text File to MATLAB

Same with the notes, a notepad file containing the matrix is


also loaded unto the MATLAB application with constant
values like tempo and frequency included. This matrix contains
the notes imbued with the knowledge of chords. After loading
the individual chord sounds, it is then converted into a .wav
format.

Table T1. Note Frequency Table

Duration (s)

Quarter
Note
0.25

Half Note

Whole Note

0.5

Table T2. Note Duration Table

A. Playing the Notes


To be able to play the music as it should sound, we
approached it in a different method. A matrix was created with
the first row of values as frequency, and the second row of
values as the corresponding duration. This matrix was created
using the built-in application notepad. This matrix also contains
the frequency and the duration of the notes.
The notepad file containing the matrix is then loaded unto
the MATLAB application with constant values like tempo and
frequency included. After loading the note sounds, it is then
converted into a .wav file format.

Fig F3. Code on Loading Chord Text File to MATLAB

Fig F4. Code on Playing Combined .wav Files in MATLAB

the last and the tricky part: combining the two .wav files.
This process needed the concept of modulation to avoid sound
distortion. Down below shows how the two waves are
combined and how the modulated and combined sounds was
achieved, and played.
B. Spectrogram
The sounds and music we hear are just waves and signals
oscillating and vibrating at different frequencies. Being only
identified by our sense of hearing, it can also be visually
represented as a spectrum of varying frequencies over a period
of time. This representation is called a Spectrogram. A sample
spectrogram is shown in Figure F5 where the frequencies of
notes C4 to C5 are displayed over a period of 10 seconds. The
colours of the vertical axis represent the frequency and the
most prominent acoustic spike at a given time [R1].
Spectrogram is implemented in Matlab in the form of the
specgram function. This function works by doing a ShortTime Fourier Transform on a given signal and the frequency
magnitude is shown in the vertical axis. It is called by running
the command: specgram(y,overlapSamp,Fs); where y is the
signal vector, overlapSamp is the number of samples that each
segment overlaps, and Fs is the sampling frequency. A sample
spectrogram of our song is shown in Figure F6 where it is also
overlaid with the notes that it represents.
600
550
500

Frequency

450
400

IV. VOICE TYPE ALLOCATION IN MATLAB


Creating the combined .wav file is not the end of it all.
There was also a need to vary the frequency in the notepad text
files because of the different voice types that the music should
be in sync with.
Each voice type has different voice ranges meaning
different frequency ranges. But in this project, four voice types
will only be used and that is the soprano and alto for women,
and tenor and bass for men.

Note Range
Frequency
Range

250

5
Time

Tenor
C3 C5
130.8 523.3

Bass
E2 E4
82.41 329.6

With this table, if the initial notes used in the music sheet
do not qualify within the range, the unqualified notes should be
changed in a way that the note will transcend to a higher octave
or the note will descend in a lower octave. But the initial music
sheet that we had was already qualified for voice types alto
and tenor. So to solve the problem concerning the bass note file
and chord file. The unqualified notes were decreased by a
decrement of one octave. With this process, all the notes are
now qualified within the bass range. Lastly, concerning the
soprano, all the unqualified notes were increased with an
increment of one octave. Then four .wav files were created: the
soprano .wav file, the alto .wav file, the tenor .wav file, and the
alto .wav file.

300

Alto
F3 F5
174.6 698.5

Table T3. Note and Frequency Range Table for Different Voice Types

350

200

Soprano
C4 C6
261.6 1047

10

Fig. F5. Spectrogram of notes C4 C5

Fig. F6. Sample Spectrogram of song

V. RECORDING AND PLAYING VOICES IN MATLAB


With the polyphonic notes as the accompaniment for the
Christmas carol, the voice that it accompanies is also
recorded in Matlab. This is possible with the audiorecorder
command which creates an audio recorder object bringing
along with it the audiorecorder Methods. These methods
include the basic audio recording functions namely the
record, pause, resume, stop and play.
The part of the script used for the recording of our carol
is shown in Figure F7. The first line creates the
audiorecorder object having the variable name voice, a
sampling rate of 16000 Hz, 16 bits per sample, and having
only a single channel. Line 2 is then executed where the
recording is started in the voice object. At this time, we
speak through the microphone and after singing; the
recording is stopped by executing line 3. The audio data is
then taken from the voice object and saved to the audio
variable in line 4. This is then written was a .wav file at
line 5 having a sampling frequency of 16000 Hz and with a
voice filename. The recorded audio is then played and can
be heard by executing line 6.

when dealing with MatLab and its core functions and


features.

ACKNOWLEDGMENT
The authors would like to thank God for the wisdom,
knowledge He has given us and for the opportunity to learn
more. We would like to thank our colleagues family for
letting us stay for a night or two as we accomplish this
project. We would like to thank this learning institution for
providing us the opportunity to showcase our skills and
talents in this field. Lastly, we would like to thank our
parents for supporting us in this project.

REFERENCES
[1]http://www.cslu.ogi.edu/tutordemos/SpectrogramReading/spectrogram.h
tml
[2]http://www.thestudysite.com/importance-of-sound
[3] http://donrathjr.com/frequency-table/

Fig. F7. Script used for recording audio


Fig. F7. Script used for Recording Audio

CONCLUSION
To wrap this all up, MATLAB can really be used as a
great accompaniment in music but way harder to manipulate
than the usual musical instruments. Accomplishing this
project will not only require programming skills, but also
singing skills and skills concerning the technicalities of
music. We were able to successfully read notes from our
chosen music score sheet and convert the notes to their
corresponding frequencies. All these data are placed on a
Matlab data file and we created the code to read and combine
it to create the music accompaniment. Our voices were also
recorded using Matlab and was combined with the
accompaniment to finish up our medley. A music video was
then made in relation to the song therefore completing the
Christmas carol to the tunes of Jingle Bells and Feliz
Navidad respectively. The entire project was very
educational yet challenging. It has put the students
potentials to the test and had their brains and knowledge
tested on a whole new different academic and technical level.
Therefore, it is safe to conclude that this project has brought
the students substantial amount of experience and knowledge

Anda mungkin juga menyukai