1
$\begingroup$

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.

$\endgroup$
4
  • 2
    $\begingroup$ Would be great if you could provide a sound, and the expected graph. $\endgroup$
    – Öskå
    Aug 29, 2014 at 15:41
  • $\begingroup$ Do you want the graphs that are part of a Sound object, e.g. the output of Import["ExampleData/rule30.wav"]? $\endgroup$
    – Karsten7
    Aug 29, 2014 at 15:43
  • $\begingroup$ 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. $\endgroup$ Aug 29, 2014 at 16:23
  • $\begingroup$ He! Reminded me of this codegolf.stackexchange.com/a/3764/315 $\endgroup$ Aug 29, 2014 at 16:47

1 Answer 1

3
$\begingroup$

For Sound objects like

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

Sound

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]

Sound1

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

Sound3

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

moreSound

$\endgroup$
8
  • 4
    $\begingroup$ Graph[] =!= Plot[] :D $\endgroup$ Aug 29, 2014 at 16:43
  • $\begingroup$ @belisarius I thought he meant graph and not Graph ;-). $\endgroup$
    – Karsten7
    Aug 29, 2014 at 17:12
  • $\begingroup$ I've always wondered how to solve the traveling salesman problem without being able to see... $\endgroup$
    – Guillochon
    Aug 29, 2014 at 17:14
  • $\begingroup$ 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 :) $\endgroup$ Aug 29, 2014 at 17:38
  • $\begingroup$ @FrancoisVanderseypen Thanks! And and also thank you to belisarius for his hint. $\endgroup$
    – Karsten7
    Aug 29, 2014 at 17:48

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.