0% found this document useful (0 votes)
34 views5 pages

MATLAB Low Pass Filter Designs

The document provides MATLAB code for designing various types of filters including Butterworth, Elliptic, Chebyshev Type I, and Chebyshev Type II filters. It covers low pass, high pass, band pass, and band stop filters with specified parameters such as order, cutoff frequency, and sampling frequency. Each filter design includes code snippets for frequency response analysis and visualization using fvtool.

Uploaded by

334nasiffuad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

MATLAB Low Pass Filter Designs

The document provides MATLAB code for designing various types of filters including Butterworth, Elliptic, Chebyshev Type I, and Chebyshev Type II filters. It covers low pass, high pass, band pass, and band stop filters with specified parameters such as order, cutoff frequency, and sampling frequency. Each filter design includes code snippets for frequency response analysis and visualization using fvtool.

Uploaded by

334nasiffuad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Butterworth Filter:

Design a 6th order Butterworth filter with cutoff frequency 300 Hz for which data sampled at 1000
Hz for low pass, high pass, band pass & band stop filter using fv tool.

Code 1 (Butter):
close all;
clear all;

fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
[h,w]=freqz(b,a);
[b2,a2] = butter(6,fc/(fs/2),'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = butter(3,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = butter(3,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);

figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter')

Elliptic Filter:
Design a 6th-order low pass, high pass, band pass & band stop elliptic filter with 5 dB of pass-
band ripple, 40 dB of stop-band attenuation, and a pass-band edge frequency of 300 Hz, which,
for data sampled at 1000 Hz, corresponds to rad/sample using fv tool.

Code 2:

[b,a] = ellip(6,5,40,0.6);
[h,w]= freqz(b,a);
[b2,a2] = ellip(6,5,40,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = ellip(3,5,50,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = ellip(3,5,50,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend(' ellip')

Chebyshev Type I Filter:


Design a 6th-order low pass, high pass, band pass & band stop Chebyshev Type I filter with 10
dB of passband ripple and a passband edge frequency of 300 Hz, which, for data sampled at 1000
Hz, corresponds to rad/sample using fv tool.

Code 3:
fc = 300;
fs = 1000;

[b,a] = cheby1(6,10,0.6);
[h,w]=freqz(b,a);
[b2,a2] = cheby1(6,10,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(3,5,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby1(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);

figure(1);
plot(w/pi,20*log(abs(h)));
figure(2);
plot(w2/pi,20*log(abs(h2)));
figure(3);
plot(w3/pi,20*log(abs(h3)));
figure(4);
plot(w4/pi,20*log(abs(h4)));
grid;

fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('cheby1')

Chebyshev Type II Filter:


Design a 6th-order low pass, high pass, band pass & band stop Chebyshev Type II filter with 10
dB of passband ripple and a passband edge frequency of 300 Hz, which, for data sampled at 1000
Hz, corresponds to rad/sample using fv tool.

Code 4:
clc
close all
clear all
fc = 300;
fs = 1000;
[b,a] = cheby2(6,10,0.6);
[h,w]=freqz(b,a);
[b2,a2] = cheby2(6,10,0.6,'high');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby2(3,5,[0.2 0.6],'stop');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);figue(1);
plot(w/pi,20*log(abs(h)));
figue(2);
plot(w2/pi,20*log(abs(h2)));
figue(3);
plot(w3/pi,20*log(abs(h3)));
figue(4);
plot(w4/pi,20*log(abs(h4)));

fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('cheby2')

Low pass filter:


Matlab code:

Design a 6th-order low pass for Butterworth, Elliptic, Chebyshev Type I & Chebyshev Type II
filter with 10 dB of passband ripple and a passband edge frequency of 300 Hz, which, for data
sampled at 1000 Hz, corresponds to rad/sample using fv tool.

Code 5:
clc
clear all
close all
n=6;
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
[h,w]=freqz(b,a);
[b2,a2] = ellip(6,5,40,0.6);
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(6,10,0.6);
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(6,10,0.6);
[h4,w4]=freqz(b4,a4);
plot(w/pi,20*log(abs(h)));
hold on
plot(w2/pi,20*log(abs(h2)));
plot(w3/pi,20*log(abs(h3)));
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter','ellip','cheby1','cheby2')

Band pass filter:

Design a 6th-order band pass for Butterworth, Elliptic, Chebyshev Type I & Chebyshev Type II
filter with 10 dB of passband ripple and a passband edge frequency of 300 Hz, which, for data
sampled at 1000 Hz, corresponds to rad/sample using fv tool.

Code 6:
clc
clear all
close all
n=6;
fc = 300;
fs = 1000;
[b,a] = butter(3,[0.2 0.6],'bandpass');
[h,w]=freqz(b,a);
[b2,a2] = ellip(3,5,50,[0.2 0.6],'bandpass');
[h2,w2]=freqz(b2,a2);
[b3,a3] = cheby1(3,5,[0.2 0.6],'bandpass');
[h3,w3]=freqz(b3,a3);
[b4,a4] = cheby2(3,5,[0.2 0.6],'bandpass');
[h4,w4]=freqz(b4,a4);
plot(w/pi,20*log(abs(h)));
hold on
plot(w2/pi,20*log(abs(h2)));
plot(w3/pi,20*log(abs(h3)));
plot(w4/pi,20*log(abs(h4)));
grid;
fvtool(b,a,b2,a2,b3,a3,b4,a4);
xlabel('Frequency (GHz)')
ylabel('Attenuation (dB)')
legend('butter','ellip','cheby1','cheby2')

Lowpass Filter code:


clc clear all
close all n=6;
fc = 50; fs =
100;
[b,a] = butter(n,fc/fs,'low');
[h,w]=freqz(b,a);
plot((w/pi)*fs,(abs(h))); grid on
xlabel('Frequency (Hz)') ylabel('Amplitude')

Bandpass Filter code:


clc clear all
close all n=6;
fc = 55; fs =
100;
[b,a] = butter(n,[(fc-20)/fs (fc+20)/fs],'bandpass');
%This line is the same: [b,a] = butter(n,[0.35
0.75],'bandpass'); [h,w]=freqz(b,a);
plot((w/pi)*fs,(abs(h))); grid on
xlabel('Frequency (Hz)') ylabel('Amplitude')

Common questions

Powered by AI

Chebyshev Type I filters, having ripple only in the passband, provide a quicker transition from passband to stopband, leading to a better performance in terms of selective bandpass at the expense of passband distortion due to the ripple . Chebyshev Type II filters offer smooth passband characteristics without ripple, favoring scenarios where passband integrity is crucial, though they provide a slower cutoff . The passband ripple in Chebyshev Type I affects the flatness of the passband, introducing potential signal inaccuracies, whereas Chebyshev Type II maintains a flat passband but sacrifices sharpness in transition .

The passband edge frequency is crucial as it directly affects how the filter separates desired signal frequencies from undesired ones. In applications requiring minimal signal distortion and maximum fidelity, Butterworth filters may be preferred due to their smooth roll-off around the passband edge . For applications demanding sharper transitions and tighter control over frequency bands, Elliptic or Chebyshev filters are more suitable due to their steep cutoff characteristics near the edge frequency . However, trade-offs such as ripple and potential distortion must align with the application's tolerance and performance requirements, determining the appropriate filter selection .

Butterworth filters have a maximally flat frequency response in the passband with no ripples, leading to a smooth transition in the frequency response . Elliptic filters, or Cauer filters, allow for the steepest roll-off for a given filter order and have ripples in both the passband and stopband, providing very sharp cutoff characteristics . Chebyshev Type I filters exhibit ripples in the passband but not in the stopband, allowing for a faster transition than Butterworth at the cost of passband ripples . Chebyshev Type II filters, in contrast, have ripples in the stopband but not in the passband, offering a smooth passband response but a less sharp cutoff compared to Elliptic filters .

The FVTool (Filter Visualization Tool) in MATLAB is integral to the design and analysis of filters as it provides comprehensive tools to visualize various aspects of the filter's behavior such as magnitude, phase, impulse, and group delay responses . FVTool simplifies the process of evaluating different filter parameters, allowing for configuration and testing of filter effectiveness through comparative analysis on the same interface . It also supports the interactive adjustment of filter coefficients and real-time observation of resultant changes, facilitating efficient iterative development and enhancement of robust filter designs . Its capability to process and visualize data for multi-stage filters further extends its utility in complex filter design projects .

The main consideration in choosing a 6th-order filter over a lower order one is the trade-off between filter steepness and computational complexity. Higher-order filters exhibit steeper roll-offs, allowing for sharper transitions between passband and stopband, which is essential in achieving precise frequency selection . In Butterworth filters, this helps in maintaining a maximally flat passband; in Elliptic filters, it contributes to minimizing transition widths while handling severe attenuation requirements . The complexity increases with order, affecting processing time and resources, an important consideration for real-time signal processing applications .

The sampling frequency impacts the filter design by defining the Nyquist frequency, which is half the sampling rate. The Nyquist frequency serves as a reference to determine the normalized frequency, making it critical for avoiding aliasing effects . In the design of the Butterworth low-pass filter, a 1000 Hz sampling frequency is used, giving a Nyquist frequency of 500 Hz. This allows the 300 Hz cutoff frequency to be well within the range of operation, ensuring accurate filtration without aliasing, given the practical limits of the digital filter .

Misconfiguring the normalized frequency can lead to significant errors like aliasing and incorrect filter behavior. For example, setting frequencies beyond the Nyquist limit (half the sampling frequency) results in aliasing, where higher frequencies are misconstrued as lower ones . It's mitigated by ensuring that design frequencies are correctly normalized concerning the defined sampling frequency, maintaining them below the Nyquist threshold . Additionally, using tools like MATLAB's FVTool allows visual assessment of frequency responses, highlighting potential misconfigurations before they impact actual signal processing tasks .

The frequency response grid helps visualize and compare the characteristic differences among various filters by plotting the magnitude response across the frequency spectrum . It aids in assessing crucial attributes such as bandwidth, attenuation, and ripple effects directly, providing a visual method for comprehensive performance evaluation . This visual representation is beneficial during design adjustments for analyzing parameter influence on frequency response, allowing for informed modifications to achieve desired outcomes in filter characteristics . Additionally, the grid facilitates quick comparisons between filter responses for improved decision-making in selecting appropriate filter types for specific applications .

In high-pass filter designs, Butterworth maintains a maximally flat frequency response with no ripple across both pass and stop bands, preserving signal fidelity without distortion but with a relatively slower roll-off towards the stopband . On the other hand, Elliptic filters employ ripples in both passbands to achieve faster roll-off, offering sharper transitions but potentially introducing signal distortion due to ripple effects in scenarios where passband precision is critical . Thus, while Butterworth designs offer high signal fidelity at the cost of roll-off sharpness, Elliptic filters prioritize transition characteristics potentially affecting fidelity .

Elliptic filters offer the advantage of having the steepest transition between pass-band and stop-band among all filter types of the same order, ensuring very efficient filtration with minimal filter order . However, the disadvantages include ripples present in both the pass-band and stop-band which can distort the signal depending on sensitivity to ripple levels . The 5 dB pass-band ripple can lead to signal distortion in applications where ripple constraints are strict, and careful consideration must be given to the nature of the signal being processed .

You might also like