5
$\begingroup$

I want to split signal in multiple bands and process each band. Number of bands is not yet determined, but it would be more then 6 and less then 11 (depending on the collected results)

As demonstrative example, let's consider common linear PCM sound data file input.wav and I want to calculate RMS per each band. Using a tool such as SoX I can extract only one band at a time (1000-2000 Hz in this example):

sox input.wav output.wav gain -n sinc 1000-2000

and pipe output to processor and extract wanted feature.

What I would appreciate is solution to process all previously determined bands in one pass.

It doesn't need to be a ready made program like SoX, but preferably Matlab/Octave script or Python/SciPy/NumPy and similar approach.

$\endgroup$
  • $\begingroup$ What have you tried? Is this a signal processing or a MATLAB programming question? $\endgroup$ – Phonon Dec 23 '11 at 14:38
  • $\begingroup$ I didn't try anything as I'm not aware of such approach. I know only to do single band (bandpass) in one pass, both programatically and using external tool like in above example. I'm asking for advice how to do multiband in one pass, (without repeating processing for every band) with any kind or tool or general programming environment. It doesn't have to be Matlab $\endgroup$ – zetah Dec 23 '11 at 15:30
  • $\begingroup$ You won't get anyone to do work for you, and especially write code for you on Stack Exchange. People here will guide you, not nothing else. $\endgroup$ – Phonon Dec 23 '11 at 15:54
  • $\begingroup$ That's what I'm looking for - pointer in right direction as I'm not aware of such possibility. Don't need code, I'll do it myself, just be kind and tell in your words if you know how $\endgroup$ – zetah Dec 24 '11 at 3:11
2
$\begingroup$

The most direct way to make these calculations is to design a set of filters to your specifications, then read the data out of the WAV files and run it through the filters. In Python/SciPy, you can use Python's wave module to read and write WAV files, SciPy's firwin to design a windowed sinc filter like SoX's sinc effect, and SciPy's lfilter to apply each filter. You will have to design each filter separately and call lfilter for each filter.

A simple way to approximate the energy in several bands is to first calculate the Discrete Fourier Transform (DFT) of consecutive frames, and sum up the energy in the bins corresponding to your bands of interest. The DFT approximates a signal with a sum of harmonically related sinusoids. The advantage of this technique is that it's easy to sum up several arbitrarily spaced bands. A big disadvantage is you have to apply a window to control spectral leakage. This makes the energy calculation an approximation. You can use NumPy's rfft function to calculate the Fourier Transforms.

If your bank of filters is related, for instance all the same bandwidth, or centered at harmonically or logarithmically related frequencies, there are some clever techniques that fall under the concept of filterbanks. This is more specialized, and I don't know of much pre-packaged code you could use.

$\endgroup$
  • $\begingroup$ Thanks for your nice answer. Perhaps question title is too general. I was thinking about how multiband filters (like multiband compressor i.e) are designed, although I just needed RMS calculation for my example. Do you think that also MPL can be used by simply appling x,y = PSD(...) and then get RMS for arbitrary band by sqrt(sum(custom_y_range)/len(custom_y_range))? $\endgroup$ – zetah Dec 26 '11 at 15:02
  • $\begingroup$ 1 - I don't know of anything off-the-shelf in Python for multiband filterbanks, although it's certainly simple to design a bunch of adjacent filters. 2 - Yes, but like I said it will be an approximate answer due to the window effects. $\endgroup$ – mtrw Dec 27 '11 at 4:04
0
$\begingroup$

Sox now supports multiband companding (compression/expanding).

From the man page for v14.4.1:

   mcompand "attack1,decay1{,attack2,decay2}
          [soft-knee-dB:]in-dB1[,out-dB1]{,in-dB2,out-dB2}
          [gain [initial-volume-dB [delay]]]" {crossover-freq[k] "attack1,..."}

          The multi-band compander is similar to the single-band compander but the audio is first divided into  bands  using  Linkwitz-Riley  cross-over
          filters and a separately specifiable compander run on each band.  See the compand effect for the definition of its parameters.  Compand param‐
          eters are specified between double quotes and the crossover frequency for that band is given by crossover-freq; these can be repeated to  cre‐
          ate multiple bands.

          For example, the following (one long) command shows how multi-band companding is typically used in FM radio:
             play track1.wav gain -3 sinc 8000- 29 100 mcompand \
               "0.005,0.1 -47,-40,-34,-34,-17,-33" 100 \
               "0.003,0.05 -47,-40,-34,-34,-17,-33" 400 \
               "0.000625,0.0125 -47,-40,-34,-34,-15,-33" 1600 \
               "0.0001,0.025 -47,-40,-34,-34,-31,-31,-0,-30" 6400 \
               "0,0.025 -38,-31,-28,-28,-0,-25" \
               gain 15 highpass 22 highpass 22 sinc -n 255 -b 16 -17500 \
               gain 9 lowpass -1 17801
          The  audio  file  is played with a simulated FM radio sound (or broadcast signal condition if the lowpass filter at the end is skipped).  Note
          that the pipeline is set up with US-style 75us pre-emphasis.

          See also compand for a single-band companding effect.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.