Sunteți pe pagina 1din 8

Using Mathematica to Compose Music and Analyze Music

with Information Theory

Christopher W. Kulp1,* and Dirk Schlingmann2


1
Department of Physics and Astronomy
2
Department of Mathematics and Statistics
Eastern Kentucky University
Richmond, KY USA 40475
cwkulp@gmail.com,
dirk.schlingmann@eku.edu

Abstract. In this paper we present two case studies for the application of the
technical computing software Mathematica in the domain of music creation and
music research. The first section describes an experimental interface for the
usage of random points, parametric curves and other mathematical objects in
the role of three-dimensional musical scores. Similar to the technology of the
old-fashioned player piano roles which encode any arbitrary piece for
mechanical player piano in three basic dimensions (onset, pitch, duration) we
provide an interface where a 3-dimensional score is created, visualized and
played. With this software the scores can be created with the assistance of a rich
arsenal of mathematical functions and also the sound of each single note can be
controlled in terms of mathematical functions. The aim of this software is the
creation of experimental musical pieces which explore the musical potential of
certain mathematical functions. In this paper we restrict ourselves to sketch the
interface. The more interesting aspects, namely the ‘musicality‘ of concrete
sonifications of certain mathematical objects, are subject to our live
demonstrations in Berlin.
In the second section we show how information theory may be used in the
analysis of musical scores and how specialized packages of the software
Mathematica may assist such investigations. As a particularly interesting topic
we describe the calculation of the transfer entropy between selected
instrumental parts in Beethoven symphonies.

1 Composition of Music Using Mathematica


With the technical computing software Mathematica, one can produce high-quality
sounds. The Mathematica command, Play[f, {t, 0, tmax}], plays a sound with
amplitude f as a function of time t in seconds. For example, Play[Sin[440*2*π*t],
{t, 0, 1}] plays a pure tone with a frequency of 440 Hz (A4) for 1 second. Please

* Permanent address: Department of Physics, Lycoming College, Williamsport, PA USA


17701.

T. Klouche and T. Noll (Eds.): MCM 2007, CCIS 37, pp. 441–448, 2009.
© Springer-Verlag Berlin Heidelberg 2009
442 C.W. Kulp and D. Schlingmann

consult Wolfram (2003) for all the information on Mathematica’s sound capabilities.
We will explore Mathematica’s high-level programming language, graphics
capabilities, and numerical and symbolical calculation tools to generate potentially
exciting music. We will present programs that create musical compositions based on
mathematical objects. The possibilities are endless for creating interesting and
intriguing music and sounds.
In a simplified way, music in the traditional sense is a collection of finite pitch
tones (frequencies) that are played at certain times for certain durations. A three-
dimensional point {x, y, z} could be interpreted as a tone that is played at time x
(measured in seconds), with frequency y (measured in Hz), for a duration z (measured
in seconds). In this fashion, a list of three-dimensional points represents a musical
composition. For example, the list of two three-dimensional points, {{0.6, 440.0,
1.5},{1.1, 554.365, 0.3}}, consists of two tones where the first tone is played after 0.6
seconds, with frequency 440.0 Hz, for 1.5 seconds, and the second tone is played after
1.1 seconds, with frequency 554.365 Hz, for 0.3 seconds. The Mathematica command
to play such a sound is: Play[Piecewise[{{Sin[440.0*2*π*t], (t >= 0.6) && (t <=
0.6+1.5)}}]+Piecewise[{{Sin[554.365*2*π*t], (t >= 1.1) && (t <= 1.1+0.3)}}], {t, 0,
2.1}], where Piecewise[{{val1, cond1},{val2, cond2}, …}] represents a piecewise
function with values vali in the regions defined by the conditions condi Wolfram
(2003). If none of the conditions condi apply, the default value is 0.
Based on the above Mathematica command, we will introduce a program called
createMusic, written by Schlingmann (see Kulp, Machado and Schlingmann 2007),
that takes any finite list of three-dimensional points, like the one mentioned in the
previous paragraph, as input and turns it into a musical composition as described
above. Of course, we might need to scale the coordinates of the three-dimensional
points to reasonable values so that times (when tones are played), frequencies, and
durations are in acceptable ranges. For example, we do not want to include negative
durations or frequencies outside the range of human hearing. In the process of using
the program createMusic, a three-dimensional graph of the scaled three-dimensional
points will also be displayed (see Figure 1). This graph can serve as a visualization of
the musical composition. We apply createMusic to data that originates from random
points, parametric curves, sequences, or a variety of other mathematical objects.

Fig. 1. An example of a graph created by the program createMusic


Using Mathematica to Compose Music and Analyze Music with Information Theory 443

Instead of imitating and enhancing traditional music, Mathematica is also capable


of playing continuously changing sounds that stem from mathematical functions. For
example, Play[Sin[f[t]*2*π*t]+Sin[g[t]*2*π*t], {t, start, end}] plays continuously
changing frequencies that are controlled by the functions f and g. Of course, the
functions f and g might need scaling again to guarantee reasonable frequencies. We
then explore these possibilities with a variety of mathematical functions.
Besides using Mathematica to create music, we can also use it to develop time
series analysis algorithms which will allow us to analyze musical compositions.

2 Nonlinear Time Series Analysis of Musical Compositions


In this section, we will use time series analysis to study the relationships between
string instruments in several of Beethoven’s symphonies. Classical music
compositions contain a lot of very interesting structure which can be adequately
described and analyzed using mathematics. One way of analyzing music using
mathematics is to create a time series from the music. A time series is a list of
numbers which represent the measurement of a physical quantity. The measurements
are usually (but not always) taken at a regular time interval, Δt. For example, one can
measure the temperature of a room every five minutes. In general we write a time
series in the following format:

S = {s1 s2 s 3  s N },
where the element, si , represents the measurement of the physical quantity, S, taken at
time (i – 1) Δt. There exists a large literature on extracting information about a
system by performing calculations on time series measurements taken from the
system (Kantz and Schreiber 2004; Abarbanel 1996; and references therein). By
applying time series analysis methods to musical compositions, we hope to be able to
learn more about specific compositions as well as demonstrate quantitatively the
differences and similarities between compositions and composers. One of the long-
term goals of this project is to be able to use time series analysis to classify
compositions by composer without having to hear the piece.
The application of time series calculations on musical compositions is not new. In
Monroe and Pressing (1998) and Reiss and Sandler (2003), time series were generated
from a digital recording of various compositions. In particular, the authors of Monroe
and Pressing (1998) and Reiss and Sandler (2003) focused on phase space
reconstruction and the estimation of Lyapunov exponents. Estimation of the Lyapunov
exponent is typically done to determine whether or not a system is chaotic. In this
paper, we will not use recordings of Beethoven’s symphonies to generate our time
series; instead we will use the sheet music of the symphony. Furthermore, we will
focus on estimating the rate of information transfer between instruments as a means of
illustrating the relationships between string instruments in Beethoven’s symphonies.

2.1 Creating Time Series from Sheet Music

We begin by demonstrating how to create a time series from sheet music. Consider
the measure shown in Figure 2.
444 C.W. Kulp and D. Schlingmann

Fig. 2. A sample measure which was used to create the time series that appears below

The measure in Figure 2 contains a one-eighth A4 note, a one-eighth C5 note, and


two quarter-rests. Each note in Figure 2 represents a sound with a specific frequency.
For example, the A4 note corresponds to a sound with a frequency of 440 Hz while
the C5 note has a frequency of 523.35 Hz in twelve tone equal temperament. A rest
would correspond to a sound of zero amplitude and zero frequency. The elements of
the time series will be the frequencies of each note sampled at one sixteenth-note time
intervals. Hence, an eighth-note would be represented by two adjacent elements of the
time series. Following this scheme, the time series represented by the measure in
Figure 2 is:

{440 440 523.35 523.35 0 0 0 0 0 0 0 0} .


Please consult Kulp, Machado and Schlingmann (2007) for a Mathematica
algorithm which aides in the process of creating time series in the above fashion. The
time series in Monroe and Pressing (1998) and Reiss and Sandler (2003) were
generated from digital recordings of the music. This can lead to multiple time series
representations for the same composition. In our work we need a unique time series
representation for each piece. However, the above process for creating time series is a
slow and tedious one. In the near future, we hope to automate the above process by
using a Mathematica program to read a MIDI recording of the composition and
produce a time series. The advantage of the MIDI format, of course, is that the
recording contains a lot of symbolically preprocessed information about the piece
(note played, duration, velocity, etc…) and will lead to a unique time series
representation of the piece.
Once we have generated a time series from sheet music, we then convert it into a
binary series. Sometimes this is referred to as symbolizing the series (Daw, Finney and
Tracy 2003). Using a binary representation of a series is a powerful tool which can be
used to speed-up time series computations. When done carefully, the symbolization
retains much of the important temporal information. The symbolization is performed
by choosing a threshold, a number calculated from the time series. If an element of the
time series is greater than or equal to the threshold, then it is reassigned the value 1. If
an element of the time series is less than the threshold then that element is reassigned
the value of 0. For the work presented in this paper, we have chosen our threshold so
that it maximizes the binary series’ Shannon Entropy (Shannon 1948). This allows us
to retain as much of the information from the original system as possible.
We used the process described above to generate a binary time series for each
string instrument in several of Beethoven’s symphonies. Next, we will show how to
use a set of time series to demonstrate relationships between physical systems. This
will allow us to quantify the relationship between string instruments in each
symphony.
Using Mathematica to Compose Music and Analyze Music with Information Theory 445

2.2 Transfer Entropy and the Relationship between Physical Systems

We begin this section with a non-musical example. Suppose one were to measure the
amount of rainfall in the Gulf of Mexico and the average price of gasoline in the United
States each week for a period of ten years. By doing this, the observer has produced two
time series, one for rainfall and one for the price of gasoline. A natural question to ask
is, based on our data, does the amount of rainfall in the Gulf of Mexico influence the
price of gasoline in the United States? Time series analysis provides a means of
answering this question through the transfer entropy calculation (Schreiber 2000).
The transfer entropy measures the amount of information exchanged between two
systems based on their time series measurements. Consider two time series, X and Y,
each measured from a different (but possibly related) system. The transfer entropy
between the two systems can be computed using the equation below.
§ p ( x n +1 | x n , y n ) ·
T (Y → X ) = ¦ p ( x n +1 , x n , y n ) Log 2 ¨¨ ¸¸
© p ( x n +1 | x n ) ¹
§ p ( y n +1 | x n , y n ) ·
T ( X → Y ) = ¦ p ( y n +1 , x n , y n ) Log 2 ¨¨ ¸¸
© p ( y n +1 | y n ) ¹
The summation is over all possible elements in the time series. The base-two
logarithm gives a unit of bits for the transfer entropy. Hence, if T(X Æ Y) = 0.01 and
T(Y Æ X) = 0.1, then we say that Y more strongly influences X than vice-versa. The
function, p, is the probability that an element or set of elements occurs in the time
series. For example, the function, p(xn+1 = 1, xn = 1, yn = 0), would give the
probability of a 1 occurring in X one time-step after a 1 is measured in X and a 0 is
measured in Y. For a Mathematica algorithm which computes the transfer entropy,
the interested reader should consult Kulp, Machado and Schlingmann (2007).

2.3 The Application of the Transfer Entropy to a Symphony


When applied to string instruments in a symphony, the transfer entropy gives the
amount of information exchanged between instruments in the symphony. In other
words, the transfer entropy gives a way of quantifying relationships between
instruments in a symphony. As mentioned previously, in this paper we focus on the
string section of some of Beethoven’s symphonies. For example, Figure 3 shows the
result of the transfer entropy analysis of the first 30 measures of the first movement of
Beethoven’s First Symphony. We see that for any string instrument, X, T(V1 Æ X) >
T(X Æ V1). This tells us that the amount of information exchanged from the first
violin to any other string instrument is larger than the amount of information
exchanged in the opposite direction. Hence, we can say that the first violin influences
the other string instrument during these 30 measures. Note that T(B Æ C) = T(C Æ B)
= 0, this is due to the fact that parts for the bass and the cello are the same for the first
30 measures of the First Symphony. Extending this analysis further, one could then
generate the necessary time series for a transfer entropy analysis on a later movement
(or even a later time in the first movement) and see how these relationships change.
Note that it is not important to restrict the analysis to 30 measure blocks.
446 C.W. Kulp and D. Schlingmann

Fig. 3. The transfer entropy analysis of the string section of Beethoven’s First Symphony. Note
the change in notation, T(A,B) = T(A Æ B). Further note that: V1 = first violin, V2 = second
violin, V = viola, C = cello, and B = bass.

Fig. 4. The transfer entropy analysis of the string section of Beethoven’s Fifth Symphony. Note
the change in notation, T(A,B) = T(A Æ B). Further note that: V1 = first violin, V2 = second
violin, V = viola, C = cello, and B = bass.
Using Mathematica to Compose Music and Analyze Music with Information Theory 447

Besides looking at the relationships between instruments in one symphony, we can


also compare results from several symphonies. Figure 4 shows the results from the
transfer entropy analysis of the first 30 measures of Beethoven’s Fifth Symphony.
Notice that the relationship between the first violin and the other string instruments
has changed. In the Fifth Symphony, the most influential instrument appears to be the
bass (with the exception of when the bass is paired with the second violin). Figure 5
shows the results from the transfer entropy analysis for the first 30 measures of
Beethoven’s Sixth Symphony. Here we see that the viola tends to be the most
influential string instrument (with the exception of when the viola is paired with the
second violin). The point here is that we are seeing different relationships between the
string instruments in different symphonies.
The relationship between instruments in a piece of music sometimes is a hallmark
of the style of the composer. Using the transfer entropy, we can quantify the
relationship between instruments in a piece of music. By sampling different parts of
the same symphony, we can quantitatively study how the relationships between
instruments change throughout the duration of the symphony. Furthermore, if we see
that a particular instrument, such as the bass, is influential in one symphony but not in
a later symphony; it may suggest a change in style of composition by the composer.
In this case, the transfer entropy analysis can serve as one method of quantifying the
change in the style of the composer from one symphony to another. By sampling
other pieces written by the composer during different stages of his or her life, we may
be able to quantify how the composer’s style changed during his or her life. However,
to do such an analysis with Beethoven, we’d would need to do a complete transfer
entropy analysis of each of his symphonies. Completing such an analysis is a goal of

Fig. 5. The transfer entropy analysis of the string section of Beethoven’s Sixth Symphony. Note
the change in notation, T(A,B) = T(A Æ B). Further note that: V1 = first violin, V2 = second
violin, V = viola, C = cello, and B = bass.
448 C.W. Kulp and D. Schlingmann

this project. It is also important to mention that any attempt to quantify a composer’s
style using time series will most likely include several other analyses. However, we
believe that the transfer entropy will be an important piece of the overall all
quantitative analysis of a composer’s style of composition.

3 Conclusions
Mathematica can be used to generate interesting music based on data sets and
mathematical curves as shown above. Time series analysis provides a powerful tool
with which we can learn more about musical compositions. By using the transfer
entropy we can identify relationships between instruments in a symphony. By
studying how these relationships change from one symphony to the next, we may be
able to quantify how the style of a composer changes during his or her lifetime. With
more extensive studies, it may even be possible to identify the composer of a piece of
music of which little is known.

References
Abarbanel, H.D.I.: Analysis of Observed Chaotic Data. Springer, New York (1996)
Daw, C.S., Finney, C., Tracy, E.: A review of symbolic analysis of experimental data. Review
of Scientific Instruments 72, 915–930 (2003)
Kantz, H., Schreiber, T.: Nonlinear Time Series Analysis, 2nd edn. Cambridge, London (2004)
Kulp, C., Machado, M., Schlingmann, D.: Composition and Analysis of Music Using
Mathematica. Mathematica in Education and Research 12, 1–20 (2007)
Monro, G., Pressing, J.: Sound visualization using embedding: The art and science of auditory
correlation. Computer Music Journal 22, 20–34 (1998)
Reiss, J.D., Sandler, M.B.: Nonlinear Time Series Analysis of Musical Signals. In: Proc. on the
6th Intl. Conference on Digital Audio Effects (DAFX 2003), London, United Kingdom,
September 8-11 (2003)
Schreiber, T.: Measuring Information Transfer. Physical Review Letters 85, 461–464 (2000)
Shannon, C.E.: A Mathematical Theory of Communication. The Bell System Technical
Journal 27, 379–423 (1948)
Wolfram, S.: The Mathematica Book, 5th edn. Wolfram Media, Inc., Champaign (2003)

S-ar putea să vă placă și