Residual Distortion - loudifier/chirplab GitHub Wiki

Residual Distortion Measurement

The Residual Distortion measurement constructs an idealized version of the chirp response signal and measures the residual signal left over after subtracting the idealized response from the full response signal. This process can be used to measure THD+N (compared to Harmonic Distortion, which can only measure THD), or triggered/sympathetic, impulsive, and other types of "Rub and Buzz" distortions.

The Residual Distortion process and output is very roughly equivalent to Klippel's Rub and Buzz measurement. Where Klippel (presumably) uses Thiele-Small parameters (and possibly large signal nonlinear models) to simulate speaker output from an arbitrary stimulus, Chirplab uses an extension of the "Farina method" to window out the main impulse and a selected number of harmonic impulses from the raw derived impulse response and convolves it with the stimulus signal to generate an idealized response that consists only of the fundamental and low order harmonic distortion.

THD+N

  • Analysis mode: residual RMS
  • RMS time: set appropriately for desired output resolution
  • Model transfer function up to: 1st harmonic (only modeling the fundamental response)

total distortion comparison

Klippel-style "Rub and Buzz"

  • Analysis mode: residual peak for "peak ratio" output, crest factor for "crest factor" output
  • RMS time: adjust depending on measurement needs. 0.33 octaves is a good starting point point to measure impulsive spikes and artifacts against a 1/3 octave smoothed RMS signal
  • Model transfer function up to: ~10th harmonic. May take some experimentation to determine where Rub and Buzz artefacts show up, typical speaker nonlinearities tend to be conenctrated in 2nd, 3rd, and 5th harmonics, sometimes extending above 7th harmonic

Measurement Parameters

mode

Determines the method used to measure the residual signal level after subtracting the idealized signal from the raw response signal

  • 'rms': The RMS level of the residual signal, calculated over the time period set by rms_unit and rms_time
  • 'peak': The maximum of the absolute residual signal level in each frequency interval around the output frequency points set by the output parameters
  • 'crestfactor': The 'peak' residual signal level relative to the 'rms' residual signal level, which can help to highlight impulsive distortion artifacts

rms_time and rms_unit

When mode is 'rms' or 'crestfactor', rms_time and rms_unit are used to set the length of time over which the residual signal's RMS level is calculated

When rms_unit is 'seconds', the RMS period in samples is rms_time multiplied by the chirp analysis sample rate. When rms_unit is 'octaves', the RMS period in seconds is calculated as rms_time divided by the chirp sweep rate, and then the RMS period is converted to samples for the actual RMS calculation.

For example, for rms_unit='octaves' and rms_time=0.083 (1/12 octave), with a 1s 20-20kHz chirp and 48kHz sample rate, the sweep rate is 9.97 octaves/second, for an RMS time of 8.3ms, which rounds to 400 samples at 48kHz.

max_harmonic

The highest harmonic that is included in the windowed impulse response used to generate the idealized response signal. If set to 1, only the time around t0 is included in the impulse response, so the idealized response represents the response of the fundamental chirp frequency. If set to 2 or greater, the idealized impulse response is constructed from the t0/fundamental impulse and a section of the raw impulse response windowed out around the harmonic arrival time for each harmonic from H2 through max_harmonic

Output Parameters

unit

Output points are specified in this measurement unit. Two different sets of output units can be specified, depending on the mode parameter.

When mode is 'rms' or 'peak':

  • 'dB': Decibel level of the residual distortion relative to the fundamental frequency response. The fundamental frequency response is calculated using the Frequency Response measurement with default parameter values and the same output frequency points as the Residual Distortion measurement
  • '%': Level of the residual distortion relative to the fundamental frequency response, expressed as a percentage. If the residual distortion level is greater than the fundamental frequency response level, the percentage can exceed 100%
  • '% (IEC method)': The residual distortion level divided by the sum of the residual distortion and the fundamental frequency response, expressed as a percentage. As distortion level increases and fundamental response falls the percentage will approach but never exceed 100%
  • 'dBFS' or 'FS': Absolute Full Scale digital level not referenced to the fundamental or total signal level, using the "true RMS" definition of full scale. For a residual distortion signal that is typically primarily sinusoidal, a measured RMS level of 0.707FS or -3.01dBFS corresponds to a sine wave that peaks at a digital level of 1.0FS
  • 'Pa' or 'dBSPL': Absolute acoustic Sound Pressure Level not referenced to the fundamental or total signal level, in Pascals or decibels converted from digital measurement using the project's FS_per_Pa calibration parameter. dBSPL level is defined as the dB level relative to 20uPa, so 20uPa = 0dBSPL and 1Pa = 94dBSPL.
  • 'V' or 'dBV': Absolute electrical Voltage not referenced to the fundamental or total signal level, converted from digital measurement using the project's FS_per_V calibration parameter

When mode is 'crestfactor':

  • 'dB': Decibel level of the 'peak' residual distortion relative to the 'rms' residual distortion
  • '%': Level of the 'peak' residual distortion relative to the 'rms' residual distortion level, expressed as a percentage. When the 'peak' level is greater than the 'rms' level, the percentage can exceed 100%

min_freq

The lowest output frequency point in Hz

min_auto

If True the min_freq parameter is ignored and the lowest output frequency point is set to the chirp start_freq

max_freq

The highest output frequency point in Hz

max_auto

If True the max_freq parameter is ignored and the highest output frequency point is set to the chirp stop_freq

spacing

  • 'linear': Output points are spaced evenly for num_points between min_freq and max_freq
  • 'log': Output points are spaced proportionally for num_points between min_freq and max_freq
  • 'octave': Output points are spaced proportionally between min_freq and max_freq. The total number of frequency point is num_points multiplied by the number of octaves between min_freq and max_freq rounded to the nearest whole number (total number of points = round(num_points * Log2(max_freq/min_freq)) )

num_points

If spacing is 'linear' or 'log', the total number of output frequency points between min_freq and max_freq. If spacing is 'octave', the number of points per octave used to calculate the total number of output frequency points between min_freq and max_freq

round_points

If True the array of output frequency points will be rounded to the nearest whole Hz. In cases where low frequiencies are rounded to the same whole Hz, duplicate points will be removed, resulting in fewer total output points than specified by num_points

Measurement Calculation

The Harmonic Distortion measurement is calculated by first generating an array that contains the instantaneous chirp frequency at every sample in the chirp response input signal. Due to the chirp analysis pre/post-sweep range extending before and after the chirp signal, the array of chirp frequencies starts below the chirp start frequency and extends higher than the chirp stop frequency, corresponding to what the actual start and stop frequencies would be at the beginning of the pre-sweep and end of the post-sweep, based on the chirp sweep rate.

instantaneous chirp frequency

Next, the raw impulse response is calculated by dividing the spectrum of the chirp response signal by the spectrum of the internal stimulus signal.

spectrums to impulse response

After calculating the raw impulse response a window or set of windows is generated based on the max_harmonic parameter. A window is generated around the t0 point of the impulse response (corresponding to the first harmonic/fundamental) based on the lowest chirp frequency, similar to the adaptive Frequency Response measurement process.

fundamental impulse response window

If max_harmonic is 2 or greater, additional windows are generated at the arrival time of each harmonic from 2 through max_harmonic using the same process as in the Harmonic Distortion measurement.

harmonic impulse response windows

The fundamental and harmonic windows are added together and applied to the raw impulse response, then the windowed impulse response is convolved with the internal chirp stimulus to generate an idealized version of the response signal.

Due to the windowing applied to the impulse response, the idealized response includes the fundamental chirp response and harmonic distortion artifacts up through max_harmonic, without any higher order harmonic distortion and very little of the system noise or non-harmonic distortion artifacts.

idealized response

The residual distortion signal is calculated by subtracting the idealized response from the raw response signal. The 'rms' residual distortion level is calculated by squaring each sample of the residual distortion signal, then applying a moving average filter with the length determined by the rms_unit and rms_time parameters, taking the square root of each sample, then mapping the instantaneous chirp frequency to the RMS signal and interpolating it at the output frequency points. The 'peak' residual distortion level is calculated by mapping the instantaneous chirp frequencies to the residual distortion signal and finding the maximum absolute value in each interval around the output frequency points.

residual distortion levels

When mode is 'rms' or 'peak' and a relative output unit is selected ('dB', '%', or '% (IEC method)'), the output is calculated relative to the fundamental frequency response. When mode is 'crestfactor', the output is the 'peak' residual distortion level relative to the 'peak' distortion level.

residual distortion output levels