Skip to main content
Added embellishments
Source Link
Bob Hanlon
  • 162.7k
  • 7
  • 81
  • 205
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"}}]}]]

enter image description here

Original answer:

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"}}]}]]
Clear["Global`*"]

$Version

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

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"}}]}]]
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"}}]}]]

enter image description here

Original answer:

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"}}]}]]
Source Link
Bob Hanlon
  • 162.7k
  • 7
  • 81
  • 205

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)" *)

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"}}]}]]

enter image description here