Visualizations of Tonality
CCRMA Affiliates, 10 May 2001
Craig Stuart Sapp (craig@ccrma.stanford.edu)

Key determination algorithm


Pitch Space

Sample Graphical Determination of Root

Rhythmic Weightings

Samples root scores for above musical example





Basic Algorithm Calculations

 
@vectorx = ( 0, 7, 7, 1000, 4, 4, 4, 4, 4, 1000, 8, 1, 1, 8, 8, 5, 5,
                5, 5, 5, 1000, 9, 2, 2, 2, 9, 1000, 6, 6, 6, 6, 6, 1000, 3,
                3, 3, 3, 10, 7, 7 );
 
@vectory = ( 0, -2, -4, 1000, 4, 2, 0, -2, -4, 1000, 3, 1, 1, -3, -5, 5,
                3, 1, -1, -3, 1000, 4, 2, 0, -2, -4, 1000, 4, 2, 0, -2, -4,
                1000, 3, 1, -1, -3, -5, 4, 2 );
$delta = -4;
$lambda = -3;
$alpha = 0.65;
For every hypothetical root, measure the distance to all input notes. Choose the hypothetical root with the lowest distance score as the most likely root.
sub analysis {
   my $count = @pitch;
   my @analysis;
   for ($i=0; $i<40; $i++) {
      $asum = 0.0; $bsum = 0.0; $dsum = 0.0; $lsum = 0.0;
      for ($j=0; $j<$count; $j++) {
         $p = ($pitch[$j] - $i + 40) % 40;
         $ipn = sqrt($alpha * $alpha * $vectorx[$p] * $vectorx[$p] +
                      $vectory[$p] * $vectory[$p]);
         $asum += $ipn * ($delta + log($duration[$j]));
         $bsum += $ipn * ($lambda + log($level[$j]));
      }
      $analysis[$i] = ($asum + $bsum)/$count;
   }
   return @analysis;
}