4
$\begingroup$

I don't really know much above Fourier Transform , or how it's used in Mathematica but I want to know how I can find out, out of which Sin-waves a (static) sound is made of.

So for example I take "G" played by a Violin

Sound[SoundNote["G", 1, "Violin"]]

Because this isn't a pure tone, I want to know, which frequencies are present in which "strength".

My Questions:

How do I get this information?

How do I plot that? (I think it's called "Frequency-Domain")

How do I plot all the involved frequencies together?

I know, this may be simple for some people, but I have neither much know-how in Mathematica, nor do I know how to use Fourier Transform at all.

Hope you can help me, nxt191 aka Marc

$\endgroup$

3 Answers 3

6
$\begingroup$

Unfortunately I don't think that Mathematica really knows anything about the frequency content of SoundNote objects. They are not audio files (recorded in the time domain), but more like MIDI objects. (In fact I think they're 'sonified' by sending them as MIDI events to the OS.)

You can, however, do a fourier transform on an audio file. Either import your own with Import, or use one of the example sounds:

sound = ExampleData[{"Sound", "ViolinScale"}]

We can extract the list of samples from the single SampledSoundList inside this Sound object:

samples = sound[[1, 1, 1]];

We can also extract the sample rate:

sampleRate = sound[[1, 2]];

From here we can compute the FFT and plot:

fft = Fourier[samples];
ListLogPlot[Abs[fft]^2, PlotRange -> All, 
 DataRange -> {0, (1 - 1/Length[samples]) sampleRate}]

There is a lot of other analysis you can do, but that should get you started.

$\endgroup$
2
  • $\begingroup$ It's true that there is no way to get SampledSoundList directly from MIDI, but here is a workaround. $\endgroup$
    – Dan Oak
    Commented Apr 28, 2016 at 10:22
  • 1
    $\begingroup$ Five years later, this question has some activity, and I think it's worth noting that in the current version of Mathematica, AudioData does the trick: AudioData[Sound[SoundNote["G", 1, "Violin"]]] gives two lists of amplitudes (one for each audio channel). :) $\endgroup$
    – thorimur
    Commented Nov 30, 2020 at 4:52
4
$\begingroup$

This is easy to do now with Mathematica's Audio support introduced in v11.0 in 2016 - though note Spectrogram was available in 2012 v9.0:

au = Audio[Sound[SoundNote["G", 1, "Violin"]]];
Spectrogram[au]

(* ... or if you want an array ... *)
spectrogramData = SpectrogramArray[au];

spectrogram

$\endgroup$
1
$\begingroup$

Another option is to use the Periodogram function:

sound = ExampleData[{"Sound", "ViolinScale"}];
Periodogram[sound,
 Frame -> True,
 Axes -> None,
 BaseStyle -> {14, FontFamily -> "Helvetica", FontColor -> Black},
 FrameStyle -> Directive[Black, 14], 
 FrameLabel -> {"Freq (Hz)", "dB"}]

Periodogram Plot

$\endgroup$

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.