From Sound to Swara: The Mathematics of Music

Why This Matters

You hear a sound. Your brain instantly knows:
– Is it high or low?
– Is it stable or wobbling?
– Does it match the previous note?

In Carnatic music, this becomes systematic: Sounds organize into swaras (notes with defined pitch relationships).

Swara isn’t just “a note”—it’s a position in a relational system. Understanding this transforms listening from “nice sounds” to “structured musical logic.”


What You’ll Learn

By the end of this article, you’ll understand:

  1. What makes a sound a “swara” (stable pitch, defined relationships)
  2. The 12-swara system and why it’s based on frequency ratios
  3. How swaras relate to each other (intervals, not absolute pitches)
  4. What happens when pitch relationships break (out-of-tune, microtones, gamakas)

From Physics to Perception: What Is Pitch?

Sound as Vibration

Physical reality:
– String vibrates at 440 Hz (cycles per second)
– Creates pressure waves in air
– Ear detects these oscillations

Perceptual reality:
– Brain interprets 440 Hz as “A”
– Higher frequency → higher pitch
– Lower frequency → lower pitch

Key insight: Pitch is logarithmic, not linear.

# Frequency doubling = one octave higher
A3 = 220 Hz   # Low A
A4 = 440 Hz   # Middle A (twice the frequency)
A5 = 880 Hz   # High A (twice again)

# Perceptually: A3→A4 sounds "same distance" as A4→A5
# But physically: 220Hz difference vs. 440Hz difference

Why logarithmic?
– Matches how our hearing works
– Small frequency changes matter more at low frequencies
– Musical intervals are multiplicative ratios, not additive differences


The 12-Swara System: Relationships, Not Absolutes

Saptaswaras: The Seven Core Pitches

Carnatic music names seven fundamental pitches:

Sa  Ri  Ga  Ma  Pa  Da  Ni  (Sa)
 1   2   3   4   5   6   7   (8)

“Sa” (Shadja) = reference pitch (like “C” in Western music)
All other swaras defined relative to Sa.

The 12 Positions: Including Variations

Full chromatic system includes variants:

Sa  Ri1  Ri2  Ga1  Ga2  Ma1  Ma2  Pa  Da1  Da2  Ni1  Ni2  (Sa)
 1    ♭2   2    ♭3    3    4    ♯4   5   ♭6    6    ♭7    7   (8)

Key principle: These are not arbitrary frequencies. They’re mathematical ratios relative to Sa.

Frequency Ratios: Why These Pitches?

Just Intonation (pure ratios):

Swara Ratio to Sa Example (if Sa=240Hz)
Sa 1:1 240 Hz
Ri2 9:8 270 Hz
Ga2 5:4 300 Hz
Ma1 4:3 320 Hz
Pa 3:2 360 Hz
Da2 5:3 400 Hz
Ni2 15:8 450 Hz
Sa 2:1 480 Hz (octave)

Why these ratios?
– Simple integer ratios sound “consonant” (harmonious)
– 3:2 (Pa to Sa) = perfect fifth (most stable interval)
– 2:1 = octave (same note, different register)

Code demonstration:

def frequency_ratio(ratio_string, sa_frequency):
    """Calculate swara frequency from ratio."""
    numerator, denominator = map(int, ratio_string.split(':'))
    return sa_frequency * (numerator / denominator)


sa = 240  # Hz
pa = frequency_ratio('3:2', sa)
print(f"Sa = {sa} Hz")
print(f"Pa = {pa} Hz")
print(f"Ratio: {pa / sa:.3f}")

# Output:
# Sa = 240 Hz
# Pa = 360 Hz
# Ratio: 1.500

Swaras Are Relational, Not Absolute

Key Insight: Sa Can Be Anything

In Carnatic music, Sa is arbitrary:
– Your Sa might be 220 Hz (A3)
– My Sa might be 240 Hz (B♭3)
– Singer’s Sa might be 260 Hz (C4)

What matters: The relationships between swaras, not their absolute frequencies.

Example: Raga Mayamalavagowla uses this pattern:

Sa Ri1 Ga2 Ma1 Pa Da1 Ni2 Sa
 1  ♭2   3   4  5  ♭6   7  8

Intervals (ratios):

Sa → Ri1: semitone (16:15)
Ri1 → Ga2: whole tone + semitone (75:64)
Ga2 → Ma1: semitone
Ma1 → Pa: whole tone
Pa → Da1: semitone
Da1 → Ni2: whole tone + semitone
Ni2 → Sa: semitone

These intervals stay the same regardless of what frequency Sa is!


When Pitch Relationships Break

Failure Mode 1: Out of Tune

# Perfect Pa: 3:2 ratio
sa = 240
pa_perfect = sa * (3/2)  # 360 Hz

# Slightly off
pa_flat = 355  # 5 Hz flat
pa_sharp = 365  # 5 Hz sharp

ratio_flat = pa_flat / sa  # 1.479 (not 1.5)
ratio_sharp = pa_sharp / sa  # 1.521 (not 1.5)

# Perceptually: sounds "wrong" even though close

Human ears are sensitive: ~5-10 Hz deviation at this range is noticeable.

Failure Mode 2: Equal Temperament Compromise

Problem: Simple ratios don’t divide octave into 12 equal steps.

Equal temperament solution:

import math

def equal_tempered_frequency(sa, semitones):
    """Calculate frequency using equal temperament."""
    return sa * (2 ** (semitones / 12))


sa = 240
pa_equal = equal_tempered_frequency(sa, 7)  # 7 semitones up

print(f"Pa (just intonation): {sa * 3/2:.2f} Hz")
print(f"Pa (equal tempered): {pa_equal:.2f} Hz")

# Output:
# Pa (just intonation): 360.00 Hz
# Pa (equal tempered): 359.46 Hz

Trade-off: Equal temperament allows modulation (changing keys) but sacrifices pure consonance.

Carnatic music mostly uses just intonation (pure ratios) because Sa is fixed per performance.

Failure Mode 3: Gamakas (Intentional Pitch Variation)

Not all pitch movement is “wrong”!

Gamaka = ornamental pitch oscillation/glide that’s part of the swara’s identity.

Ri in Raga Todi:
┌─┐
│ │  Oscillates around target pitch
└─┘

This looks “out of tune” on a spectrogram but is musically correct.

Key difference:
Out of tune: Unintentional, static wrong pitch
Gamaka: Intentional, controlled pitch variation that expresses the raga


Cross-Domain Connections

Mathematics: Logarithmic Scales

From MATH-200.1: Exponential and Logarithmic Functions:

Musical intervals are multiplicative:

Sa × (3/2) = Pa
Pa × (3/2) = Ri (next octave)

Logarithmic scale makes multiplication look like addition:

log(Pa) - log(Sa) = log(3/2) = constant interval

Statistics: Perception vs. Measurement

From STAT-100.2: Distribution Shape:

Frequency distribution (linear): Spread out at high frequencies
Pitch distribution (logarithmic): Evenly spaced perceptually

AI: Pattern Recognition

From AI-200.3: Audio Processing:

Neural networks can learn to recognize swaras from audio, detecting:
– Fundamental frequency
– Harmonic structure
– Gamaka patterns


Pattern Passport

Pattern Observed: RELATIONAL STRUCTURE

How It Appears Here:
Swaras = pitches defined by ratios, not absolutes
Sa = arbitrary reference point
Intervals = multiplicative relationships (frequency ratios)
System = 12 positions with defined relationships

Representation:
Physical: Frequency (Hz)
Musical: Swara name (Sa, Ri, Ga, …)
Mathematical: Ratio relative to Sa (1:1, 9:8, 5:4, …)
Perceptual: Interval (semitone, whole tone, fifth)

Transformation Rules:
Transpose: Multiply all frequencies by constant (preserves ratios)
Octave: Multiply frequency by 2 (same swara, higher register)
Inversion: Swap ascending/descending intervals

Assumptions:
– Human perception is logarithmic (roughly)
– Simple integer ratios sound consonant
– Sa is stable throughout performance
– Listeners can perceive pitch relationships

Failure Conditions:
1. Out of tune: Ratios don’t match system (unintentional)
2. Temperament clash: Just intonation vs. equal temperament
3. Lost reference: Can’t identify Sa → can’t identify other swaras
4. Microtonal ambiguity: Pitch falls between defined positions

Related Disciplines:
Mathematics MATH-200.1: Logarithmic scales
Statistics STAT-100.2: Distribution transforms
AI AI-200.3: Audio pattern recognition

Next Learning Steps:
1. MUSIC-100.2: The Violin — Continuous pitch instrument
2. MUSIC-100.3: Tala — Rhythmic structure
3. MUSIC-200.1: Raga System — How swaras combine into ragas


Summary: Pitch as Relational System

Swaras are defined by relationships, not absolute frequencies.

Three key insights:

  1. Logarithmic perception: Pitch intervals are frequency ratios (multiplicative)
  2. Relational system: Sa is arbitrary; other swaras defined relative to it
  3. Mathematical foundation: Simple integer ratios create consonant intervals

What makes a swara:
– Stable pitch (not noise)
– Defined ratio to Sa
– Fits within 12-position system

What breaks the system:
– Out-of-tune performance (wrong ratios)
– Lost reference (can’t identify Sa)
– Temperament conflicts (pure ratios vs. equal temperament)

The value: Understanding pitch as relational system reveals structure in music. Not just “sounds” but “organized sound with mathematical logic.”


Exercises

  1. Calculate frequencies: If Sa = 220 Hz, calculate Ri2 (9:8), Ma1 (4:3), and Pa (3:2).

  2. Transpose: A melody uses Sa=240Hz. Rewrite all swara frequencies for Sa=260Hz. What stays the same?

  3. Detect out-of-tune: Pa should be 360 Hz (Sa=240Hz). Measured Pa is 355 Hz. What’s the ratio error?

  4. Design validation: Write code to check if recorded audio matches Raga Mayamalavagowla swara ratios (within 5 Hz tolerance).


Revision History

2026-07-30: Substantially revised to include frequency calculations, ratio demonstrations, failure modes, cross-domain connections.

2024-05-01: Originally published.


Reproducible Code

All code in this article is available at:
Code/pitch_examples.py — Frequency ratio calculations
validation/test_pitch_system.py — Validation tests

Run tests:

cd Categories/07-Music-and-Violin/100.1-From-Sound-to-Swara
python validation/test_pitch_system.py