Main Content

grpdelay

Average filter delay (group delay)

Description

[gd,w] = grpdelay(b,a,n)returns then-point group delay response vector,gd, and the corresponding angular frequency vector,w, for the digital filter with transfer function coefficients stored inbanda.

example

[gd,w] = grpdelay(sos,n)returns then-point group delay response corresponding to the second-order sections matrixsos.

example

[gd,w] = grpdelay(d,n)returns then-point group delay response for the digital filterd.

[gd,w] = grpdelay(___,'whole')returns the group delay atnsample points around the entire unit circle.

[gd,f] = grpdelay(___,n,fs)returns the group delay response vectorgdand the corresponding physical frequency vectorffor a digital filter designed to filter signals sampled at a ratefs.

[gd,f] = grpdelay(___,n,'whole',fs)returns the frequency vector atnpoints ranging between 0 andfs.

gd= grpdelay(___,win)returns the group delay response vectorgdevaluated at the normalized frequencies supplied inwin.

example

gd= grpdelay(___,fin,fs)returns the group delay response vectorgdevaluated at the physical frequencies supplied infin.

example

grpdelay(___)with no output arguments plots the group delay response of the filter.

Examples

collapse all

Design a Butterworth filter of order 6 with normalized 3-dB frequency 0 . 2 π rad/sample. Usegrpdelayto display the group delay.

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

Figure contains an axes object. The axes object contains an object of type line.

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')

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Group delay, Phase delay.

Usedesignfiltto design a sixth-order Butterworth Filter with normalized 3-dB frequency 0 . 2 π rad/sample. Display its group delay response.

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

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay contains an object of type line.

Design an 88th-order FIR filter of arbitrary magnitude response. The filter has two passbands and two stopbands. The lower-frequency passband has twice the gain of the higher-frequency passband. Specify a sample rate of 200 Hz. Visualize the magnitude response and the phase response of the filter from 10 Hz to 78 Hz.

fs = 200; d = designfilt('arbmagfir',...'FilterOrder',88,...'NumBands',4,...'BandFrequencies1',[0 20],...'BandFrequencies2',[25 40],...'BandFrequencies3',[45 65],...'BandFrequencies4',[70 100],...'BandAmplitudes1',[2 2],...'BandAmplitudes2',[0 0],...'BandAmplitudes3',[1 1],...'BandAmplitudes4',[0 0],...'SampleRate',fs); freqz(d,10:1/fs:78,fs)

数字滤波器的可视化工具——级响应nse (dB) and Phase Response contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (dB) and Phase Response contains an object of type line.

Compute and display the group delay response of the filter over the same frequency range. Verify that it is one-half of the filter order.

filtord(d)
ans = 88
grpdelay(d,10:1/fs:78,fs)

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay contains an object of type line.

Input Arguments

collapse all

Transfer function coefficients, specified as vectors. Express the transfer function in terms ofbandaas

H ( e j ω ) = B ( e j ω ) A ( e j ω ) = b(1) + b(2) e j ω + b(3) e j 2 ω + + b(M) e j ( M 1 ) ω a(1) + a(2) e j ω + a(3) e j 2 ω + + a(N) e j ( N 1 ) ω .

Example:b = [1 3 3 1]/6anda = [3 0 1 0]/3specify a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

Data Types:double|single
Complex Number Support:Yes

Number of evaluation points, specified as a positive integer scalar no less than 2. Whennis absent, it defaults to 512. For best results, setnto a value greater than the filter order.

Second-order section coefficients, specified as a matrix.sosis aK-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, the function treats the input as a numerator vector. Each row ofsos对应于coefficients of a second-order (biquad) filter. Theith row ofsoscorresponds to[bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].

Example:s = [2 4 2 6 0 2;3 3 0 6 0 0]specifies a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

Data Types:double|single
Complex Number Support:Yes

Digital filter, specified as adigitalFilterobject. Usedesignfiltto generate a digitalfilter based on frequency-response specifications.

Example:d = designfilt('lowpassiir','FilterOrder',3,'HalfPowerFrequency',0.5)specifies a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

Sample rate, specified as a positive scalar. When the unit of time is seconds,fsis expressed in hertz.

Data Types:double

Angular frequencies, specified as a vector and expressed in rad/sample.winmust have at least two elements, because otherwise the function interprets it asn.win=πcorresponds to the Nyquist frequency.

Frequencies, specified as a vector.finmust have at least two elements, because otherwise the function interprets it asn. When the unit of time is seconds,finis expressed in hertz.

Data Types:double

Output Arguments

collapse all

Group delay response, returned as a vector. If you specifyn, thengdhas lengthn. If you do not specifyn, or specifynas the empty vector, thengdhas length 512.

If the input togrpdelayis single precision, the function computes the group delay using single-precision arithmetic. The outputhis single precision.

Angular frequencies, returned as a vector.whas values ranging from 0 toπ. If you specify'whole'in your input, the values inwrange from 0 to 2π. If you specifyn,whas lengthn. If you do not specifyn, or specifynas the empty vector, thenwhas length 512.

Frequencies, returned as a vector expressed in hertz.fhas values ranging from 0 tofs/2 Hz. If you specify'whole'in your input, the values infrange from 0 tofsHz. If you specifyn,fhas lengthn. If you do not specifyn, or specifynas the empty vector, thenfhas length 512.

More About

collapse all

Group Delay

Thegroup delay responseof 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 isH(e), then the group delay is

τ g ( ω ) = d θ ( ω ) d ω ,

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

Introduced before R2006a