Pages

Thursday, 4 December 2014

PAMGuard Tutorial-Down-sample Files

Once in a while you might want to downsample your data.

Because sometimes, there's just too much.

And your computer gets swamped.

And your hard-drive fills up.

And your processor slows down.

And then you get a headache from screaming at the computer.

And your office mates kick you out.

Then you move into a van, down by the river....



So, recently I've discovered* that PAMGuard has a relatively easy way to "downsample"  or "decimate" acoustic data.

For instance, in my post on Warships, Whales, and Lot and Lots of Duct Tape, the data we collected were recorded at 576 kHz. That means there were over 576,000 bits of data collected every second. In addition to the very real storage problems that can cause, opening high frequency data in Raven will crash the program. Less than ideal.

So, what's an acoustics nerd to do? The solution is or decimate or downsample the data.

One method for decimating data
By decimating the data, we take out a portion of the sampled points. The result is that we now have low(er) frequency data that are a lot easier to work with. This is particularly useful if, say, you are only interested in sounds  on the lower end of the frequency spectrum (such as wind, rain, distant shipping traffic, blue whales, my stomach rumbling etc.etc.).

Preferred method of decimating data. Note that while fewer samples of the signal are taken,
the shape of the pressure (sound) wave is preserved

Decimating data is a relatively simple procedure with one major caveat regarding low-pass filtering. I won't go into that too much now but it's in red, bold font in the tutorial below.  

So, should you find yourself in need of decimating  data I've written a PAMGuard that will show you how. I've chosen PAMGuard as the platform for this procedure because it's free. There are undoubtedly other software packages out there that can do this for you but PAMGuard is a good place to start, again, because it's free. and very powerful.



PAMGuard Downsample Procedure


1. Open PAMGuard and save a new configuration. I've chosen to creatively name this session and PAMGuard settings file as "DownSampleFiles.psf" 


2. You will need to add the following modules:
     Sound Acquisition
     Decimator
     Sound recorder
     FFT (Spectrogram) Engine

3. The module setup should look like this:


4. Now adjust the settings for all your modules starting with the Sound Acquisition 

     Set the Data Source Type to Audio file folder or multiple files and navigate to the files or folders you want to downsample


6. Now the decimator and filter settings. This bit is important.

Set your output sample rate. In this example, the data PAMGuard was reading in was sampled at 576 kHz and I wanted to downsample this to 96kHz. That part seems easy enough.

7. Now go to the Filter Settings in the Decimator window 

FILTERING-PAMGUARD/ACOUSTIC NOVICES PAY CLOSE ATTENTION!!

8. Click the Low Pass Filter Response radio button

Set the Low Pass frequencies to NO MORE THAN HALF of the output frequency you've chosen for the decimator. This is to avoid accidentally aliasing your data. Since our output is 96kHz, our filter will keep (or pass over) everything below 48kHz. 



Aliasing is what happens when you undersample sounds and don't filter. The result is that high frequency signals may be represented in the low-frequency realm. 

Aliased data. The black line is the true sound signal in time and
the red line is what happens if sound is undersampled. Less than ideal. 



9. Next go to the Sound Recorder Settings  and set the Raw data source to Decimator Data. This will feed the downsampled data from steps 7 and 8 to the sound recorder. 

Enable the Buffer and set your file output, here I was saving them for Luke, my adviser so.. I put them in a file called ForLuke.. Original, I know. 


One last tricky part..
Press Play (big red dot) in the PAMGuard console then quickly switch back to the Sound Recorder tab. While PAMGuard is running, switch to the Sound Recorder from Off to Continuous.

Let it do it's thing and, hopefully, you will have a nicely downsampled file ready for further analysis. 



Thanks for reading!









*e.g. I asked one of the brilliant/helpful PAMGuard developers



1 comment:

  1. Hi,
    If you want to skip the last step (where you press start but then switch to the Sound Recorder Module to press 'continuous'), you can instead go to the Sound Recorder's settings dialogue box, and select "Automatically restart recording after PAMGUARD start/stop." This will make it so that the start time of the sounds being recorded are the same time as the start time of your input audio file.
    Cheers,
    Chloe

    ReplyDelete

Comment forum rules.
1. Be accurate
2. Cite your sources
3. Be nice

Comments failing to meet these criteria will be removed