Wednesday, 22 June 2016

Bat call broadcasts.

For training purposes, I've been using the Pettersson D1000x to play back previously recorded bat calls so that participants at workshops can then listen through heterodyne, frequency division or even time expansion to practise using bat detectors. The calls have been broadcast through an L400 loudspeaker which is pretty good even up to 100 kHz.

Being a 'belt and braces' sort of person, I was always worried that if the technology decided not to work one day, then the whole workshop would be wasted, so I looked around for another way of broadcasting high frequency .wav files. I initially tried LabVIEW, but the problem with the version I had was that it wouldn't accept .wav files with high sampling rates, so you had to read in the file in other ways, which was cumbersome. In the end, I found a quick and easy way in Matlab.

You will need the Matlab base package, and the data acquisition toolbox. You will also need a compatible data acquisition card capable of Digital to Analog output of about 500 kHz. I use a National Instruments USB-6251 box. You will need a suitable high frequency loudspeaker and some original files to broadcast. If they are time expanded you will just need to put in a little function to raise the sample rate back up 10x (be careful that your card can handle arbitrary sample rates though as 44.1 kHz becomes 441 kHz which some cards may not be able to deal with).

The Matlab code is really ridiculously simple, and easy to adapt to different cards or situations.

% Matlab .m script to select a .wav file and then play that file back

% through a USB D/A Device - in this case a NI USB-6251.


% GUI commends to select a file and get the path to that file

[filename pathname] = uigetfile({'*.wav'},'File Selector');

fullpathname = strcat (pathname, filename);

% Use audioread to open the file identified from Pathname: Note that will

% not open batsound .wav format files. Use Batsound to open them and then

% save as standard .wav files first.

[Wave_File, Fs] = audioread(fullpathname);

% Fs is the sample rate it gets from the .wav file. Report it.


% Plot an oscillogram of the signal to check it has loaded properly.


% Plots the sonogram though the frequencies aren't right. Currently commented

% out as it takes ages for long files. The y axis option swaps the x and y

% axes to put frequency up the side.

% spectrogram(Wave_File,128,120,128,1e3,'yaxis')

% Reports which devices are found - ni: National Instruments USB-6251 (BNC)

% (Device ID: 'Dev1')

devices = daq.getDevices

% ni is the device label, creates a session.

s = daq.createSession('ni')

% Set the sampling rate to that of the loaded .wav file

s.Rate = Fs

% Add a D/A Output channel. Dev1 is the device and ao0 is the analog output

% channel: 1 2 channels ('ao0','ao1')


% Loop ten times. Change if you want more or less.

for lp = 1:10

% queue the data to the D/A device


% Start the output of the data and return command to matlab when done



One day I might get around to writing a nice GUI for it, but this works very well as it is.

No comments:

Post a Comment