# How to visualize overtones in Mathematica?

I would like to visualize the difference in sounds extracted by different musical instruments, which is due to different overtones. In order to do this, I define the following samples:

ViolinNote = Sound[SoundNote["G", 1, "Violin"]]
PianoNote = Sound[SoundNote["G", 1, "Piano"]]
GuitarNote = Sound[SoundNote["G", 1, "Guitar"]]
AltosaxNote = Sound[SoundNote["G", 1, "AltoSax"]]


Naively, I expected to see the difference clearly when using Periodogram:

Periodogram[ViolinNote]
Periodogram[PianoNote]


However, it is completely non-illustrative. In particular, I am not able to distinguish overtones from these plots, as they are too dense:

May I please ask you whether for these samples a more illustrative demonstration of different overtones exists? Or, maybe, these samples are too complicated, and for some simpler samples such a demonstration exists?

• A slightly improved alternative than the Periodogram that retains time information.
– Syed
Oct 8, 2021 at 14:00
• Use PlotRange to show only the relevant part: Periodogram[{ViolinNote, PianoNote}, PlotRange -> {{0, 8000}, {-30, 30}}, AspectRatio -> 1/3]. Oct 8, 2021 at 16:08
• You should probably plot frequency in log-domain, which corresponds (somewhat) better to human perception than linear frequency domain. Oct 8, 2021 at 23:45

You can use Manipulate with an IntervalSlider to look at the different harmonics.

Clear["Global*"]

\$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)


EDIT: Some embellishments to the original answer.

Manipulate[
Module[{
notes = {"C", "C♯", "D", "D♯", "E", "F",
"F♯", "G", "G♯", "A", "A♯", "B"}, ff},
ff = 440.*2^((Position[notes, note][[1, 1]] - 10)/12);
Periodogram[
Sound[SoundNote[note, 1, instr]],
PerformanceGoal -> "Quality",
PlotRange ->
{{intHz[[1]], intHz[[2]]}, {intdB[[1]],
intdB[[2]]}},
Frame -> True,
FrameLabel ->
(Style[#, 12, Bold] & /@ {"Hz", "dB"}),
GridLines -> {Range[ff, 19 ff, ff], None},
GridLinesStyle ->
Directive[Red, Dashed, AbsoluteThickness[1]],
PlotLabel ->
StringForm["fundamental frequency = ",
NumberForm[ff, {6, 2}]]]],
Control[{{intHz, {0, 2000},
Row[{Spacer[100], "Interval [Hz]"}]}, 0, 5000, 200,
ControlType -> IntervalSlider,
Method -> "Push",
MinIntervalSize -> 250,
ControlPlacement -> Bottom,
Appearance -> "Labeled"}],
{{intdB, {-30, 30}, Rotate["Interval [dB]", Pi/2]},
-90, 40, 2,
ControlType -> IntervalSlider,
Method -> "Push",
MinIntervalSize -> 3,
ControlPlacement -> Left,
Appearance -> {"Vertical", "Labeled"}},
Row[{
Spacer[100],
Control[{{note, "G", "Note"},
{"C" -> "C", "C♯" -> "C♯/D♭", "D" -> "D",
"D♯" -> "E♭/D♯", "E" -> "E", "F" -> "F",
"F♯" -> "F♯/G♭", "G" -> "G",
"G♯" -> "A♭/G♯",
"A" -> "A", "A♯" -> "B♭/A♯", "B" -> "B"}}],
Spacer[36],
Control[{{instr, "Violin", "Instrument"},
{"AltoSax", "Guitar", "Piano", "Violin"}}]}]]


Manipulate[
Periodogram[Sound[SoundNote[note, 1, instr]],
PerformanceGoal -> "Quality",
PlotRange -> {{int[[1]], int[[2]]}, All},
Frame -> True,
FrameLabel ->
(Style[#, 12, Bold] & /@ {"Hz", "dB"})],
{{int, {0, 2000}, "Interval [Hz]"}, 0, 5000, 250,
ControlType -> IntervalSlider,
Method -> "Push", MinIntervalSize -> 500,
Appearance -> "Labeled"},
Row[{
Control[{{note, "G", "Note"},
{"C" -> "C", "C#" -> "C#/D♭", "D" -> "D",
"D#" -> "E♭/D#", "E" -> "E", "F" -> "F",
"F#" -> "F#/G♭", "G" -> "G", "G#" -> "A♭/G#",
"A" -> "A", "A#" -> "B♭/A#", "B" -> "B"}}],
Spacer[36],
Control[{{instr, "Violin", "Instrument"},
{"Violin", "Piano", "Guitar",
"AltoSax"}}]}]]
`