Analyze: Usage

△ Index ▼ Usage ▷ Examples ▷ Parameters ▷ Calibration ▷ File formats ▷ How it works
▾ Overview ▾ Software ▾ Hardware ▾ Scripts

Overview

This program analyzes incoming PCM data on the fly and passes the results to files. The C++ source code is available and should be portable to other platforms at reasonable effort. The open source library FFTW version 3.x is utilized for fast operation. Analyze is optimized to use sound devices for the A/D and D/A conversion.

Use cases

Software setup

Software setupAnalyze is just the core application without any platform dependent stuff.

The recording and the playback of the PCM stream as well as some buffering, to handle real time operation, must be provided with other platform specific tools like arecord/aplay (Linux) or playrec (OS/2). AFAIK nothing simple like that is available for Windows - sorry guys, so I do not recommend that OS for this purpose.

It is absolutely essential to use the same sound device for input and output. Analyze makes heavy use of the very high time correlation of input and output samples when the A/D and D/A converters are controlled by the same crystal oscillator for the sampling frequency. If different devices are used results of higher frequencies will derate after less than one second.

The graphic output is also not part of Analyze. I recommend Gnuplot but any other application that can deal with ASCII files will do the job as well.

See the example scripts for suggestions for the software setup including parameter files for Analyze.

Sampling rate and sample format

In general it is a good advice to use the maximum native sample rate supported by your sound device. Only for audio only you might prefer 48 kHz even if you have an HD audio device. This will save some computing power and reduce the risk of sample drops. You definitely must avoid sample rate conversions.

Independent of your hardware I recommend 16 bits per sample. Using more usually adds no value. But it might make things worse because some sound devices do not perform well when choosing the maximum bit depth at the maximum sample rate.

PulseAudio

Although the entire process will work with PulseAudio in principle I recommend not to use it. The chance to get unexpected resampling artifacts or stray sounds from other applications is significantly higher with PulseAudio. You can simply bypass PulseAudio by choosing the appropriate sound device for arecord and aplay. Young might need to terminate the PulseAudio daemon by pulseaudio -k before to get the device unlocked.

External hardware setup

While the software setup is always basically the same the hardware varies with the desired measurements.

Channel map:

input
channel
two port
measurement
impedance
measurement
L(t) response signal
voltage U(t)
R(t) reference signal
current I(t)

Impedance measurement - LCR meter

For high precision impedance measurements you need 4 wire connections and high impedance differential amplifiers. And to drive higher current you need an additional amplifier. The latter can be almost any audio amplifier, but the differential probes need some electronics. Two INA105 with an TL074 as impedance converter at its inputs will do the job.

Depending on the impedance to measure the reference resistor might be chosen from the range 100 mΩ to 50 kΩ roughly.

I furthermore recommend a 3 point calibration with a known impedance. This will also compensate for the properties of the reference resistor with respect to its frequency response, e.g. because of parasitic inductance.
If you do so you will be able to measure really low and high impedance from about 1 mΩ up to 10 MΩ, including the reactance of capacitors and inductors.

Poor man's impedance measurement

There is a very simple variant that requires only one external reference resistor. Of course, you get only restricted accuracy, but the most limiting factor is the maximum output current of the sound device. While old sound cards often had a small built-in amplifier new ones sometimes do not even have enough power to drive a 32 Ω headphone.
You may overcome this limit by using an audio amplifier. But be careful, not all amplifiers have one terminal of the speaker output connected to ground. And even if so it might introduce some stray current from its power supply.

Reasonable values for Rref are only between 33 Ω and 3,3 kΩ roughly.

In this configuration the voltage over the reference resistor cannot be sampled directly. Only the sum with the voltage over the test impedance is available. You need to tell Analyze by the diff option to use differential sampling mode. This causes the current (denominator) to be calculated by

I = (Right - Left) / Rref

I recommend to use 3 point calibration even in this simple configuration. Although you cannot use a 4 wire connection it will significantly improve the accuracy.

wire diagram for two port network 2 port measurement - transfer function

If you two-port network can directly deal with the line level of the sound device, e.g. an audio equalizer, it can be directly connected like shown in the image. The only special thing needed is an Y-cable to get the reference feedback.

Loudspeaker response

To the left is the typical setup for speaker measurements. The properties of the audio amplifier (and sound device) have no relevant influence on the result. The microphone and its corresponding amplifier is the critical part. There are calibration services available for these combinations at reasonable charge.

You cannot use USB microphones calibrated by the manufacturer. They use a different crystal oscillator for the sampling rate than the sound card used for playback of the reference. This results in slightly different speed of playback and recording destroying the phase coherence used by Analyze to get high precision results. At least this is untested.

You should chose a sweep mode to reduce systematic errors due to harmonic distortion, intermodulation or non minimum phase responses.

Of course, there are more things to respect to get a reasonable speaker measurement, first of all some kind of anechoic location. But this is by far beyond the scope of this document.
If your intention is to characterize the room and the speakers together for doing digital room correction, things are easier.

Linear amplifier

If you trust your amplifier to be linear or you want to compensate for its properties you can use a more simple setup. A sufficiently linear amplifier must satisfy the following properties:

Helper Scripts

In the sample folder there are a bunch of scripts to set up scenarios as mentioned above. They are all intended to be used with Ubuntu Linux, but you may use them as blueprint for other platforms too. See examples for some results created by these sample files.

The sample files assume that your sound card can deal with 192 kHz sampling rate (HD audio) which is quite common for modern PCs. If not you should adjust the sampling rate to 48 kHz and set the maximum frequency in fft.cfg to 20 kHz.

All file names mentioned here are in the same directory. The analyze executable have to be build before the scrips can be used. The Analyze executable is expected in the parent folder. If you have chosen a different build directory you should put a symbolic link there.

Configuration files for Analyze

The *.cfg files are configuration files for Analyze. They are only slightly platform dependent. The files have an inheritance hierarchy by including the parent configuration file.

Shell scripts

The *.sh scripts are intended for Bash.

measure.sh - invoke one of the above configuration files

This script is intended for all measurements except for calibration. Use ./measure @filename.cfg with the appropriate configuration file name to start a measurement.

You can also pass additional command line parameters to Analyze. In fact @filename.cfg is also just an include directive for Analyze.

calibrate2.sh, calibrate3.sh - perform 2 point or 3 point calibration

Just start the script and follow the instructions. The result is shown with Gnuplot after completion. Whenever possible you should prefer the 3 point calibration.
After the calibration completed you probably want to copy the result file zero.dat to a more descriptive file name matching your current setup. These files are also included by the impedance measurement configuration files.

calibrate2-verify.sh, calibrate3-verify.sh - verify calibration

After calibration a second verification step is recommended. It performs the same calibration but with the previously perfromed calibration result in zero.dat applied. The result is now written to zeroD.dat. At this point you should see a significantly improved result.

setup_alsa_server.sh - start recording and playback pipeline - do not invoke directly!

This script creates a record.pipe and play.pipe fifo and tries to start arecord and aplay in different terminals to feed and consume the pipe data respectively. The script is automatically invoked by Analyze if you use the sample configuration files above.

The setup also passes the content of the file mixer.in to amixer. You should use this to set defined mixer levels.

You likely need to adjust this file matching your sound hardware.

Gnuplot macros

The macro files are named *.gp and used by the above scripts to visualize data. Feel free to adjust the according your needs.

setup.gp - global Gnuplot options

This file is invoked by all sample scripts. Put general Gnuplot settings here.

viewlcr.*.gp - view impedance measurement result

This is invoked by the fft-*.cfg files to show the results of the data.dat file.

zero.gp - view the result of a calibration

Show the amplitude of the diagonal and non-diagonal calibration matrix elements, the phase of the diagonal matrix elements and the absolute frequency dependent amplitude of voltage at both input channels.

zero3.gp - view the result of a 3 point calibration

This is the same as zero.gp but with slightly different scale for 3 point calibration.

zeroD.gp - view the result of a calibration verification

Same as zero.gp, but for the file zeroD.dat.

viewH.gp - view stereo loudspeaker response

This will show the speaker level and the group delay of a two channel measurement.