I would like to visualize a sampled sound, and place the sounds as notes starting from C0 to A8 or such. I have a table of frequencies (in $[Hz]$) of these notes, and I have a sample sound.

My goal is to have along the $y$ axis the possible notes, and along the $x$ axis the time.

My main question is, what are the values of the SampleSoundList, and can they easily be related to the frequencies from my table? The table is in Excel, but I could write it out as a list of { { C0, 16.35}, .. }.

Any help or pointers in the right direction would be much appreciated.

Additional Information: What are values?

toSpectrogram[x_] := Print[Spectrogram[x]] &&  Print[ x ]
Button["Sing", snd = SystemDialogInput["RecordSound"]; 
 toSpectrogram[snd[[1]]], Appearance -> "DialogBox", 
 Method -> "Queued"]

What I mean by what are the values of a SampledSoundList in this sense:

SampledSoundList[{{0.,0.,-0.0078125,0.,0.,0.,0.,-0.0078125,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,-0.0078125,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.0078125,0., ........ 0.,0.,0.0078125}},11025]

The final value ,11025] is the sample rate. But what are all of the other Reals? How could/would they relate to finding a pitch, or frame to look at to figure out if the sound is a note or what note they are?

Can I iterate over this list of "values" and get an idea of the Musical Note at any point, or series of points?

I imagine that the sound is sampled at a certain rate, i.e. the 11025 and so this means that a certain block of numbers in the list represent a point in time, but I don't know what the actual numbers mean? Are they some kind of representation of pitches?

The numbers are from -1 to 1, so they represent some kind of whole but what that whole is is unknown to me. I am sorry if I am being dense. This is just an area of curiosity for me.



From all the input and more doc reading, I have come up with this:

toSpectrogram[x_] := (Print[Spectrogram[x]]; plotSampledSoundList[x])
  x_] := (sa = Abs[SpectrogramArray[x[[1]][[1]], 16, 10]]; 
  Print[ListLinePlot[sa[[{10, 35}]], DataRange -> {0, 8000}, 
    PlotRange -> {{500, 5000}}, Ticks -> {Automatic, None}]])
Button["Sing", snd = SystemDialogInput["RecordSound"]; 
 toSpectrogram[snd[[1]]], Appearance -> "DialogBox", 
 Method -> "Queued"]

This is getting very close to what I want, though I am still unclear on some of the arguments. In the case of SpectrogramArray, the 16 is supposed to be the bit depth of the sample? So if I record at 11khrtz 16bit then this should be good? The plot that comes out is what I was hoping for, but I could be wrong.

The final part of my question is: How do I place the Note values up the y axis starting with C0-A8 or what not ( can be smaller range, or even better if it fits the sound to the range).

  • $\begingroup$ What do you mean "what are the values of SampleSoundList" ? I can easily ask what are the values of the traffic lights from here to Baltimore, but that would not make sense. Please, elaborate :) And also add any relevant data - even if it is a sample. $\endgroup$
    – Sektor
    Apr 14, 2014 at 12:29
  • $\begingroup$ Look at SpectrogramArray, especially the "Neat Example" $\endgroup$ Apr 14, 2014 at 14:10
  • $\begingroup$ I added some more details and some working code to look at what I am looking at. $\endgroup$
    – J. Martin
    Apr 14, 2014 at 20:17
  • $\begingroup$ @Simon Woods SpectrogramArray seems to be the right direction, but what is meant by partition, or more specifically, how do I figure out the partition? $\endgroup$
    – J. Martin
    Apr 15, 2014 at 8:31
  • $\begingroup$ The numbers in SampledSoundList are samples of the wave amplitude. You need to do some processing to convert this data to a time-frequency representation. One way is to split the data into chunks (partitions) and compute the discrete Fourier transform of each chunk, which is what SpectrogramArray does. The second argument is the length of each partition, i.e. the number of samples it contains. $\endgroup$ Apr 15, 2014 at 13:20

1 Answer 1


To help you get started, here is a simple demonstration with Spectrogram. First I need a list of note names and frequencies:

notes = Thread[{440.0*2^(Range[0, 12]/12),
         {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A"}}];

Now I choose a sample rate and generate a set of samples corresponding to playing each note in turn for 1/2 second. In your application you are getting the list of samples from the SampledSoundList.

samplerate = 20000;

samples = Join @@ Table[Sin[2 \[Pi] f t],
    {f, notes[[All, 1]]},
    {t, 0, 0.5, 1/samplerate}];

Now show the Spectrogram:

Show[Spectrogram[samples, 2048, 256, BlackmanWindow,
  DataRange -> {
    {0, Length[samples]/samplerate},
    {0, samplerate/2}},
  AspectRatio -> 0.8],
 PlotRange -> {All, {600, 700}}, 
 FrameTicks -> {Range[0, 7], Range[400, 1000, 100], {}, notes},
 GridLines -> {None, notes[[All, 1]]},
 GridLinesStyle -> Opacity[0.3],
 Method -> {"GridLinesInFront" -> True},
 FrameLabel -> {"Time (s)", "Frequency (Hz)", "", "Notes"}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.