Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# 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(Hd,n)
[gd,f] = grpdelay(b,a,n,fs)
[gd,w] = grpdelay(b,a,n,'whole')
[gd,f] = grpdelay(b,a,n,'whole', fs)
gd = grpdelay(b,a,w)
gd = grpdelay(b,a,f,fs)
grpdelay(...)

## Description

The group delay 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

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

[gd,w] = grpdelay(b,a) returns the group delay, 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

The filter's group delay 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 of the discrete-time filter evaluated at n equally-spaced points on the unit circle in the interval [0,π). n is a positive integer.

[gd,w] = grpdelay(sos,n) returns the group delay 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 i-th row of the sos matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].

[gd,w] = grpdelay(Hd,n) returns the group delay for the dfilt filter object, Hd, or the array of dfilt filter objects. If Hd is an array of dfilt objects, each column of gd is the group delay of the corresponding dfilt object.

[gd,f] = grpdelay(b,a,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 is evaluated. f contains n points between 0 and fs/2.

[gd,w] = grpdelay(b,a,n,'whole') and

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

gd = grpdelay(b,a,w) and

gd = grpdelay(b,a,f,fs) return the group delay 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(...) plots the group delay versus frequency. The plot is displayed in fvtool. If the input is the numerator and denominator coefficients, a second order sections matrix, or a single dfilt object, the group delay of the single filter is displayed. If the input is an array of dfilt objects, the group delays of all filters in the array are displayed.

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

Plot the group delay of Butterworth filter b(z)/a(z):

```[b,a] = butter(6,0.2);
grpdelay(b,a,128)
```

The same example using a dfilt object and displaying the result in the Filter Visualization Tool (fvtool) is

```[b,a] = butter(6,0.2);
Hd=dfilt.df1(b,a);
grpdelay(Hd,128)
```

Plot both the group and phase delays of a system on the same graph:

```[b,a] = butter(6,0.2);
gd = grpdelay(b,a,512);
gd(1) = [];       % Avoid NaNs
[h,w] = freqz(b,a,512); h(1) = []; w(1) = [];
pd = -unwrap(angle(h))./w;
plot(w,gd,w,pd,':')
axis([0 pi min(gd) max(gd)]);
legend('Group Delay','Phase Delay');
```