# grpdelay

Average filter delay (group delay)

## Syntax

[gd,w] = grpdelay(b,a) [gd,w] = grpdelay(b,a,n)[gd,w] = grpdelay(sos,n)[gd,w] = grpdelay(d,n)[gd,f] = grpdelay(...,n,fs)[gd,w] = grpdelay(...,n,'whole')[gd,f] = grpdelay(...,n,'whole',fs)gd = grpdelay(...,w)gd = grpdelay(...,f,fs)grpdelay(...)

## Description

[gd,w] = grpdelay(b,a)  returns the group delay response, gd, of the discrete-time filter specified by the input vectors, b and a. The input vectors are the coefficients for the numerator, b, and denominator, a, polynomials in z-1. The Z-transform of the discrete-time filter is

$H\left(z\right)=\frac{B\left(z\right)}{A\left(z\right)}=\frac{\sum _{l=0}^{N-1}b\left(n+1\right){z}^{-l}}{\sum _{l=0}^{M-1}a\left(l+1\right){z}^{-l}},$

The filter's group delay response is evaluated at 512 equally spaced points in the interval [0,π) on the unit circle. The evaluation points on the unit circle are returned in w.

[gd,w] = grpdelay(b,a,n) returns the group delay response of the discrete-time filter evaluated at n equally spaced points on the unit circle in the interval [0,π). n is a positive integer. For best results, set n to a value greater than the filter order.

[gd,w] = grpdelay(sos,n) returns the group delay response for the second-order sections matrix, sos. sos is a K-by-6 matrix, where the number of sections, K, must be greater than or equal to 2. If the number of sections is less than 2, grpdelay considers the input to be the numerator vector, b. Each row of sos corresponds to the coefficients of a second-order (biquad) filter. The ith row of the sos matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].

[gd,w] = grpdelay(d,n) returns the group delay response for the digital filter, d. Use designfilt to generate d based on frequency-response specifications.

[gd,f] = grpdelay(...,n,fs) specifies a positive sampling frequency fs in hertz. It returns a length-n vector, f, containing the frequency points in hertz at which the group delay response is evaluated. f contains n points between 0 and fs/2.

[gd,w] = grpdelay(...,n,'whole') and [gd,f] = grpdelay(...,n,'whole',fs) use n points around the whole unit circle (from 0 to 2π, or from 0 to fs).

gd = grpdelay(...,w) and gd = grpdelay(...,f,fs) return the group delay response evaluated at the angular frequencies in w (in radians/sample) or in f (in cycles/unit time), respectively, where fs is the sampling frequency. w and f are vectors with at least two elements.

grpdelay(...) with no output arguments plots the group delay response versus frequency.

grpdelay works for both real and complex filters.

 Note:   If the input to grpdelay is single precision, the group delay is calculated using single-precision arithmetic. The output, gd, is single precision.

## Examples

collapse all

### Group Delay of a Butterworth Filter

Design a Butterworth filter of order 6 with normalized 3-dB frequency rad/sample. Use grpdelay to display the group delay.

[z,p,k] = butter(6,0.2); sos = zp2sos(z,p,k); grpdelay(sos,128) 

Plot both the group delay and the phase delay of the system on the same figure.

gd = grpdelay(sos,512); [h,w] = freqz(sos,512); pd = -unwrap(angle(h))./w; plot(w/pi,gd,w/pi,pd), grid xlabel 'Normalized Frequency (\times\pi rad/sample)' ylabel 'Group and phase delays' legend('Group delay','Phase delay') 

### Group Delay Response of a Butterworth digitalFilter

Use designfilt to design a sixth-order Butterworth Filter with normalized 3-dB frequency rad/sample. Display its group delay response.

d = designfilt('lowpassiir','FilterOrder',6, ... 'HalfPowerFrequency',0.2,'DesignMethod','butter'); grpdelay(d) 

expand all

### Group Delay

The group delay response of a filter is a measure of the average delay of the filter as a function of frequency. It is the negative first derivative of the phase response of the filter. If the frequency response of a filter is H(e), then the group delay is

${\tau }_{g}\left(\omega \right)=-\frac{d\theta \left(\omega \right)}{d\omega }$

where θ(ω) is the phase, or argument, of H(e).

### Algorithms

grpdelay multiplies the filter coefficients by a unit ramp. After Fourier transformation, this process corresponds to differentiation.