# Fourier Transform on a Sound

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

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.

• It's true that there is no way to get SampledSoundList directly from MIDI, but here is a workaround. Apr 28, 2016 at 10:22
• 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). :) Nov 30, 2020 at 4:52

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