Sunday, April 1, 2012

Visualizing Musical Intervals and Harmonies using Matlab Figures

Visualizing Musical Harmonies

In this post we consider the issue of providing a visual interpretation of musical harmonies. Our approach is via
the simple model of Lissajous (“LEE-suh-zhoo”) figures, which are parametric plots that capture the visual nature of a harmonic system. Lissajous figures provide visual insight into the mathematical behavior of musical intervals in two dimensions and musical chords in three or more dimensions. For example, given two or more waveforms of fundamental frequencies: wavfreq1=sin (at + α), wavfreq2=sin(bt + β), etc., then we can easily plot the parametric curves using Matlab with lovely results.

In the theory of music, an octave is an interval with a pair of acoustic frequencies that range over a factor of two.

• On a piano (and most Western music) an octave is divided into twelve semitones with equal frequency ratios.
• Since twelve semitones comprise a factor of two, one semitone spans a factor that is 12th root of 2.
• The pitch we hear is the log of frequency, so successive pitches sound as if they are equally separated.
• σ (sigma) will be the basis for determining frequency intervals in our Matlab programs.
>> sigma = 2^(1/12)

% Here is code for plotting the 12 harmonic music intervals in Western music
% We take rational powers that approximate integral powers of sigma,
% which achieve more satisfying results
sigma = 2^(1/12);
powers = (0:12)';
equal = sigma .^ powers; % equal temperament
[num den] = rat(equal, .02);
for s = 1:12
t = linspace(0, 2 * den(s + 1) * pi, 500);
x = sin(t);
y = sin(num(s + 1)/den(s + 1) * t);
subplot(3, 4, s);
plot(x, y);
st = sprintf('%d/%d', num(s + 1), den(s + 1));
title(['\sigma^p : ' st]);

Here is a sample Matlab program based on usage of fractional powers of sigma for a sequence of 2-D plots of musical intervals. I leave the reader with the challenge to design a simple user interface to control the plot with respect to the movement to higher and lower frequencies.

%Matlab code to plot an animation of changing musical intervals
t = (0:0.1:100);
for a=0:.01:12
if (mod(a,1)==0)
pause(1); else pause(.05); end

% Here is code for plotting musical chords based on 3-dimensional Lissajous figures
t = (0:0.1:360);
for a= 11:1/60:60
if (mod(a,1)==0)
pause(2); else pause(.05); end


  1. Could you please add the axis for the third figure?

  2. Great idea! How did you find it? I'm a musician and mathematician and see these figures in my imagination when play. But you describe and draw them sciencly.
    Thanx, great work!