Speaker calibration tutorial

From Bcontrol
Revision as of 08:29, 5 December 2007 by Lunghaotai (talk | contribs) (New page: Lung-Hao Tai November 2007 This is a record of how I set up my new rig and also serves as a tutorial for people to calibrate their rig and speakers. == Calibration setup == I used NI-...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Lung-Hao Tai November 2007

This is a record of how I set up my new rig and also serves as a tutorial for people to calibrate their rig and speakers.

Calibration setup[edit]

I used NI-9201 for data acquisition. Since I am going to acquire only one channel, 500k samples/sec is enough for acquiring sound frequency up to 100kHz that I used. The microphone/amplifier system is from Bruel&Kjaer. The microphone is type 4939 and the preamp is type 2670. From the back of the amplifier is a BNC out put that I connected to AI-0 and COM (ground) of the screw terminal block on NI-9201. This amplifier has two channels that you can actually calibrating two rigs at the same time.


For Matlab to recognize NI-9201 we need to install the driver NIDAQmx 8.3 from National Instrument. Then you can plug in the NI-9201 to any USB 2.0 port on the windows computer controlling the rig. Position the microphone at the place of rat’s ear and facing the speaker you want to calibrate. Remember to fix the microphone in place so it won’t move during the calibration process.


Calibration Process[edit]

I modified a program Mike Morgan wrote a while back to adapt it to our new system. It’s called CalibrateForTuningCurve.m and can be downloaded here http://zadorlab.cshl.edu/tai/CalibrateForTuningCurve.m It is recommended that you run it on a computer with >1GB of memory. Though it works on computer with less memory, it often gives “out of memory” error when calibrating more than 50 frequencies. Before stating the calibration program, first execute the “mystartup.m” script that sets up the IP address for the RTLinux and sound machine. So the program knows how to connect to sound server to play sounds. Then run the “CalibrateForTuningCurve.m”. When it starts, the program will ask you to locate a text file that contains a list of frequencies that you want to calibrate. The text file is just a column of numbers representing the frequencies. It is recommended that you keep the number of frequency below 100.to avoid “out of memory error”. After loading the text file, a GUI will show up like the figure below. Click on “Parameters” to set up your calibration parameters:


Max. Volume (dB) is the target sound intensity you want to reach at all frequencies being tested by attenuating sound of different frequencies.

Number of tones is the maximum limit of number of frequencies used in the calibration process. If the frequencies loaded from the text file exceeds this limit, then the program will generate tones of the number specified here with frequencies logarithmically spaced between the lowest and the highest frequencies.

Target range (+ - dB) is the satisfactory range of calibration. When the attenuation needed for generating pure tones of max. volume specified in the parameters GUI actually produced tones within max. volume + - target range, the program accepts the attenuation and record it in a mat file (detail about this file will be described later).

Microphone unit (V/Pa) is the conversion unit the program uses to calculate the intensity of the sound recorded. If you are not using the same microphone/amplifier described here, you can try to use a Bruel&Kjaer type 4231 sound level calibrator (94dB and 114dB@1kHz) to determine this conversion unit in your system. Before starting the calibration, make sure you are calibrating the speaker your microphone is pointed to. If not, click the correct speaker button to change it.

To start the calibration process, click on the “unfiltered” button. The program will start sending pure tones to the sound machine at the speaker’s maximum volume and play them while recording the microphone output. In a new figure window, it’ll show the acquired microphone signal and power spectrum density analysis for the tone being analyzed. It’ll calculate the power under corresponding frequency peak for each frequency and summarize it in the original GUI window.


The next step is to calculate a preliminary attenuation factor for each frequency, or the “filter” by clicking on “Compute filter”. Since the volume data we get is by sending max. signal to the speakers, we can only attenuate the signal. But max. signal (usually +-1V) often cause some harmonic distortion to the sound and sometime also reduce the power at the specified frequency. After clicking on “Compute filter”, The filter for desired max volume will appear (blue line) along with piecewise polynomial fit of the filter (green line).

Next, you can click on “Filtered” to evaluate the filter. The program will generate attenuated (filtered) sound and re-analyzed them from the microphone output. If the result of these filtered tone still falls outside of the desired volume range, you can click on “Iterate filter” to automatically iterate this process for up to 8 more times till the desired volume range is achieved. As mentioned before, sometimes even the max signal at some frequency can not give you the desired volume. And this program isn’t smart enough to lower the signal send to the speaker at those particular frequencies to get out of the non-linear regime. My trick is to calibrate first to say 10-20dB below your desired volume and then move the target back to the desired volume in the parameters GUI. This trick usually works for me.


Finally, assume now you have a filter that you like, one that produce sound volume within your desired range across frequencies you requested. The program has already automatically saved a copy of relevant parameters about the filter in a mat file residing in the same directory as the program. It also creates a “result” directory that stores the unfiltered, computed filter and filtered GUI figures as well as all the calibration results for individual tones in enhanced meta file (.emf) format.


You may wonder, why do I need those results for individual tones? If you look closely in the left panel of one of these results, while x axis means frequency and y axis means power, you’ll find there’s power under not just the frequency we want to produce but also several other peaks at higher frequencies. This is mostly due to the harmonic resonance of either the speaker itself or the environment. Usually by setting a lower desired volume can get rid of much of the harmonic distortion due to the speaker itself. If you still see some dubious peak, maybe you need to check out your environmental source of noise.

Using the calibration result to produce sound[edit]

The mat file this program creates is call “ppfilter.mat”. In this mat file there are two variables: CalibrationParams and PP. PP is a structure that has the parameters for the piecewise polynomial curve that fits the filter. To obtain the attenuation needed for producing a pure tone at given frequency, f, use the following expression:

attenuation = ppval(PP, log10(f));

CalibrationParams is another structure variable that lists the frequency used in the calibration and the corresponding attenuation needed to reach what desired volume. This is for people who just want to use linear interpolation to calculate attenuation at frequency not used in the calibration.

Now you should know how to calibrate a speaker and how to use the result of the calibration to produce tone of any frequency at your favorite volume! If you have more question, please ask Lung-Hao Tai or any one who has calibrated a speaker before using this program.