# Turning sound into a graph

I'm writing a comprehensive text on graphs and Mathematica and in this context I have this, let's call it, creative gap between sound and graphs. There are plenty of ways one can create graphs from and to objects; meshes, morphological graphs from images, to/from (sparse) matrices, curated data...but how to turn sound into a graph?

One could use a discrete Markov process to transition between chords, for example, but I don't see a solution in the other direction. Note, I'm not asking thousand lines of code, just a simple textbook-like example or idea.

• Would be great if you could provide a sound, and the expected graph.
– Öskå
Aug 29, 2014 at 15:41
• Do you want the graphs that are part of a Sound object, e.g. the output of Import["ExampleData/rule30.wav"]? Aug 29, 2014 at 15:43
• I don't have an expected graph for a sound. For an arbitrary wav or mp3, how would you represent the data contained in this sound as a graph? It's a conceptual question, not so much a technical one. Though I'd be happy if there was a magical line of code. Aug 29, 2014 at 16:23
• He! Reminded me of this codegolf.stackexchange.com/a/3764/315 Aug 29, 2014 at 16:47

For Sound objects like

sound = Import["ExampleData/rule30.wav"]


Mathematica creates a visual representation be default.
To use it in your own visualizations, you can extract this information by

ListLinePlot[sound[[1, 1]], PlotRange -> All]


and do something like

Graph@Table[
sound[[1, 1, 1]][[n]] <-> sound[[1, 1, 1]][[n + 1]],
{n, 1, Length@sound[[1, 1, 1]] - 1}]


Graph@Table[
sound[[1, 1, 1]][[n]] <-> sound[[1, 1, 1]][[n + 1]], {n, 1, 100}]


• Graph[] =!= Plot[] :D Aug 29, 2014 at 16:43
• @belisarius I thought he meant graph and not Graph ;-). Aug 29, 2014 at 17:12
• I've always wondered how to solve the traveling salesman problem without being able to see... Aug 29, 2014 at 17:14
• Yes, the fact that people use 'graph' for barcharts and whatnot is annoying. Same for 'network' and 'diagram', in fact. In any case, brilliant solution @Karsten-7. Lovely floral graphs :) Aug 29, 2014 at 17:38
• @FrancoisVanderseypen Thanks! And and also thank you to belisarius for his hint. Aug 29, 2014 at 17:48