Mathematical Problems in Engineering

Mathematical Problems in Engineering / 2015 / Article
Special Issue

Mathematical and Computational Topics in Design Studies

View this Special Issue

Research Article | Open Access

Volume 2015 |Article ID 560926 |

Xiao-Yi Song, Dong-Run Huang, "A Study on Digital Analysis of Bach’s “Two-Part Inventions”", Mathematical Problems in Engineering, vol. 2015, Article ID 560926, 6 pages, 2015.

A Study on Digital Analysis of Bach’s “Two-Part Inventions”

Academic Editor: Teen-Hang Meen
Received16 Jun 2014
Accepted29 Aug 2014
Published27 Aug 2015


In the field of music composition, creating polyphony is relatively one of the most difficult parts. Among them, the basis of multivoice polyphonic composition is two-part counterpoint. The main purpose of this paper is, through the computer technology, conducting a series of studies on “Two-Part Inventions” of Bach, a Baroque polyphony master. Based on digitalization, visualization and mathematical methods, data mining algorithm has been applied to identify bipartite characteristics and rules of counterpoint polyphony. We hope that the conclusions drawn from the article could be applied to the digital creation of polyphony.

1. Introduction

1.1. Patterns

In the process of composition, the composer will always follow inspirations and then proceed according to a certain mode. Various types of patterns and rules are available in music works, the audience’s understandings on music can be expressed in a formalized way through a series of rules [1, 2]. These rules enables the audience to generate hearing expectation, which exists in different dimensions such as melody, rhythm, and harmony, and produces different patterns and pieces on the basis of constant changes in basic elements [1, 2]. Fractal geometry originated in the nineteenth century. Fractal sets are the geometry of chaos. It is an important branch in modern mathematics. Some famous mathematicians discovered the existence of a special structure and morphology with study on continuous nondifferentiable curves.

1.2. Our Works

This paper applied the MATLAB tool to visualize MIDI music data and observed and unveiled pattern features of polyphonic music with intuitive techniques. We emphasized our analysis on the No. 1 to No. 5, No. 6, No. 8, No. 13, and No. 14 of Two-Part Inventions (Johann Sebastian Bach). Experimental analyses were made in terms of the pitch and the tone, and the application of these patterns and rules in computerized digital music composition was discussed in the end.

2. Experiments

2.1. Preparations

The pitch is a very important element in the music; the audiences are very sensitive to changes in the pitch, and they are capable of feeling only 0.5% of change [1, 2]. Constant change in the pitch is reflected in the process of music, and the interval of change between pitches is very important in Western music system. We retrieved information from a MIDI file [3] and only utilized partial information in order to simplify the process. We defined a matrix aswhere is the start tempo, is continuing tempo, is the pitch, and is the pitch interval; that is,

2.2. Pitch Intervals and Statistics

This paper conducted statistics and analysis on semitone spaces of adjacent pitches in Bach’s works, and results were shown in Table 1. It is clearly seen that 1, 2, and 3 semitones represent the largest proportion of semitone spaces in the nine works of Bach under study. Effects of melodic interval and harmonic interval are similar, and they arouse different psychological feelings, like harmonic interval does, and let people have expectations, thus developing continuously from music thoughts. We can define a simple rule for composition in accordance with the statistics:

when a music event sequence is given, the proportion of semitone space between and at 1, 2, and 3 should be greater than 70% (Rule I) in the development of (Rule I).


No. 140.0030.1770.3580.1190.0580.070.0340.0680.0340.0340.0140.003
No. 130.0070.090.080.3680.140.0670.0540.1070.0330.0430.0030.003
No. 80.0030.20.2780.1190.0780.0340.0270.060.0540.0470.040.003
No. 60.0130.2940.3430.1250.0860.0430.0130.0130.0130.0170.010.003
No. 50.0050.260.4550.130.0590.0260.0050.0030.010.020.0080.015
No. 40.0250.2490.50.0360.0180.0250.0070.0290.0140.040.0430.011
No. 30.0360.2660.4090.0840.0330.0550.0260.0070.0180.0260.0360.004
No. 20.0390.2960.40.0560.0280.090.010.0140.0170.0230.0140.011
No. 10.0160.2340.4130.1630.070.0280.0040.020.0160.010.0160.008

2.3. Melody Intervals

In addition to overall statistics on this type of interval spaces, we also want to understand specific laws of changes in pitch interval during the marching process of the melody. We defined a set , each element of is a data pair , representing that the pitch interval between MIDI note event and on a voice part is equal to pitch interval between MIDI note event and on the other voice part; namely, . We mapped the pitch interval with MATLAB drawing tool, and the results are shown in Figure 1.

The following characteristics can be concluded by analyzing the above diagram: continuous circle lines occur in the linear system (slope: 1), a small starting piece repeatedly occurs at different positions in the second voice part. We can see, according to transitive relation, that lots of repetitive pieces occur on single parts, and by mapping the distribution diagram we can also find out that such pieces are occurring repeatedly in one voice part.

With further analysis of the music data, we know that the piece in the slope of Figure 1 maps to the note event as shown in Table 2. What is interesting is that the repeated piece is imitated differently. Some are imitated partly, while some fully. As shown in the original music staff in Figure 2, we can see that a piece of different event notes follows the repeated piece. They have different ostinato which gives the listener a sense of change.

First part start noteFirst part end noteSecond part start noteSecond part end note


It can be found from Table 3 that repeated interval pieces represent a very large proportion in Bach’s two-part inventions, and most of them (except No. 4) are at least 50%. During further analyses, we were aware that such repeated pieces occurred at different starting points of the pitch, and such repeat occurred at different tonalities. Therefore, we can define a new rule:

when given a particular pitch interval sequence to form a complete repertoire of music event sequence , sequence can be used to make the pitch interval sequence repeat times in , with being the starting pitch every time (Rule II).

No. 1No. 2No. 3No. 4No. 5No. 6No. 8No. 13No. 14


2.4. Tonality

As regards researches on tonality, a great many researchers have put forward plenty of models to describe changes in the tonality. Krumhansl proposed an algorithm to measure the music data and to determine perceivable tonality [1, 2, 4] on the basis of relevance with the attribute data of major and minor tonality measured by experience. Krumhansl’s algorithm is called K-Finding algorithm which is used to find out the main tonality of a piece of music. The method has shown great accuracy in measuring classical music such as Bach’s works. In our experiment, we apply Krumhansl’s K-Finding algorithm to analyze the change law of tonal characteristics of creative music in Bach’s inventions which we are going to study.

signifies the matrix of simplified music event; minimum was calculated from the first note event in sequence, making the total duration from the first note event to the th note event , tempos ( is user defined value). Then we applied the K-Finding algorithm to analyze the tonality key of in this piece and repeated the above-mentioned process with the second note event in as the first music note to get the second piece, until all note events were measured; in this way, we could obtain a set of music piece tonal change data. We used a visual method to map out the data, as shown in Figures 3, 4, 5, and 6: data distribution of Bach’s Two-Part Inventions No. 1.

It can be concluded that melodies converge on several different tonalities when rhythm lengths of benchmark pieces are different. According to the data collected, although Invention No. 1 is a Major C piece, its piece tonality is constantly changing in relation to the tonality of the whole work.

In order to further analyze the change rule of the tonality, we use Tables 4 and 5 to illustrate the relationship between changing pieces and the tonality.

MajorRising or Falling

Major C
Major FFalling B
Falling Major BFalling B, Falling E
Falling Major EFalling B, Falling E, and Falling A
Falling Major AFalling B, Falling E, Falling A, and Falling D
Falling Major DFalling B, Falling E, L Falling A, Falling D, and Falling G
Falling Major GFalling B, Falling E, Falling A, Falling D, Falling G, and Falling C
Major BRising F, Rising C, Rising G, Rising D, and Rising A
Major ERising F, Rising C, Rising G, and Rising D
Major ARising F, Rising C, and Rising G
Major DRising F, Rising C
Major GRising F

Relative minorRising or Falling

Minor ARising G
Minor DFalling B, Rising C
Minor GFalling B, Falling E, and Rising F
Minor CFalling E, Falling A
Minor FFalling B, Falling A, and Falling D
Falling Minor BFalling B, Falling E, Falling D, and Falling G
Falling Minor EFalling B, Falling E, Falling A, Falling G, and Falling C
Rising Minor GRising C, Rising G, Rising D, Rising A, and Heavy Rising F
Rising Minor CRising F, Rising C, Rising G, Rising D, and Rising B
Rising Minor FRising F, Rising C, Rising G, and Rising E
Minor BRising F, Rising C, and Rising A
Minor ERising F, Rising D

We used the piece tonality distribution diagram to analyze the characteristics of a music piece’s changes in tonality under the Krumhansl model, and the results are shown in Table 6.

WorksMain tonalitiesSpaces

Number 1Major C, Major G, Minor D, and Minor E1
Number 2Minor G, Rising Major A, Minor c, and Major C2
Number 3Major A, Minor B, and Major D1
Number 4Minor D, Minor A, and Major C2
Number 5Rising Major D, Minor F, and Rising Major G1
Number 6Major B, Major E1
Number 8Major F, Major C, Minor D, and Major A1
Number 13Minor E, Major C, and Minor A1
Number 14Rising Major F, Rising Major A, and Major D2

It can be concluded from Table 6 that whenever there are tonality changes, normally a tonality with minimum rising or falling values adjacent to the given main tonality will be selected for change purpose. In line with the above analyses, we can develop a new rule:

when composing a complete music event sequence , may consist of music sequences, and when the piece tonality under the Krumhansl model is no more than 12 (), the space between tonalities of music sequences should be no more than 2 (Rule III).

This rule is of great significance, and in the case of connecting repeated pieces, this method of tonality change may be used to analyze possibly connected pieces.

3. Discussion

In our experiment, we concluded the patterns and rules in Bach’s Two-Part Inventions, which is typical of polyphony works, and we discovered three characteristic rules (Rules I–III) in Bach’s Two-Part Inventions. Nevertheless, it needs pointing out that these three rules only cover the pitch and the tonality, with no consideration for the rhythm, melody, and harmony. Studies show that global context has an effect on music perception [5]. William did a lot a lot of experiments to study the effects on music perception of the integration of pitch and rhythm. Results show that the integration of the individual music parameter cannot be combined easily. They have effects on each other after integration [6]. So, the modeling of music is difficult; we need to study it further rather than applying the three rules everywhere.

4. Conclusion

Computerized musical composition includes auxiliary composition, algorithm composition, and works’ compilation. The three rules we put forward are applicable for basic rules of polyphony works with styles similar to Bach’s; in computerized algorithm composition these three rules can be used for assessing and selecting works with better polyphony styles, and they can be used in auxiliary computer composition to inspire the composer with musical pieces generated from these rules so as to speed up the efficiency of composition. In addition, these three rules can be used for identifying the characteristics of existent works and for categorizing various types of works.

Conflict of Interests

The authors declare that they have no competing interests regarding the publication of this paper.

Authors’ Contribution

All authors completed the paper together. All authors read and approved the final paper.


  1. C. L. Krumhansl, Cognitive Foundations of Musical Pitch, Oxford University Press, New York, NY, USA, 1990.
  2. C. L. Krumhansl, “Rhythm and pitch in music cognition,” Psychological Bulletin, vol. 126, no. 1, pp. 159–179, 2000. View at: Publisher Site | Google Scholar
  3. C. Roads, The Computer Music Tutorial, The MIT Press, Cambridge, Mass, USA, 1996.
  4. P. Toiviainen and C. L. Krumhansl, “Measuring and modeling real-time responses to music: the dynamics of tonality induction,” Perception, vol. 32, no. 6, pp. 741–766, 2003. View at: Publisher Site | Google Scholar
  5. E. Bigand and M. Pineau, “Global context effects on musical expectancy,” Perception & Psychophysics, vol. 59, no. 7, pp. 1098–1107, 1997. View at: Publisher Site | Google Scholar
  6. W. F. Thompson, “Sensitivity to combinations of musical parameters: pitch with duration, and pitch pattern with durational pattern,” Perception & Psychophysics, vol. 56, no. 3, pp. 363–374, 1994. View at: Publisher Site | Google Scholar

Copyright © 2015 Xiao-Yi Song and Dong-Run Huang. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

Related articles

No related content is available yet for this article.
 PDF Download Citation Citation
 Download other formatsMore
 Order printed copiesOrder

Related articles

No related content is available yet for this article.

Article of the Year Award: Outstanding research contributions of 2021, as selected by our Chief Editors. Read the winning articles.