# How to get DFT from Sound/Audio/Image?

When I'm trying to do Discrete Fourier Transform or just get a ListPlot of values from Sound object, I get error message.. I understand that Fourier command (and ListPlot of course) works only with lists. May be there is some command to extract values from Sound/Audio/Image object so further I could apply DFT?

p.s.: it's interestingly though that similar transforms like Wavelet could be applied directly on image or sound samples...

• Could you make a MWE of what you tried? Jun 7 at 11:07
• I'd like to apply Fourier to an image as easyly as ImagePeriodogram can be applied :) But it's occured to me just now that we can use Sqrt@ImagePeriodogram, so we can get magnitude of Fourier spectrum :) Periodogram is just an modulus of Fourier squared, isn't it?! Jun 14 at 11:16

If you already, have Audio or lists of samples, then the answer is simple. For Sound objects, you should convert them to Audio first.

music = Sound@SoundNote["A", 1.25, "Violin"]

(* Convert it to Audio *)
asaudio = Audio[music];

(* You can call Periodogram directly on audio without needing a list of samples *)
Periodogram[asaudio, ScalingFunctions -> "dB"]

(* ... and spectrogram *)
Spectrogram[asaudio]

(* ... and you get get data from the periodogram / spectrogram directly too *)
periodogramData = PeriodogramArray[asaudio]
spectrogramData = SpectrogramArray[asaudio];

(* You can get the sample rate and the samples like this *)
rate = AudioSampleRate[asaudio];
data = AudioData[asaudio];

(* and do your own DFT (note data can be stereo so I choose the first channel here) *)
channel1 = data[[1]];
four = Fourier[channel1];
powerSpectrumInDecibels = 20 Log10[Abs[four[[1 ;; Length[four]/2]]]];
ListPlot[powerSpectrum]

• Thank u, it's very useful! Especially the use of AudioData in order to extract data (list of values) from Audio object. As far as I understand, we can analogously use ImageData to extract data from an Image. Concerning Fourier command, it's still seems pretty inconvinient and even strange that we cannot apply Fourier directly on a image/Audio, but similar commands like Periodogramm, Spectrogramm, Wavelet can be apllied... I'm telling that because I use another (more automized) ImageJ program. So I'd like to compare Wolfram results and ImageJ ones. Jun 14 at 10:58
• By the way, Spectrogramm/Periodogram can be applied on Sound object as well as on Audio object :) Jun 14 at 11:10
• @shamilkhal I didn't know that. I guess that makes it really easy then. Jun 14 at 14:48