Why does "sox stat -freq" give me different data multiple times?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The left hand column then repeats about 20 times, from 0 to about 22000. The right hand column changes in each repetition. Now, I thought that this command would give me the frequencies on the left, and the respective decibel levels on the right, but I don't know why I'm getting different data 20 times.
I'm trying to determine the peaks in frequency of the sound file. Is this the right way to do this?
When you transform from the time domain to the frequency domain, you have to sample a number of points in the time domain in order to represent the signal in the frequency domain. Rather than sample the entire file (which would give only a single frequency spectrum), sox samples groups of data points (4096 samples) and gives a spectrum, then repeats this for the length of the file. This enables you to use the data to show the frequency spectrum as it changes over time. For example, if your file was sampled at 44100Hz, then you will see a frequency spectrum for each tenth second interval.
If you actually want the spectrum of the entire file, then you may want to average these individual power spectra together.
Do you have any suggestions for how to average these power spectra together? I've tried using grep, and have been able to separate the the lines with a particular frequency, but I can't figure out how to average the power spectra, as they're on the same line, just separated by a space. I think I need sed, or something similar, but I don't know enough to use it properly.
If you just want to look at a particular frequency, you could just use awk to do the additions, for example:
Code:
sox 1.wav -n stat -freq |& grep '^0\.0' | awk '{s+=$2; ++c} END {print s/c}'
If you want to average the whole set of 2048 frequencies, then you may have to write something a bit more extensive in your language of choice, for example:
Code:
sox 1.wav -n stat -freq |& head -n -15 | \
perl -lne 'split; @sum[$i++%2048] += $_[1]; END { $i/=2048; foreach (@sum) {print $_/$i} }'
Also keep in mind that this analysis using sox assumes a single channel audio source.
You could also consider using audacity, which can analyze spectra and export these, if you don't need to automate the process.
Last edited by neonsignal; 02-17-2012 at 03:33 PM.
Reason: forgot to escape the full stop!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.