Correcting General Waveforms for Phone Calibration

						  Programming Note # 15
						  Ravi Kochhar
						  Dept. of Physiology
						  Nov. 18, 1997
						  Rev. Level 1.002 (11/25/97)

The need for correction

A "General Waveform", for the purposes of this note, is any waveform that is played back via the General Waveform Buffer (GEWAB) of the Digital Stimulus System (DSS) (ref. #1). Briefly, the DSS has a 1 Megaword (16-bit words) memory which can be loaded with arbitrary general waveforms, which can then be delivered to an acoustic transducer (i.e. phones) at a user selectable playback rate. Examples of general waveforms are noise, speech, synthetic vowels, combination tones etc.

The DSS is capable of playing waveforms with great accuracy, both in amplitude (16 bits, plus 127 dB attenutors settable in 1 dB steps) and time (1 microsec). The output from the DSS, therefore, reproduces the desired general waveform very faithfully. Unfortunately, the earphones are not flat, i.e. they amplify sounds of differing frequencies by different amounts. What the animal hears (the phone output) may differ markedly from what was intended (the phone input).

Fortunately, means exist to largely compensate for this problem. This is done by determining the phone characteristic (calibration) at the start of each experiment, using the acoustic calibration program (NEUCAL, ref. #2). Fig. 1, below, shows the phone calibration curves for a typical earphone. Note that there are two curves, an amplitiude curve and a phase curve, because in general a phone introduces both an amplification and a phase shift, both of which are frequency dependent.

Calibration Curve Example

Click on the figure above to get a larger view.

The purpose of the phone calibration correction is to present to the animal's eardrum the signal exactly as intended, removing any distortions introduced by the earphone.

The Correction Method

In a general sense, the correction method is very simple, and best illustrated by a simple example:

Suppose our general waveform consists of only two frequency components, say at 500 Hz and at 1000 Hz, and suppose we want their amplitudes to be exactly the same, say 40 dB SPL. Suppose further that the earphone attenuates by 10 dB at 500 Hz and by 20 dB at 1000 Hz. To correct for the phone, all we would really need to do is to increase the 500 Hz. amplitude by 10 dB and the 1000 Hz. amplitude by 20 dB, then the phone output would have equal amplitudes for both frequencies (see Fig. 2).

This correction is done in software before the waveform is loaded into the DSS, and is called "correcting for the phone calibration", or "flattening the waveform". Any general waveform can be corrected by extending this general method to include all frequencies, and also including a phase correction.

In our auditory lab, the phone calibration correction is done in one of two places, (a) on the fly during data collection, or (b) using the program GWE. The same algorithm is used in either case. For purposes of illustration, the following description uses the GWE program as an example.

(1) The GWE program (ref. 3) is used for editing general waveforms and for signal processing. It assumes that general waveforms are stored as separate datasets in a datafile. Each datafile can have a variable number of datasets. It is started by type "GWE" at the system $ prompt. It asks the data file name containing the general waveform(s). It next presents a menu of options. Option no. 9 reads "Flatten waveform using phone calibration". When option 9 is selected, the program gives a choice between correcting just one waveform, or a range of datasets (waveforms).

(2) The user is then given a choice of whether to correct for Amplitude alone, Phase alone, or both Phase and Amplitude. In most cases, the option to correct for both Phase and Amplitude should be selected. Next, the program asks for the Dataset ID of the general waveform.

(3) The program next asks for the phone number whose calibration is to be used:

      Using most recent calibration for which DSS (1 or 2) ?

This is because there are typically two earphones in an experiment, one for the left ear and one for the right ear. Each earphone is connected to one DSS. The DSS's are numbered 1 and 2. During the calibration process, the amplitude and phase calibrations are stored in "Calibration Table File" on disc. One calibration is stored for each phone used in the experiment (see ref. 3). It is very important to pick the correct DSS (phone) number.

(4) The program (GWE) next reads in the waveform from disc, and displays the next question:

        5628 points have been read in
      Low-pass Filter Corner Freq (Hz) ?
       (Press  for 20000 Hz)
       (Enter 0 to disable filter)

The optional low-pass filter is available to smooth out problems that arise because calibration at higher frequencies is either not available or the phone may not pass high frequencies very well. The result in such cases can be incorrect correction at those frequencies. By choosing to apply an n-th order filter we filter out any extraneous high frequencies. If the calibration curve looks smooth at high frequencies then one should enter 0 to disable the filter, else enter a frequency that corresponds to a place on the curve before it tails off.

If a non-zero number is entered, the programs asks for the order of the filter:

      Order of Filter (1,2,3... etc.) ?

Enter a reasonable value between 1 and 10. Some trial and error is sometimes needed to determine the best value. This (optional) filter is applied at the very last stage, after the waveform correction has been done.

(5) The program next reads in the calibration table for the selected phone. The calibration table is read from the "Calibration Storage File", or CSF, (ref. 4) and there is a separate table for amplitude and phase (see fig. 1 above). The amplitude table is stored in array SPLC and the phase table in array PHAS.

It is important to note that the GWE program uses the calibration tables stored in the CSF, not in the main data file (EDF). There are two ways that phone calibrations can be saved in the CSF, either by program NEUCAL by selecting the "Save Amplitude Table" and "Save Phase Table" options, or by the program ECAL using option 5 (Transfer calibration from EDF to CSF). The latter option is particularly useful when using an older calibration for correction.

(6) The waveform array (X) is re-sampled to the next higher power of 2 (if the number of points is not already a power of 2).

(7) The general waveform spectrum is computed using the Fast Fourier Transform (FFT) (ref. 5). The amplitudes are coverted to dB and the phase to radians.

(8) The phone calibration is "subtracted" from the general waveform in the frequency domain. If necessary the calibration values are interpolated (using linear interpolation) to the frequency step of the general waveform. If X(J) is the amplitude (in dB) of the general waveform, and X(J+1) is the phase (in radians), then:


where CAL and CPHAS are the (interpolated) amplitude and phase calibrations at that particular frequency. We "add" rather than subtract phase because the calibration program (NEUCAL) stores phase with it's sign reversed.

If the calibration amplitude (CAL) is more than 50 dB down from the peak calibration amplitude (CALMX), then we set CAL to CALMX-50 before the above correction. This is to avoid any large dips in the calibration curve which are not very reliable, and may contaminate the corrected waveform. Fig. 3 below illustrates this "clipping" of the calibratrion.

(9) The DC term is removed from the corrected waveform.

(10) The corrected waveform is converted back to time domain using the inverse FFT routine (ref. 5).

(11) The corrected time domain waveform is re-scaled to peak GEWAB units (plus or minus 32767).

(12) If the waveform was re-sampled earlier (step (6) above) to a power of 2, then it is re-sampled back down to the original number of points.

(13) If a filter was selected in step (4) above, then it is applied at this stage.

(14) Finally, the corrected waveform is saved back into the datafile as a new dataset. The original waveform is not changed.

Does it work ?

As a test, we connected the DSS to an earphone connected to a plastic tube (to simulate an animal's ear canal). The other end of the tube was connected to a 1/2" B & K microphone. This closed system was calibrated using the program NEUCAL. Then, a sharp rectangular click (50 microsecs wide) was played through the earphone both with and without correction for the phone calibration. The results are shown in the following figures:

Figure 4 shows the phone amplitude calibration

Figure 5 shows the output with no correction

Figure 6 shows the output with phone correction

It is clear that there is a dramatic improvement when phone correction is done.

Effect of N'th order filter

To illustrate the effects of applying the N'th order filter to the correction, we repeated the above cases with and without filtering.

The output with phone correction and 6'th order filter

The output with phone correction but no filter

It is apparent that that applying the filter leads to less high frequency ringing. Much of the ringing can be seen to be at approx. 23,000 Hz, which is the location of the sharp notch in the phone calibration. The 6'th order filter was applied with a corner frequency set at 20,000 Hz.


This work was done under the direction of Dr. W.S. Rhode. Supported by a grant from NIH.


(1) "Digital Stimulus System - Version II", R. Olson, D. Yee and W.S. Rhode, June 1985.

(2) "NEUCAL - Acoustic Calibration Program", R.Kochhar, Tech.Report # 4, Dept. of Neurophysiology.

(3) "GWE - General Waveform Editing/Time Series Analysis", R.Kochhar, Tech.Report # 15, Dept. of Neurophysiology.

(4) "CSF - Calibration Storage File", R.Kochhar, Programming Note # 16, Dept. of Physiology, Nov. 1997.

(5) "NUMLIB - Numerical Routines Library", R.Kochhar, Technical Report # 8, Dept. of Neurophysiology, Mar. 1988.

Back to Top

If you have questions about, or suggestions for, this document, please send e-mail to
Return to Documentation Page
Return to Basement Page
This page last modified on : Nov. 25, 1997