Frequency Response - MATLAB & Simulink - MathWorks United Kingdom (2024)

Frequency Response

Digital Domain

freqz uses an FFT-basedalgorithm to calculate the Z-transform frequency response of a digitalfilter. Specifically, the statement

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

returns the p-point complex frequency response, H(ejω),of the digital filter.

H(ejω)=b(1)+b(2)ejω+...+b(n+1)ejωna(1)+a(2)ejω+...+a(m+1)ejωm

In its simplest form, freqz accepts the filtercoefficient vectors b and a,and an integer p specifying the number of pointsat which to calculate the frequency response. freqz returnsthe complex frequency response in vector h, andthe actual frequency points in vector w in rad/s.

freqz can accept other parameters, such asa sampling frequency or a vector of arbitrary frequency points. Theexample below finds the 256-point frequency response for a 12th-orderChebyshev Type I filter. The call to freqz specifiesa sampling frequency fs of 1000 Hz:

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

Because the parameter list includes a sampling frequency, freqz returnsa vector f that contains the 256 frequency pointsbetween 0 and fs/2 used in the frequency responsecalculation.

Note

This toolbox uses the convention that unit frequency is theNyquist frequency, defined as half the sampling frequency. The cutofffrequency parameter for all basic filter design functions is normalizedby the Nyquist frequency. For a system with a 1000Hzsampling frequency, for example, 300Hz is 300/500=0.6. To convert normalized frequencyto angular frequency around the unit circle, multiply byπ.To convert normalized frequency back to hertz, multiply by half thesample frequency.

If you call freqz with no output arguments,it plots both magnitude versus frequency and phase versus frequency.For example, a ninth-order Butterworth lowpass filter with a cutofffrequency of 400 Hz, based on a 2000 Hz sampling frequency, is

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

To calculate the 256-point complex frequency response for thisfilter, and plot the magnitude and phase with freqz,use

freqz(b,a,256,2000)

freqz can also accept a vector of arbitraryfrequency points for use in the frequency response calculation. Forexample,

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

calculates the complex frequency response at the frequency pointsinw for the filter defined byvectors b anda.The frequency points can range from 0 to 2π.To specify a frequency vector that ranges from zero to your samplingfrequency, include both the frequency vector and the sampling frequencyvalue in the parameter list.

These examples show how to compute and display digital frequencyresponses.

Frequency Response from Transfer Function

Open Live Script

Compute and display the magnitude response of the third-order IIR lowpass filter described by the following transfer function:

H(z)=0.05634(1+z-1)(1-1.0166z-1+z-2)(1-0.683z-1)(1-1.4461z-1+0.7957z-2).

Express the numerator and denominator as polynomial convolutions. Find the frequency response at 2001 points spanning the complete 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);

Plot the magnitude response expressed 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)')

Frequency Response- MATLAB & Simulink- MathWorks United Kingdom (1)

Frequency Response of an FIR Bandpass Filter

Open Live Script

Design an FIR bandpass filter with passband between 0.35π and 0.8π rad/sample and 3 dB of ripple. The first stopband goes from 0 to 0.1π rad/sample and has an attenuation of 40 dB. The second stopband goes from 0.9π rad/sample to the Nyquist frequency and has an attenuation of 30 dB. Compute the frequency response. Plot its magnitude in both linear units and 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)')

Frequency Response- MATLAB & Simulink- MathWorks United Kingdom (2)

Magnitude Response of a Highpass Filter

Open Live Script

Design a 3rd-order highpass Butterworth filter having a normalized 3-dB frequency of 0.5π rad/sample. Compute its frequency response. Express the magnitude 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])

Frequency Response- MATLAB & Simulink- MathWorks United Kingdom (3)

Analog Domain

freqs evaluates frequencyresponse for an analog filter defined by two input coefficient vectors, b anda. Its operation is similar to thatof freqz; you can specify a number of frequencypoints to use, supply a vector of arbitrary frequency points, andplot the magnitude and phase response of the filter. This exampleshows how to compute and display analog frequency responses.

Comparison of Analog IIR Lowpass Filters

Open Live Script

Design a 5th-order analog Butterworth lowpass filter with a cutoff frequency of 2 GHz. Multiply by 2π to convert the frequency to radians per second. Compute 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 5th-order Chebyshev Type I filter with the same edge frequency and 3 dB of passband ripple. Compute 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 of stopband attenuation. Compute 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 5th-order elliptic filter with the same edge frequency, 3 dB of passband ripple, and 30 dB of stopband attenuation. Compute 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 frequency. Compute its frequency response.

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

Plot the attenuation in decibels. Express the frequency in gigahertz. Compare the filters.

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

Frequency Response- MATLAB & Simulink- MathWorks United Kingdom (4)

The Butterworth and Chebyshev Type II filters have flat passbands and wide transition bands. The Chebyshev Type I and elliptic filters roll off faster but have passband ripple. The frequency input to the Chebyshev Type II design function sets the beginning of the stopband rather than the end of the passband. The Bessel filter has approximately constant group delay along the passband.

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Frequency Response- MATLAB & Simulink- MathWorks United Kingdom (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Frequency Response
- MATLAB & Simulink
- MathWorks United Kingdom (2024)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated:

Views: 5983

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.