LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 02-04-2012, 11:16 AM   #1
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Rep: Reputation: 3
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?
 
Old 02-04-2012, 09:12 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
Old 02-05-2012, 07:24 AM   #3
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Original Poster
Rep: Reputation: 3
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!
 
Old 02-05-2012, 08:51 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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!
 
Old 02-17-2012, 11:09 AM   #5
schachwizard
Member
 
Registered: Sep 2010
Location: Philly
Distribution: OpenSuse
Posts: 67

Original Poster
Rep: Reputation: 3
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!
 
Old 06-09-2016, 08:09 AM   #6
vvn2023
LQ Newbie
 
Registered: Jun 2016
Posts: 7

Rep: Reputation: Disabled
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
 
  


Reply

Tags
sound, sox


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sox package, Slackware 13.1, fails on sox 1.wav -e stat burbabro Slackware 1 05-04-2011 02:26 AM
How to get the "data type" of an "unknown variable" in "C Language" ? Affair Programming 8 06-20-2009 12:30 PM
Can someone give me the definition of "Kernel Symbol" and "EXPORT_SYMBOL" ?? Raynus Programming 2 08-30-2008 07:19 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
Data transfer online is slow "at times" or "stops at times" Balarabay1 SUSE / openSUSE 14 04-30-2006 10:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration