Scale Factors for Wave Files Recorded with Measurement Recorder from Analog Inputs

Created on 2010-11-24 07:35:00

The APx500 Measurement Recorder has a great feature that allows you to record raw audio data to a .wav file during a measurement. If this feature is used when the Input Connector is set to one of the analog inputs, the APx software converts the measured data from analog units (e.g., Vrms or dBV) to digital units (FS or dBFS). This is necessary because .wav files are digital by definition.

Typically, if you want to analyze a .wav file recorded from the analog output of a device, you would prefer to have the results in analog units like V or dBV, not in digital units. Fortunately, this is handled quite nicely in the APx500 software. When Measurement Recorder is used to record a .wav file from an analog source, APx500 embeds a scale factor in the metadata of the audio file. Then, if you use the APx .wav file analysis feature with the input set to File (Analog Units), the analyzer reads the scale factor and automatically scales the data to the correct analog units.

To illustrate how this scaling works, we recorded a series of five .wav files in loopback mode with the analyzer set to a different input range for each file. (The APx585 used in this case has input ranges of 0.32, 1.0, 3.2, 10.0, and 32 Vrms.)  For all five recordings, the generator was set to generate a 1 kHz sine wave at -20.0 dBV (100 mVrms). Figure 1 shows the RMS Level results from analyzing these five .wav files with the Input Connector set to File (Analog Units). As shown, for all five files, the analyzer returns the correctly scaled result of -20 dBV.

Figure 1.  Recorded .wav files analyzed with Input = File (Analog Units)

In Figure 2, notice what happens when the same five files are analyzed with the Input Connector set to File (Digital Units). This represents the actual level of the signal in each .wav file, since the digital to analog scale factor has not been applied. Note that the level results are spaced 10 dB apart. This corresponds with the 10 dB ranging steps of the analog input section.

Figure 2.  Recorded .wav files analyzed with Input = File (Digital Units)

Accessing the Scale Factors Embedded in the Wav File Metadata

From the example above, it’s clear that the simplest way to ensure correct scaling of analog data recorded to .wav files is to use the wave file analysis feature with the input set to File (Analog Units). But what if you are analyzing the .wav file with some external program like Matlab, and you want to get the scaling right?

Wave files use a type of structured file storage known as the Resource Interchange File Format (RIFF), in which data is divided into tagged “chunks”. The APx500 scaling metadata is embedded into a chunk that is tagged with the label “APx5”. Per the RIFF specification, the 4 bytes following the tag are used to specify the size of the data in the chunk. The Matlab function shown below can be used to extract the digital to analog scale factors embedded by APx500 in a recorded .wav file. This function reads the entire .wav file into a string, then searches for the tag “APx5” in the string, to determine the location of the chunk in the file. It then reads the chunk size and uses it to determine the number of channels in the .wav file. Next, it reads the scale factor for each channel.

function ScaleFactor = GetAPxWavScale(FileName);   %   % Gets the scale factor(s) embedded in a .wav file recorded with an   % APx500 audio analyzer. To scale the data from digital FS units to     % analog Vrms units use the equation:   %   % Vrms = FS * Scale Factor / sqrt(2)   %   % Open the .wav file and read the entire file into a string   fid = fopen(FileName);   string = fread(fid);   % find the index of the 'APx5' chunk   ChunkIndex = findstr(string','APx5');   fseek(fid,ChunkIndex +3,'bof');   ChunkSize = fread(fid,1,'int32');   NumChannels = ChunkSize / 8;   for i = 1 : NumChannels;   ScaleFactor(i) = fread(fid,1,'double');   end;fclose(fid);

Once the scale factors have been extracted, the level of the signal in analog units can be determined from the level in digital units by an appropriate formula. For example, for units of dBFS and dBV, the conversion is:

The table below shows the scale factor recovered from each of the five recorded .wav files, the measured levels in dBV and dBFS, and the levels in dBV calculated from the digital levels and the embedded scale factors.






Analog Input Range used to record file

Level Measured with Input = File (Analog Units) (dBV)

Level Measured with Input = File (Digital Units) (dBFS)

Scale Factor from file metadata

Calculated Level from columns
3 & 4