Get a spectrum of frequencies from WAV/RIFF using linux command line

zsedc picture zsedc · Feb 13, 2014 · Viewed 12.6k times · Source

How to generate file including spectrum of frequencies of wav/riff sound file? I would like to use linux command line.

I know the cool sox function to generate png spectrograms

sox sound.wav -n spectrogram

But I do not need visual representation of the spectrum of frequencies. I just want to get spectrum of frequencies in data file so I can work on them. I believe that there must be an option using sox. Sox need to generate that data before plotting it. How to get this?

Not sure, maybe the second solution is exporting wav file into the dat file. Each sample from dat file is a measure of the position of the membrane at a moment in time. So this is not spectrum of frequencies.

sox sound.wav file.dat

How to convert those membrane positions into spectrum i need?

Thanks.

Answer

mti2935 picture mti2935 · Feb 13, 2014

What you are looking for is called a Fourier Transform, or Fast Fourier Transform (FFT). The FFT is a mathematical algorithm that transforms time domain samples (i.e. the membrane positions, as you put it, at points in time), which are contained in a .wav file - into frequency components. If you Google FFT, you will find much more information, including source code that you can compile and reuse in Linux. See How do I plot the spectrum of a wav file using FFT? for a good start.