Chapter 7: Statistics of Sound
Free Preview
7.1 Music as Data
Think of a melody as numbers: pitch, duration, timbre. Simple statistics reveal style and structure.
# Example melody in MIDI pitches
melody_pitches = [60, 62, 64, 65, 67, 69, 71, 72]
melody_pitches7.2 Music Analysis with Pandas and Python
Spreadsheets are just tables: every row describes one song, every column stores the same kind of fact for each song (tempo, key, energy, …).
Why is that powerful?
- Consistency → quick math Uniform columns let us sort, filter, and average in a single line of code.
- Clarity → better questions Well-labeled tables make patterns jump out: which keys dominate? How fast is the typical Miles Davis tune?
- Automation → scale The Pandas library treats a CSV file like a programmable spreadsheet, so the same analysis works on twenty songs or twenty-thousand.
In the table below each row is a jazz classic; the columns capture five numeric (quantitative: countable values) or categorical (qualitative: descriptive categories) features:
- Title: song name (categorical)
- Artist: performer or ensemble (categorical)
- Tempo: beats per minute (numeric)
- Key: tonal center (categorical)
- Energy: 0 to 1 proxy for loudness, density, rhythmic drive (numeric)
You’ll compute summary stats and build three quick plots:
- Histogram of tempo: see how fast most tunes sit.
- Scatter of tempo vs energy: spot high-energy outliers.
- Box-plot of tempo by key: compare common jazz keys side-by-side.
Continue reading this chapter
You're reading a free preview. Purchase the book to unlock every chapter in Artificial Intelligence for Musicians.
✓ Full book unlocked✓ Every chapter✓ Runnable code✓ Lifetime access
