Phase Response and Group Delay - loudifier/chirplab GitHub Wiki

Phase Response and Group Delay Measurements

Phase Response is a measure of the phase vs frequency of the system under test. Phase is related to the timing of the response signal relative to the stimulus and can be calculated as excess phase, estimating the effective response delay and subtracting it from the phase measurement, or absolute phase, looping the stimulus output back to a second input channel and using the loopback channel as a phase/delay reference.

Group Delay is the derivative of the phase response, measuring the time delay vs frequency of a system relative to its input (or a time reference). The Chirplab Group Delay measurement is derived from an internal Phase Response measurement, so the calculation method is the same, but the parameters are slightly different and they have different outputs, so they are maintained as separate measurements for clarity. Any differences between the two measurements will be noted below and any references to "delay" "group delay" and "phase shift" can be thought of as equivalent.

To measure absolute phase, split the output signal or play the stimulus from a second channel and connect the output back to a second input on your audio interface. Set the Phase Response mode to 'relative' and set the ref_channel to the input channel that the phase reference is sent to

phase loopback setup

Measurement Parameters

mode

  • 'excess': Calculate the effective phase response, estimating and cancelling the total group delay of the response signal
  • 'relative': Use a second input channel as a timing reference to calculate the absolute phase of the response
    • If you do not have a known good timing reference, either an external loopback or a second DUT used for comparison, then the 'excess' mode will produce more meaningful results
    • If the delay between the reference and response signals is very long, the main chirp analysis pre_sweep/post_sweep times may need to be extended to avoid cutting off the beginning or end of the signals
    • The reference signal magnitude does not directly impact the resulting phase response calculation, but a low reference signal level can result in poor SNR and a noisy phase response output
    • Note that internal loopback signals (WASAPI output device, etc.) sometimes compensate for estimated latency, but are not accurate enough to be used as a Phase Response timing

excess_method

Method used to estimate the group delay of the response when mode is 'excess'

  • 'cross_correlation': Chirplab's default cross-correlation response time alignment is used directly without compensating for sub-sample phase shift. This is usually fairly accurate at low frequencies, but the worst-case error of alinging to the nearest whole sample can be significant at high frequencies
  • 'linear_phase': Average group delay is estimated by performing a linear regression of the raw phase response. The regression is calculated using equal-spaced FFT point, which results in weighting high frequency group delay more than low frequency group delay. This works well for most tests, because group delay tends to be lowest at high frequencies. The slope of the linear regression corresponds to the average group delay of the response, which is subtracted from the output phase response. This is usually the best way to visualize the qualitative features of the phase response
  • 'min_delay': Minimum group delay is estimated by taking the 10th percentile of the raw group delay, interpolated over a log frequency scale. This method can be useful in cases of very large phase shifts over the chirp range or noisy phase response, but is susceptible to overestimating the group delay of the response

ref_channel

The input channel to use as the phase reference when mode is 'relative'. In most cases, the input signal to this channel should be an external loopback from the output signal used to drive the Device Under Test. It can also be used as the reference channel when you want to measure the relative phase between two signals. For example, if you want to measure the phase relationship between two microphones in a microphone array you would typically analyze the phase response of the microphone farther from the sound source, with the microphone closest to the sound source as the ref_chanenl

If mode is 'relative' and there is only one input channel or ref_channel is the same as the project input channel, all output points will be -1

unwrap (Phase Response only)

If True Chriplab will attempt to unwrap the phase response. Any discontinuities in the raw phase response greater than 180 degrees are assumed to be "wrapped" around by 360 degrees (corresponding to phase shift of more than one full cycle) due to the angle calculation being bound to ±180 degrees. 360 degrees are added or subtracted from the subsequent phase response points, which can accumulate and unwrap further as frequency increases. In the case of significant phase shift or noise between frequency bins (especially at high frequencies) phase shift between 180 and 360 degrees can be erroneously unwrapped, or phase shift greater than 720 degrees will only unwrap by a single cycle, leading to over or underestimation of the total phase shift

auto_invert (Phase Response only)

If True and if the phase response measured at the lowest chirp stimulus frequency (regardless of Phase Response output frequency range) is within ±90 degrees of ±180 degrees, then 180 degrees is added or subtracted from the measurement output. This can be useful for measurements where you know the results should be non-inverted but the measurement may be inverted (speaker terminals reversed, etc.)

Output Parameters

unit

Output points are specified in this measurement unit. Options are:

  • 'degrees' (Phase Response): One full cycle = 360 degrees
  • 'radians' (Phase Response): One full cycle = 2π radians
  • 'ms' (Group Delay): Delay in milliseconds

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

Phase Response Measurement Calculation

Phase response is the angle of the polar representation of the points of a complex transfer function. This can be derived directly by dividing the spectrum of the response signal by the spectrum of the stimulus signal, but often results in very noisy output, so Chirplab first derives an impulse response of the system and applies a window that reduces harmonic distortion and noise, similar to the process used for a windowed Frequency Response measurement

If the Phase Response mode is 'excess', the internal stimulus signal is used as the reference. If the Phase Response mode is 'relative', the selected ref_channel signal is used as the reference. Significant delay between the reference and response signal result in inaccuracies in the phase response measurement, so the response signal in 'relative' mode is first time-aligned with the reference signal using cross-correlation and the gross offset is added back to the phase response output at the end of the measurement

phase reference alignment

The raw impulse response is calculated as the inverse FFT of the FFT of the response divided by the FFT of the reference

impulse response from signals

Windowing the impulse response has less impact on the accuracy of phase response than it does on frequency response, so a short and tapered window is applied to the impulse response to reject harmonic distortion and as much noise and reverberation as possible

windowed phase response

If unwrap is True, the phase will be stepped through and 360 degrees is added or subtracted from the subsequent points any time there is a discontinuity greater than 180 degrees

phase wrapping

Note that phase unwrapping and re-wrapping may be performed at intermediary stages or at the end of the calculation, depending on the calculation methods and parameter settings used. Phase is shown as unwrapped from this point for clarity

The phase response in the current state is technically accurate, but skewed by the response's total delay relative to the stimulus or reference signal. In 'relative' mode, the gross group delay was previously stored and can be added directly to the phase response output. The phase from bulk delay is the delay time multiplied by the frequency at each point to get the number of cycles, then scaling by degrees or radians. Note that the phase shift from delay is linear with frequency, but appears to decrease exponentially (for delayed response, or increase for time-advanced response) due to plotting frequency on a logarithmic scale

total relative phase

When mode is 'excess', Chirplab's chirp detection uses cross-correlation to align the response chirp to the stimulus signal, which aligns the stimulus and response to the nearest whole sample. The precise sub-sample group delay is unknown, but can be estimated and added to the phase response the same way the gross delay is added to the fine phase response in 'relative' mode.

When excess_mode is 'cross_correlation', the phase response from the initial cross-correlation time alignment is presented as-is without sub-sample group delay compensation

When excess_mode is 'linear_phase', the phase response is calculated using cross-correlation time alignment, then a linear regression is performed for phase as a function of frequency. This is done over the linearly-spaced FFT bins when transforming the impulse response into the frequency domain, which has a net effect of more heavily weighting higher frequencies than lower frequencies

linear phase regression

The slope of the linear phase regression corresponds to the effective mean group delay of the response relative to the cross-correlation-aligned stimulus. The cross-correlation phase measurement is corrected such that it's linear phase regression would be a flat line

linear phase method

When excess_mode is 'min_delay', the phase response is calculated using cross-correlation time alignment, then converted to group delay form by taking the derivative of the the phase

phase to delay

The group delay is interpolated on a logarithmic frequency scale so the frequency points will be proportionally weighted, then the minimum group delay is estimated as the 10th percentile of the log-scaled group delay, which rejects the majority of spurious noise that could skew the estimate

minimum group delay estimate

The cross-correlation phase is then compensated for the minimum group delay the same way as in the 'linear_phase' case

min delay method

All together, for this particular example the different methods for measuring phase from a reference or estimating the phase from different group delays are:

phase response methods

Finally, any real system (speaker and microphone) will have a phase response that is 0 or 180 degrees at DC. If auto_invert is True, the lowest chirp frequency will be checked and if it is within 90 degrees of ±180 degrees then 180 degrees will be added or subtracted from the full phase response to try to align the phase response to 0 degrees. Note that this may erroneously invert data from a system that is expected to have an inverted phase response (speaker connected backwards, 2nd order highpass filter, etc.), or a system that has significant phase shift between DC and the lowest chirp frequency.

automatic phase inversion

Group Delay Measurement Calculation

Group Delay is calculated using an internal instance of a Phase Response measurement. The mode, excess_method, and ref_channels of the Group Delay measurement are used for the Phase Response measurement. The Phase Response measurement's unwrap and auto_invert parameters are set to True and False, respectively, although they don't actually impact the output group delay

To avoid possible issues with unwrapping and discontinuities in the output group delay, the internal Phase Response measurement data is output at the same frequency resolution as the FFT used to calculate phase. The derivative of the phase is taken to get the group delay, which is then output at the points specified by the Group Delay measurement's output parameters

phase to group delay

Just as the different methods of calculating phase show a relative tilt in the response graph, the different methods of calculating group delay show a shifting up or down of the delay

group delay calculation methods