Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
02-04-2012, 11:16 AM
|
#1
|
Member
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67
Rep:
|
Why does "sox stat -freq" give me different data multiple times?
When I run this (with 1.wav being my sound file):
Code:
sox 1.wav -n stat -freq
I get this:
Code:
0.000000 0.231731
10.766602 2.418857
21.533203 11.277147
32.299805 4.486618
43.066406 7.143557
53.833008 0.893461
64.599609 3.215172
75.366211 0.481062
86.132812 0.767702
96.899414 1.322751
107.666016 0.363204
118.432617 0.219829
...
...
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?
|
|
|
02-04-2012, 09:12 PM
|
#2
|
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
|
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.
|
|
|
02-05-2012, 07:24 AM
|
#3
|
Member
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67
Original Poster
Rep:
|
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.
Thanks!
|
|
|
02-05-2012, 08:51 AM
|
#4
|
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
|
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!
|
|
|
02-17-2012, 11:09 AM
|
#5
|
Member
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67
Original Poster
Rep:
|
Sorry for the very late reply, but I was able to use this perfectly.
Code:
sox 1.wav -n stat -freq |& grep '^0.0' | awk '{s+=$2; ++c} END {print s/c}
I just wrote a simple bash script that looped it for all the files I needed, and for all the frequencies. Thanks a lot!
---------- Post added 02-17-12 at 12:09 PM ----------
Sorry for the very late reply, but I was able to use this perfectly.
Code:
sox 1.wav -n stat -freq |& grep '^0.0' | awk '{s+=$2; ++c} END {print s/c}
I just wrote a simple bash script that looped it for all the files I needed, and for all the frequencies. Thanks a lot!
|
|
|
06-09-2016, 08:09 AM
|
#6
|
LQ Newbie
Registered: Jun 2016
Posts: 7
Rep:
|
How to get the frequency spectrum
Hi,
I have a wav file with sample rate 48kHz.
In that file I kept a sine tone with 1kHz frequency.
I want to check these using sox or any other utility that was available in the linux.
I used sox file.wav -n stat -freq but I got lots of data which I dont know how to analyze.
Can anyone help me in this
|
|
|
All times are GMT -5. The time now is 02:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|