CCCG 2003, Halifax, Nova Scotia, August 11–13, 2003 Computing a Geometric Measure of the Similarity Between two Melodies Greg Aloupis Thomas Fevens Stefan Langerman Tomomi Matsui § Antonio Mesa Yurai Nu˜ nez David Rappaport Godfried Toussaint Abstract Consider two orthogonal closed chains on a cylinder. The chains are monotone with respect to the angle Θ. We wish to rigidly move one chain so that the total area between the two chains is minimized. This is a geometric measure of similarity between two repeating melodies proposed by ´ O Maid´ ın. We present an O(n) time algorithm to compute this measure if Θ is not al- lowed to vary, and an O(n 2 log n) time algorithm for unrestricted rigid motions on the surface of the cylin- der. 1 Introduction We have all heard numerous melodies, whether they come from commercial jingles, jazz ballads, operatic aria, or any of a variety of different sources. How a human detects similarities in melodies has been studied extensively [11, 7]. There has also been some effort in modeling melodies so that similarities can be detected algorithmically. Some results in this fascinating study of musical perception and computation can be found in a collection edited by Hewlett and Selfridge-Field [6]. Similarity measures for melodies find application in content-based retrieval methods for large music databases such as query by humming (QBH) [5, 12] but also in other diverse applications such as helping prove music copyright infringement [3]. Previous work on melodic similarity is based on methods like approxi- mate string-matching algorithms [1, 8], hierarchical cor- relation functions [9] and two-dimensional augmented suffix trees [2]. ´ O Maid´ ın [10] proposed a geometric measure of the distance between two melodies, M a and M b . The School of Computer Science, McGill University. {athens,godfried}@uni.cs.mcgill.ca Department of Computer Science, Concordia University. fevens@cs.concordia.ca Charg´ e de Recherches du FNRS, epartement d’Informatique, Universit´ e de Bruxelles. Ste- fan.Langerman@ulb.ac.be § Department of Mathematical Informatics, Graduate School of Information Science and Technology, University of Tokyo. tomomi@misojiro.t.u-tokyo.ac.jp Facultad de Matematica y Computacion, Universidad de la Habana. tonymesa@matcom.uh.cu , yurainr@yahoo.com School of Computing, Queen’s University. daver@cs.queensu.ca melodies are modelled as monotonic pitch-duration rec- tilinear functions of time as depicted in Figure 1. ´ O Maid´ ın measures the distance between the two melodies by the area between the two polygonal chains. This rec- tilinear representation of a melody is equivalent to the triplet melody representation in [9]. In a more general setting such as music retrieval sys- tems, we may consider matching a short query melody against a larger stored melody. Furthermore, the query may be presented in a different key (transposed in the vertical direction) and in a different tempo (scaled lin- early in the horizontal direction). Francu and Nevill- Manning [4] compute the minimum area between two such chains, taken over all possible transpositions. They do this for a constant number of pitch values and scal- ing factors, and each chain is divided into m and n equal time-steps. They claim (without describing in de- tail) that their algorithm takes O(nm) time, where n and m are the number of unit time-steps in each query. This time bound can be achieved with a brute-force ap- proach. In this paper we solve a similar problem, in a more general setting. In some music domains such as Indian classical music, Balinese gamelan music and African music, the melodies are cyclic, i.e. they repeat over and over. In Indian mu- sic these cyclic melodies are called talas [13]. Two such monophonic melodies may be represented by orthogo- nal polygonal chains on the surface of a cylinder, as shown in Figure 2. This is similar to Thomas Edison’s cylinder phonographs, where music is represented by in- dentations around the body of a tin foil cylinder. We consider the problem of computing the minimum area between two such chains of size n, over all translations on the surface of the cylinder. We present two algorithms to find the minimum area between two given orthogonal melodies with periods of 2π. The first algorithm will assume that the Θ direction is fixed. The second algorithm will find the minimum area when both the z and Θ relative positions may be varied. We will assume that the vertices defining M a and M b are given in the order in which they appear in the melodies. 1