# Frequency Response Analysis

This chapter discusses frequency-response analysis of digital filters. The frequency response is a complex function which yields the gain and phase-shift as a function of frequency. Useful variants such as phase delay and group delay are defined, and examples and applications are considered.

## Frequency Response

The frequency response of an LTI filter may be defined as the spectrum of the output signal divided by the spectrum of the input signal. In this section, we show that the frequency response of any LTI filter is given by its transfer function evaluated on the unit circle, i.e., . We then show that this is the same result we got using sine-wave analysis in Chapter 1.

Beginning with Eq.(6.4), we have

where X(z) is the z transform of the filter input signal , is the z transform of the output signal , and is the filter transfer function.

A basic property of the z transform is that, over the unit circle , we find the spectrum [84].8.1To show this, we set in the definition of the z transform, Eq.(6.1), to obtain

which may be recognized as the definition of the bilateral discrete time Fourier transform (DTFT) when is normalized to 1 [59,84]. When is causal, this definition reduces to the usual (unilateral) DTFT definition:

 DTFT (8.1)

Applying this relation to gives

 (8.2)

Thus, the spectrum of the filter output is just the input spectrum times the spectrum of the impulse response . We have therefore shown the following:
This immediately implies the following:
We can express this mathematically by writing

By Eq.(7.2), the frequency response specifies the gain and phase shift applied by the filter at each frequency. Since , , and are constants, the frequency response is only a function of radian frequency . Since is real, the frequency response may be considered a complex-valued function of a real variable. The response at frequency Hz, for example, is , where is the sampling period in seconds. It might be more convenient to define new functions such as and write simply instead of having to write so often, but doing so would add a lot of new functions to an already notation-rich scenario. Furthermore, writing makes explicit the connection between the transfer function and the frequency response.

Notice that defining the frequency response as a function of places the frequency axis'' on the unit circle in the complex plane, since . As a result, adding multiples of the sampling frequency to corresponds to traversing whole cycles around the unit circle, since

whenever is an integer. Since every discrete-time spectrum repeats in frequency with a period'' equal to the sampling rate, we may restrict to one traversal of the unit circle; a typical choice is [ ]. For convenience, is often allowed.

We have seen that the spectrum is a particular slice through the transfer function. It is also possible to go the other way and generalize the spectrum (defined only over the unit circle) to the entire plane by means of analytic continuationD.2). Since analytic continuation is unique (for all filters encountered in practice), we get the same result going either direction.

Because every complex number can be represented as a magnitude and angle , viz., , the frequency response may be decomposed into two real-valued functions, the amplitude response and the phase response . Formally, we may define them as follows:

## Amplitude Response

Definition. The amplitude response of an LTI filter is defined as the magnitude (or modulus) of the (complex) filter frequency response , i.e.,

Another common name for the amplitude response is magnitude frequency response.

The real-valued amplitude response specifies the amplitude gain that the filter provides at each frequency .

## Phase Response

Definition. The phase response of an LTI filter is defined as the phase (or angle) of the frequency response :

The phase response is often referred to as the phase'' of the filter. For real filters (filters with real coefficients), the filter phase can be defined unambiguously as the phase of its frequency response.

The real-valued phase response gives the phase shift in radians that each input component sinusoid will undergo.

## Polar Form of the Frequency Response

When the complex-valued frequency response is expressed in polar form, the amplitude response and phase response explicitly appear:

 (8.3)

Writing the basic frequency response description

(from Eq.(7.2)) in polar form gives

which implies

This states explicitly that the output magnitude spectrum equals the input magnitude spectrum times the filter amplitude response, and the output phase equals the input phase plus the filter phase at each frequency .

Equation (7.3) gives the frequency response in polar form. For completeness, recall the transformations between polar and rectangular forms (i.e., for converting real and imaginary parts to magnitude and angle, and vice versa):

Going the other way from polar to rectangular (using Euler's formula),

Application of these formulas to some basic example filters are carried out in Appendix B. Some useful trig identities are summarized in Appendix A. A matlab listing for computing the frequency response of any IIR filter is given in §7.5.1 below.

#### Separating the Transfer Function Numerator and Denominator

From Eq.(6.5) we have that the transfer function of a recursive filter is a ratio of polynomials in :

 (8.4)

where

By elementary properties of complex numbers, we have

These relations can be used to simplify calculations by hand, allowing the numerator and denominator of the transfer function to be handled separately.

## Frequency Response as a Ratio of DTFTs

From Eq.(6.5), we have , so that the frequency response is

and

where

and the DTFT is as defined in Eq.(7.1).

From the above relations, we may express the frequency response of any IIR filter as a ratio of two finite DTFTs:

 (8.5)

This expression provides a convenient basis for the computation of an IIR frequency response in software, as we pursue further in the next section.

### Frequency Response in Matlab

In practice, we usually work with a sampled frequency axis. That is, instead of evaluating the transfer function at to obtain the frequency response , where is continuous radian frequency, we compute instead

where is the desired number of spectral samples around the unit circle in the plane. From Eq.(7.5) we have that this is the same thing as the sampled DTFT of divided by the sampled DTFT of :

The uniformly sampled DTFT has its own name: the discrete Fourier transform (DFT) [84]. Thus, we can write

where

DFT

and , where denotes the sampling rate in Hz.

To avoid undersampling , we must have , and to avoid undersampling , we must have . In general, will be undersampled (when ), because it is the quotient of over . This means, for example, that computing the impulse response from the sampled frequency response will be time aliased in general. I.e.,

IDFT

will be time-aliased in the IIR case. In other words, an infinitely long impulse response cannot be Fourier transformed using a finite-length DFT, and this corresponds to not being able to sample the frequency response of an IIR filter without some loss of information. In practice, we simply choose sufficiently large so that the sampled frequency response is accurate enough for our needs. A conservative practical rule of thumb when analyzing stable digital filters is to choose , where denotes the maximum pole magnitude. This choice provides more than 60 dB of decay in the impulse response over a duration of samples, which is the time-aliasing block size. (The time to decay 60 dB, or '', is a little less than time constants [84], and the time-constant of decay for a single pole at radius can be approximated by samples, when is close to 1, as derived in §8.6.)

As is well known, when the DFT length is a power of 2, e.g., , the DFT can be computed extremely efficiently using the Fast Fourier Transform (FFT). Figure 7.1 gives an example matlab script for computing the frequency response of an IIR digital filter using two FFTs. The Matlab function freqz also uses this method when possible (e.g., when is a power of 2).

 function [H,w] = myfreqz(B,A,N,whole,fs) %MYFREQZ Frequency response of IIR filter B(z)/A(z). % N = number of uniform frequency-samples desired % H = returned frequency-response samples (length N) % w = frequency axis for H (length N) in radians/sec % Compatible with simple usages of FREQZ in Matlab. % FREQZ(B,A,N,whole) uses N points around the whole % unit circle, where 'whole' is any nonzero value. % If whole=0, points go from theta=0 to pi*(N-1)/N. % FREQZ(B,A,N,whole,fs) sets the assumed sampling % rate to fs Hz instead of the default value of 1. % If there are no output arguments, the amplitude and % phase responses are displayed. Poles cannot be % on the unit circle. A = A(:).'; na = length(A); % normalize to row vectors B = B(:).'; nb = length(B); if nargin < 3, N = 1024; end if nargin < 4, if isreal(b) & isreal(a), whole=0; else whole=1; end; end if nargin < 5, fs = 1; end Nf = 2*N; if whole, Nf = N; end w = (2*pi*fs*(0:Nf-1)/Nf)'; H = fft([B zeros(1,Nf-nb)]) ./ fft([A zeros(1,Nf-na)]); if whole==0, w = w(1:N); H = H(1:N); end if nargout==0 % Display frequency response if fs==1, flab = 'Frequency (cyles/sample)'; else, flab = 'Frequency (Hz)'; end subplot(2,1,1); % In octave, labels go before plot: plot([0:N-1]*fs/N,20*log10(abs(H)),'-k'); grid('on'); xlabel(flab'); ylabel('Magnitude (dB)'); subplot(2,1,2); plot([0:N-1]*fs/N,angle(H),'-k'); grid('on'); xlabel(flab); ylabel('Phase'); end

### Example LPF Frequency Response Using freqz

Figure 7.2 lists a short matlab program illustrating usage of freqz in Octave (as found in the octave-forge package). The same code should also run in Matlab, provided the Signal Processing Toolbox is available. The lines of code not pertaining to plots are the following:

[B,A] = ellip(4,1,20,0.5); % Design lowpass filter B(z)/A(z)
[H,w] = freqz(B,A);        % Compute frequency response H(w)
The filter example is a recursive fourth-order elliptic function lowpass filter cutting off at half the Nyquist limit ('' in the fourth argument to ellip). The maximum passband ripple8.2is 1 dB (2nd argument), and the maximum stopband ripple is 20 dB (3rd arg). The sampled frequency response is returned in the H array, and the specific radian frequency samples corresponding to H are returned in the w (omega'') array. An immediate plot can be obtained in either Matlab or Octave by simply typing
plot(w,abs(H));
plot(w,angle(H));
However, the example of Fig.7.2 uses more detailed compatibility'' functions listed in Appendix J. In particular, the freqplot utility is a simple compatibility wrapper for plot with label and title support (see §J.2 for Octave and Matlab version listings), and saveplot is a trivial compatibility wrapper for the print function, which saves the current plot to a disk file (§J.3). The saved freqplot plots are shown in Fig.7.3(a) and Fig.7.3(b).8.3

 [B,A] = ellip(4,1,20,0.5); % Design the lowpass filter [H,w] = freqz(B,A); % Compute its frequency response % Plot the frequency response H(w): % figure(1); freqplot(w,abs(H),'-k','Amplitude Response',... 'Frequency (rad/sample)', 'Gain'); saveplot('../eps/freqzdemo1.eps'); figure(2); freqplot(w,angle(H),'-k','Phase Response',... 'Frequency (rad/sample)', 'Phase (rad)'); saveplot('../eps/freqzdemo2.eps'); % Plot frequency response in a "multiplot" like Matlab uses: % figure(3); plotfr(H,w/(2*pi)); if exist('OCTAVE_VERSION') disp('Cannot save multiplots to disk in Octave') else saveplot('../eps/freqzdemo3.eps'); end

 Amplitude Response Phase Response

## Phase and Group Delay

In the previous sections we looked at the two most important frequency-domain representations for LTI digital filters, the transfer function and the frequency response:

We looked further at the polar form of the frequency response , thereby breaking it down into the amplitude response times the phase-response term .

In the next two sections we look at two alternative forms of the phase response: phase delay and group delay. After considering some examples and special cases, poles and zeros of the transfer function are discussed in the next chapter.

### Phase Delay

The phase response of an LTI filter gives the radian phase shift added to the phase of each sinusoidal component of the input signal. It is often more intuitive to consider instead the phase delay, defined as

The phase delay gives the time delay in seconds experienced by each sinusoidal component of the input signal. For example, in the simplest lowpass filter of Chapter 1, we found that the phase response was , which corresponds to a phase delay , or one-half sample. Thus, we can say precisely that the filter exhibits half a sample of time delay at every frequency. (Regarding the discussion in §1.3.2, it is now obvious how we should define the filter phase response at frequencies 0 and .)

From a sinewave-analysis point of view, if the input to a filter with frequency response is

then the output is

and it can be clearly seen in this form that the phase delay expresses the phase response as a time delay in seconds.

### Phase Unwrapping

In working with phase delay, it is often necessary to unwrap'' the phase response . Phase unwrapping ensures that all appropriate multiples of have been included in . We defined simply as the complex angle of the frequency response , and this is not sufficient for obtaining a phase response which can be converted to true time delay. If multiples of are discarded, as is done in the definition of complex angle, the phase delay is modified by multiples of the sinusoidal period. Since LTI filter analysis is based on sinusoids without beginning or end, one cannot in principle distinguish between true'' phase delay and a phase delay with discarded sinusoidal periods when looking at a sinusoidal output at any given frequency. Nevertheless, it is often useful to define the filter phase response as a continuous function of frequency with the property that or (for real filters). This specifies how to unwrap the phase response at all frequencies where the amplitude response is finite and nonzero. When the amplitude response goes to zero or infinity at some frequency, we can try to take a limit from below and above that frequency.

Matlab and Octave have a function called unwrap() which implements a numerical algorithm for phase unwrapping. Figures 7.6.2 and 7.6.2 show the effect of the unwrap function on the phase response of the example elliptic lowpass filter of §7.5.2, modified to contract the zeros from the unit circle to a circle of radius in the plane:

[B,A] = ellip(4,1,20,0.5); % design lowpass filter
B = B .* (0.95).^[1:length(B)]; % contract zeros by 0.95
[H,w] = freqz(B,A);      % frequency response
theta = angle(H);        % phase response
thetauw = unwrap(theta); % unwrapped phase response
In Fig.7.6.2, the phase-response minimum has wrapped around'' to the top of the plot. In Fig.7.6.2, the phase response is continuous. We have contracted the zeros away from the unit circle in this example, because the phase response really does switch discontinuously by radians when frequency passes through a point where the phases crosses zero along the unit circle (see Fig.7.3(b)). The unwrap function need not modify these discontinuities, but it is free to add or subtract any integer multiple of in order to obtain the best looking'' discontinuity. Typically, for best results, such discontinuities should alternate between and , making the phase response resemble a distorted square wave'', as in Fig.7.3(b). A more precise example appears in Fig.10.2.

 Phase Response Unwrapped Response

### Group Delay

A more commonly encountered representation of filter phase response is called the group delay, defined by

For linear phase responses, i.e., for some constant , the group delay and the phase delay are identical, and each may be interpreted as time delay (equal to samples when ). If the phase response is nonlinear, then the relative phases of the sinusoidal signal components are generally altered by the filter. A nonlinear phase response normally causes a smearing'' of attack transients such as in percussive sounds. Another term for this type of phase distortion is phase dispersion. This can be seen below in §7.6.5.

An example of a linear phase response is that of the simplest lowpass filter, . Thus, both the phase delay and the group delay of the simplest lowpass filter are equal to half a sample at every frequency.

For any reasonably smooth phase function, the group delay may be interpreted as the time delay of the amplitude envelope of a sinusoid at frequency [63]. The bandwidth of the amplitude envelope in this interpretation must be restricted to a frequency interval over which the phase response is approximately linear. We derive this result in the next subsection.

Thus, the name group delay'' for refers to the fact that it specifies the delay experienced by a narrow-band group'' of sinusoidal components which have frequencies within a narrow frequency interval about . The width of this interval is limited to that over which is approximately constant.

#### Derivation of Group Delay as Modulation Delay

Suppose we write a narrowband signal centered at frequency as

 (8.6)

where is defined as the carrier frequency (in radians per sample), and is some lowpass'' amplitude modulation signal. The modulation can be complex-valued to represent either phase or amplitude modulation or both. By lowpass,'' we mean that the spectrum of is concentrated near dc, i.e.,

for some . The modulation bandwidth is thus bounded by .

Using the above frequency-domain expansion of , can be written as

which we may view as a scaled superposition of sinusoidal components of the form

with near 0. Let us now pass the frequency component through an LTI filter having frequency response

to get

 (8.7)

Assuming the phase response is approximately linear over the narrow frequency interval , we can write

where is the filter group delay at . Making this substitution in Eq.(7.7) gives

where we also used the definition of phase delay, , in the last step. In this expression we can already see that the carrier sinusoid is delayed by the phase delay, while the amplitude-envelope frequency-component is delayed by the group delay. Integrating over to recombine the sinusoidal components (i.e., using a Fourier superposition integral for ) gives

where denotes a zero-phase filtering of the amplitude envelope by . We see that the amplitude modulation is delayed by while the carrier wave is delayed by .

We have shown that, for narrowband signals expressed as in Eq.(7.6) as a modulation envelope times a sinusoidal carrier, the carrier wave is delayed by the filter phase delay, while the modulation is delayed by the filter group delay, provided that the filter phase response is approximately linear over the narrowband frequency interval.

### Group Delay Examples in Matlab

Figure 7.6 compares the group delay responses for a number of classic lowpass filters, including the example of Fig.7.2. The matlab code is listed in Fig.7.5. See, e.g., Parks and Burrus [64] for a discussion of Butterworth, Chebyshev, and Elliptic Function digital filter design. See also §I.2 for details on the Butterworth case. The various types may be summarized as follows:

• Butterworth filters are maximally flat in middle of the passband.
• Chebyshev Type I filters are equiripple'' in the passband and Butterworth'' in the stopband.
• Chebyshev Type II filters are Butterworth'' in the passband and equiripple in the stopband.
• Elliptic function filters are equiripple in both the passband and stopband.
Here, equiripple'' means equal ripple''; that is, the error oscillates with equal peak magnitudes across the band. An equiripple error characterizes optimality in the Chebyshev sense [64,78].

As Fig.7.6.4 indicates, and as is well known, the Butterworth filter has the flattest group delay curve (and most gentle transition from passband to stopband) for the four types compared. The elliptic function filter has the largest amount of delay distortion'' near the cut-off frequency (passband edge frequency). Fundamentally, the more abrupt the transition from passband to stopband, the greater the delay-distortion across that transition, for any minimum-phase filter. (Minimum-phase filters are introduced in Chapter 11.) The delay-distortion can be compensated by delay equalization, i.e., adding delay at other frequencies in order approach an overall constant group delay versus frequency. Delay equalization is typically carried out using an allpass filter (defined in §B.2) in series with the filter to be delay-equalized [1].

 [Bb,Ab] = butter(4,0.5); % order 4, cutoff at 0.5 * pi Hb=freqz(Bb,Ab); Db=grpdelay(Bb,Ab); [Bc1,Ac1] = cheby1(4,1,0.5); % 1 dB passband ripple Hc1=freqz(Bc1,Ac1); Dc1=grpdelay(Bc1,Ac1); [Bc2,Ac2] = cheby2(4,20,0.5); % 20 dB stopband attenuation Hc2=freqz(Bc2,Ac2); Dc2=grpdelay(Bc2,Ac2); [Be,Ae] = ellip(4,1,20,0.5); % like cheby1 + cheby2 He=freqz(Be,Ae); [De,w]=grpdelay(Be,Ae); figure(1); plot(w,abs([Hb,Hc1,Hc2,He])); grid('on'); xlabel('Frequency (rad/sample)'); ylabel('Gain'); legend('butter','cheby1','cheby2','ellip'); saveplot('../eps/grpdelaydemo1.eps'); figure(2); plot(w,[Db,Dc1,Dc2,De]); grid('on'); xlabel('Frequency (rad/sample)'); ylabel('Delay (samples)'); legend('butter','cheby1','cheby2','ellip'); saveplot('../eps/grpdelaydemo2.eps');

 Group Delays

### Vocoder Analysis

The definitions of phase delay and group delay apply quite naturally to the analysis of the vocoder (voice coder'') [21,26,54,76]. The vocoder provides a bank of bandpass filters which decompose the input signal into narrow spectral slices.'' This is the analysis step. For synthesis (often called additive synthesis), a bank of sinusoidal oscillators is provided, having amplitude and frequency control inputs. The oscillator frequencies are tuned to the filter center frequencies, and the amplitude controls are driven by the amplitude envelopes measured in the filter-bank analysis. (Typically, some data reduction or envelope modification has taken place in the amplitude envelope set.) With these oscillators, the band slices are independently regenerated and summed together to resynthesize the signal.

Suppose we excite only channel of the vocoder with the input signal

where is the center frequency of the channel in radians per second, is the sampling interval in seconds, and the bandwidth of is smaller than the channel bandwidth. We may regard this input signal as an amplitude modulated sinusoid. The component can be called the carrier wave, while is the amplitude envelope.

If the phase of each channel filter is linear in frequency within the passband (or at least across the width of the spectrum of ), and if each channel filter has a flat amplitude response in its passband, then the filter output will be, by the analysis of the previous section,

 (8.8)

where is the phase delay of the channel filter at frequency , and is the group delay at that frequency. Thus, in vocoder analysis for additive synthesis, the phase delay of the analysis filter bank gives the time delay experienced by the oscillator carrier waves, while the group delay of the analysis filter bank gives the time delay imposed on the estimated oscillator amplitude-envelope functions.

Note that a nonlinear phase response generally results in , and for . As a result, the dispersive nature of additive synthesis reconstruction in this case can be seen in Eq.(7.8).

### Numerical Computation of Group Delay

The definition of group delay,

does not give an immediately useful recipe for computing group delay numerically. In this section, we describe the theory of operation behind the matlab function for group-delay computation given in §J.8.

A more useful form of the group delay arises from the logarithmic derivative of the frequency response. Expressing the frequency response in polar form as

yields the following logarithmic decomposition of magnitude and phase:

Thus, the real part of the logarithm of the frequency response equals the log amplitude response, while the imaginary part equals the phase response.

Since differentiation is linear, the logarithmic derivative becomes

where and denote the derivatives of and , respectively, with respect to . We may therefore express the group delay as

imim

Consider first the FIR case in which , with

 (8.9)

In this case, the derivative is simply

where denotes  ramped'', i.e., the th coefficient of the polynomial is , for . In matlab, we may compute Br from B via the following statement:

Br = B .* [0:M]; % Compute ramped B polynomial
The group delay of an FIR filter can now be written as

imimre

In matlab, the group delay, in samples, can be computed simply as
D = real(fft(Br) ./ fft(B))
where the fft, of course, approximates the Discrete Time Fourier Transform (DTFT). Such sampling of the frequency axis by this approximation is information-preserving whenever the number of samples (FFT length) exceeds the polynomial order . The ratio of sampled DTFTs, however, is undersampled, in general. In fact, we may have at some frequencies (zeros on the unit circle''). The grpdelay matlab utility in §J.8 watches out for division by zero, and simply sets the group delay to zero at such frequencies. Note that the true group delay approaches infinite magnitude as either a zero or pole approaches the unit circle.

Finally, when there are both poles and zeros, we have

where is given in Eq.(7.9), and

 (8.10)

Straightforward differentiation yields

 (8.11)

and this can be implemented analogous to the FIR case discussed above. However, a faster algorithm (usually) results from converting the IIR case to the FIR case:

 (8.12)

where

may be called the flip-conjugate'' or Hermitian conjugate'' of the polynomial .8.4In matlab, the C polynomial is given by
C = conv(B,fliplr(conj(A)));
It is straightforward to show (Problem 11) that

The phase of the IIR filter is therefore

and the group delay computation thus reduces to the FIR case:

re

This method is implemented in §J.8.

## Frequency Response Analysis Problems

Next Section:
Pole-Zero Analysis
Previous Section:
Transfer Function Analysis