Digital filter analysis—frequency response

Digital filter analysis—frequency response

Amplitude, phase, impulse and step response, phase and group delay, zero and pole analysis.

Analyze the frequency and time domain response of the filter. Visualize filter poles and zeros in the complex plane.

Frequency response

Number field

freqz uses an FFT-based algorithm to calculate the Z-transform frequency response of a digital filter. Specifically, the statement

[h,w] = freqz(b,a,p)

Returns the p point complex frequency response H(ejω) of the digital filter.

In its simplest form, freqz accepts filter coefficient vectors b and a and integers p > (This integer specifies the number of points used to calculate the frequency response). freqz returns the complex frequency response in radians/second in vector h, and the actual frequency points in vector w.

freqz can accept other parameters, such as the sampling frequency or a vector of any number of frequency points. The following example finds the 256-point frequency response of a 12th-order Chebyshev Type I filter. Call freqz to specify the sampling frequency fs to 1000 Hz:

[b,a] = cheby1(12,0.5,200/500);
[h,f] = freqz(b,a,256,1000);

Since the argument list contains the sampling frequencies, freqz returns the vector f containing the values between 0 and fs/2 used in the frequency response calculations 256 frequency points.

Note

This toolboxuses the convention that the unit frequency is the Nyquist frequency, defined as half the sampling frequency. The cutoff frequency parameters of all basic filter design functions are normalized by the Nyquist frequency. For example, for a system with a sampling frequency of 1000 Hz, 300 Hz is equal to 300/500 = 0.6. To convert the normalized frequency to an angular frequency about the unit circle, multiply by π. To convert the normalized frequency back to Hertz, multiply by half the sampling frequency.

If you call freqz without an output argument, it plots both amplitude versus frequency and phase versus frequency. For example, a ninth-order Butterworth low-pass filter with a cutoff frequency of 400 Hz and based on a sampling frequency of 2000 Hz is:

[b,a] = butter(9,400/1000);

To calculate the 256-point complex frequency response of this filter and plot the magnitude and phase using freqz, use

freqz(b,a,256,2000)

freqz can also accept a vector of any number of frequency points for use in frequency response calculations. For example,

w = linspace(0,pi);
h = freqz(b,a,w);

Computes the complex frequency response of the filter defined by the vectors b and a at the frequency point of w. Frequency points can be values in the range 0 to 2π. To specify a frequency vector from zero to the sampling frequency, include both the frequency vector and the sampling frequency value in the parameter list.

The following example shows how to calculate and display digital frequency response.

Frequency response of transfer function

Calculate and display the magnitude response of a third-order IIR low-pass filter described by the following transfer function:

Represent the numerator and denominator as polynomial convolutions. Find the frequency response at 2001 points distributed across the unit circle.

b0 = 0.05634;
b1 = [1 1];
b2 = [1 -1.0166 1];
a1 = [1 -0.683];
a2 = [1 -1.4461 0.7957];

b = b0*conv(b1,b2);
a = conv(a1,a2);

[h,w] = freqz(b,a,'whole',2001);

Plots the amplitude response in decibels.

plot(w/pi,20*log10(abs(h)))
ax = gca;
ax.YLim = [-100 20];
ax.XTick = 0:.5:2;
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

Figurecontainsanaxesobject.TheaxesobjectwithxlabelNormalizedFrequency(timespiblankrad/sample),ylabelMagnitude(dB)containsanobjectoftypeline.

Frequency response of FIR bandpass filter

Design an FIR bandpass filter with a passband between 0.35π and 0.8π rad/sample and a ripple of 3 dB. The first stopband is from 0 to 0.1π rad/sample with 40 dB attenuation. The second stopband is from 0.9π rad/sample to the Nyquist frequency with 30 dB attenuation. Calculate the frequency response. Plot its amplitude both in linear units and in decibels. Highlight the passband.

sf1 = 0.1;
pf1 = 0.35;
pf2 = 0.8;
sf2 = 0.9;
pb = linspace(pf1,pf2,1e3)*pi;

bp = designfilt('bandpassfir', ...
    'StopbandAttenuation1',40, 'StopbandFrequency1',sf1,...
    'PassbandFrequency1',pf1,'PassbandRipple',3,'PassbandFrequency2',pf2, ...
    'StopbandFrequency2',sf2,'StopbandAttenuation2',30);

[h,w] = freqz(bp,1024);
hpb = freqz(bp,pb);

subplot(2,1,1)
plot(w/pi,abs(h),pb/pi,abs(hpb),'.-')
axis([0 1 -1 2])
legend('Response','Passband','Location','South')
ylabel('Magnitude')

subplot(2,1,2)
plot(w/pi,db(h),pb/pi,db(hpb),'.-')
axis([0 1 -60 10])
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')

Figure contains 2 axes objects. Axes object 1 with ylabel Magnitude contains 2 objects of type line. These objects represent Response, Passband. Axes object 2 with xlabel Normalized Frequency (\times\pi rad/sample) , ylabel Magnitude (dB) contains 2 objects of type line.

Magnitude response of high-pass filter

Design a third-order high-pass Butterworth filter with a normalized 3-dB frequency of 0.5π rad/sample. Calculate its frequency response. Express the amplitude response in decibels and plot it.

[b,a] = butter(3,0.5,'high');
[h,w] = freqz(b,a);

dB = mag2db(abs(h));

plot(w/pi,dB)
xlabel('\omega / \pi')
ylabel('Magnitude (dB)')
ylim([-82 5])

Figure contains an axes object. The axes object with xlabel omega blank / blank pi, ylabel Magnitude (dB) contains an object of type line.

Use fvtool to repeat the calculation.

fvtool(b,a)

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains an object of type line.

Simulation domain

freqs computes the frequency response of an analog filter defined by two input coefficient vectors b and a. The operation is similar to that of freqz; you can specify the number of frequency points to use, provide a vector of any number of frequency points, and plot the amplitude and phase response of the filter. This example shows how to calculate and display analog frequency response.

Comparison of analog IIR low-pass filters

Try this example Copy Code Copy Command

Design a fifth-order analog Butterworth low-pass filter with a cutoff frequency of 2 GHz. Multiply by 2π to convert frequency to rad/second. Calculate the frequency response of the filter at 4096 points.

n = 5;
fc = 2e9;

[zb,pb,kb] = butter(n,2*pi*fc,"s");
[bb,ab] = zp2tf(zb,pb,kb);
[hb,wb] = freqs(bb,ab,4096);

Design a fifth-order Chebyshev I-type filter with the same edge frequency and 3 dB passband ripple. Calculate its frequency response.

[z1,p1,k1] = cheby1(n,3,2*pi*fc,"s");
[b1,a1] = zp2tf(z1,p1,k1);
[h1,w1] = freqs(b1,a1,4096);

Design a 5th order Chebyshev type II filter with the same edge frequency and 30 dB stopband attenuation. Calculate its frequency response.

[z2,p2,k2] = cheby2(n,30,2*pi*fc,"s");
[b2,a2] = zp2tf(z2,p2,k2);
[h2,w2] = freqs(b2,a2,4096);

Design a fifth-order elliptical filter with the same edge frequency and 3 dB passband ripple, 30 dB stopband attenuation. Calculate its frequency response.

[ze,pe,ke] = ellip(n,3,30,2*pi*fc,"s");
[be,ae] = zp2tf(ze,pe,ke);
[he,we] = freqs(be,ae,4096);

Design a 5th order Bessel filter with the same edge frequencies. Calculate its frequency response.

[zf,pf,kf] = besself(n,2*pi*fc);
[bf,af] = zp2tf(zf,pf,kf);
[hf,wf] = freqs(bf,af,4096);

Plots attenuation in decibels. Expresses frequency in gigahertz. Compare filters.

plot([wb w1 w2 we wf]/(2e9*pi), ...
    mag2db(abs([hb h1 h2 he hf])))
axis([0 5 -45 5])
grid
xlabel("Frequency (GHz)")
ylabel("Attenuation (dB)")
legend(["butter" "cheby1" "cheby2" "ellip" "besself"])

Figure contains an axes object. The axes object with xlabel Frequency (GHz), ylabel Attenuation (dB) contains 5 objects of type line. These objects represent butter, cheby1, cheby2, ellip, besself.

Butterworth and Chebyshev type II filters have a flat passband and a wide transition band. Chebyshev I-type and elliptical filters roll off faster but have passband ripple. The frequency input to the Chebyshev Type II design function sets the start of the stopband, not the end of the passband. Bessel filters have approximately constant group delay along the passband.

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Algorithm skill tree Home page Overview 57,500 people are learning the system