0% found this document useful (0 votes)
23 views9 pages

DSP Session1 (17) CodesA

Uploaded by

Thiện Nguyễn
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)
23 views9 pages

DSP Session1 (17) CodesA

Uploaded by

Thiện Nguyễn
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
You are on page 1/ 9

Simulation project A:

Name: Lê Văn Thịnh


Student’s ID: 421H0428
Name: Nguyễn Chí Thiện
Student’s ID: 421H0426
1. Design a digital Butterworth lowpass filter operating at a sampling rate of 80 kHz
with a 0.5-dB cutoff frequency at 4 kHz and a minimum stopband attenuation of 45
dB at 20 kHz using bilinear transformation method. Determine the order of the
analog filter prototype using the buttord function. Then design the filter using
buttap. Use zp2tf to convert the poles and zeros you obtain to a transfer function
and then use lp2lp to transform the filter to desired cut-off. Plot the magnitude and
phase response of the designed filter.
Introduction (Problem Statement):
The problem is to design a digital Butterworth lowpass filter with specific
characteristics. The filter needs to operate at a sampling rate of 80 kHz, with a cutoff
frequency of 4 kHz and a minimum stopband attenuation of 45 dB at 20 kHz. The
bilinear transformation method is to be used for the design process.
Related Theory:
Butterworth filters are a type of analog or digital filter with a maximally flat
frequency response in the passband. The bilinear transformation is a method used to
convert analog filter designs to digital filters. It maps the s-plane (analog frequency
domain) to the z-plane (digital frequency domain) using a bilinear transformation.
This method is commonly used for its stability properties and preservation of
frequency response characteristics.
Algorithms/Calculation:
1.Determine the Order of the Analog Filter Prototype:
Use the buttord function to determine the order (N) and the cutoff frequency (Wn) of
the analog filter prototype.
2.Design the Analog Filter Prototype:
Use the buttord function to determine the order (N) and the cutoff frequency (Wn) of
the analog filter prototype.
Use the buttamp function to design the Butterworth analog filter prototype with the
determined order and cutoff frequency.
3.Convert Poles and Zeros to Transfer Function:
Use the zp2tf function to convert the poles and zeros of the analog filter prototype to
a transfer function.
4.Transform the Filter:
Use the lp2lp function to transform the filter from the analog cutoff frequency to the
desired cutoff frequency.
5.Plot Magnitude and Phase Response:
Use the freqz function to compute the frequency response of the filter.
6.Plot the magnitude and phase response of the designed filter.
Source Codes:
Here's the MATLAB code :
% Bước 1: Xác định bậc của bộ lọc analog prototype
fs = 80000; % Tần số lấy mẫu
fc = 4000; % Tần số cắt
stop_atten = 45; % Độ suy giảm tối thiểu ở tần số dừng

% Chia tần số cắt cho nửa tần số lấy mẫu


Wp = fc / (fs/2);

% Tính toán bậc và tần số cắt của bộ lọc


[N, Wn] = buttord(Wp, 0.5, 0.05, stop_atten); % 0.5 là độ rộng của dải chuyển đổi

% Bước 2: Thiết kế bộ lọc analog prototype


[z, p, k] = buttap(N);

% Bước 3: Chuyển đổi poles và zeros sang hàm truyền


[b, a] = zp2tf(z, p, k);

% Bước 4: Biến đổi bộ lọc


[b, a] = lp2lp(b, a, Wn);

% Bước 5: Vẽ đồ thị phản ứng


[H, w] = freqs(b, a);
figure;
subplot(2,1,1);
plot(w/(2*pi), 20*log10(abs(H)));
title('Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;

subplot(2,1,2);
plot(w/(2*pi), angle(H)*180/pi);
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;

Results:
The results of running the MATLAB code show the magnitude and phase response of
the designed Butterworth lowpass filter. The filter meets the specified requirements
for cutoff frequency and stopband attenuation.

Conclusion:
In conclusion, the digital Butterworth lowpass filter has been successfully designed
using the bilinear transformation method in MATLAB. The filter exhibits the desired
characteristics, with a cutoff frequency of 4 kHz and a minimum stopband
attenuation of 45 dB at 20 kHz. The magnitude and phase response plots
demonstrate the effectiveness of the designed filter in achieving the desired
frequency response.
2.Design a Type I Chebyshev lowpass filter operating at a sampling rate of 80 kHz
with a 0.5-dB cutoff frequency at 4 kHz and a minimum stopband attenuation of 45
dB at 20 kHz using bilinear transformation method. Design the analog prototype
using cheb1ap. Use zp2tf to convert the poles and zeros you obtain to a transfer
function and then use lp2lp to transform the filter to desired cut-off. Get the
discrete-time filter using bilinear Plot the magnitude and phase response of the
designed filter.
Introduction (Problem Statement):
The task is to design a Type I Chebyshev lowpass filter with specific characteristics.
The filter should operate at a sampling rate of 80 kHz, with a cutoff frequency of 4
kHz and a minimum stopband attenuation of 45 dB at 20 kHz. The bilinear
transformation method is to be employed for the design process.

Related Theory:
Type I Chebyshev filters are a class of analog or digital filters known for their
equiripple behavior in the passband and a sharp transition from the passband to the
stopband. The bilinear transformation method is commonly used to convert analog
filter designs to digital filters while preserving certain characteristics such as stability
and frequency response.

Algorithms/Calculation:
1.Design the Analog Prototype:
Use the cheb1ap function to design the analog prototype Chebyshev Type I filter with
the specified characteristics.
2.Convert Poles and Zeros to Transfer Function:
Use the zp2tf function to convert the poles and zeros of the analog filter prototype to
a transfer function.
3.Transform the Filter:
Use the lp2lp function to transform the filter from the analog cutoff frequency to the
desired cutoff frequency.
4.Get the Discrete-Time Filter:
Use the bilinear transformation method to convert the analog filter to a discrete-time
filter.
5.Plot Magnitude and Phase Response:
Use the freqz function to compute the frequency response of the filter.
6.Plot the magnitude and phase response of the designed filter.
Source Codes:
Here's the MATLAB code:
close all;
% Define filter specifications
fs = 80000; % Sampling frequency
fc = 4000; % Cutoff frequency
stop_atten = 45; % Stopband attenuation
Wp = fc / (fs/2); % Relative cutoff frequency

% Design analog prototype Chebyshev Type I filter


[z, p, k] = cheb1ap(10, stop_atten); % Design analog prototype

% Convert poles and zeros to transfer function


[b, a] = zp2tf(z, p, k);

% Transform filter to desired cutoff


[b, a] = lp2lp(b, a, Wp);

% Get the discrete-time filter using bilinear transformation


[bd, ad] = bilinear(b, a, fs);

% Plot magnitude and phase response


[H, w] = freqz(bd, ad, [], fs);
figure;
subplot(2,1,1);
plot(w/(2*pi), 20*log10(abs(H)));
title('Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
subplot(2,1,2);
plot(w/(2*pi), angle(H)*180/pi);
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
Results:
The results of running the MATLAB code show the magnitude and phase response of
the designed Chebyshev Type I lowpass filter. The filter meets the specified
requirements for cutoff frequency and stopband attenuation.

Conclusion:
In conclusion, the Type I Chebyshev lowpass filter has been successfully designed
using the bilinear transformation method in MATLAB. The filter exhibits the desired
characteristics, with a cutoff frequency of 4 kHz and a minimum stopband
attenuation of 45 dB at 20 kHz. The magnitude and phase response plots
demonstrate the effectiveness of the designed filter in achieving the desired
frequency response.

3. Design an Elliptic lowpass filter operating at a sampling rate of 80 kHz with a 0.5-
dB cutoff frequency at 4 kHz and a minimum stopband attenuation of 45 dB at 20
kHz using bilinear transformation method. Design the analog prototype using
ellipap. Use zp2tf to convert the poles and zeros you obtain to a transfer function
and then use lp2lp to transform the filter to desired cut-off. Get the discrete-time
filter using bilinear. Plot the magnitude and phase response of the designed filter.

Introduction (Problem Statement):


The task at hand involves designing an Elliptic lowpass filter for a digital signal
processing application. The filter needs to operate at a sampling rate of 80 kHz and
meet specific cutoff frequency and stopband attenuation requirements. The design
process will utilize the bilinear transformation method to transform an analog
prototype filter to its discrete-time counterpart. The objective is to achieve the
desired frequency response characteristics, including magnitude and phase
responses.
Related Theory:
Elliptic filters, also known as Cauer filters, are a type of filter known for their ability to
achieve extremely sharp cutoffs between passband and stopband regions. They offer
the steepest transition band compared to other types of filters but with ripple in both
the passband and stopband. The design of Elliptic filters involves determining the
filter order based on specifications and utilizing methods like the elliptic analog
prototype design function ellipap, followed by transformation techniques to obtain
the desired discrete-time filter.

Algorithms/Calculation:
1.Determine the filter order based on specifications.
2.Design the analog prototype using the ellipap function.
3.Convert poles and zeros to a transfer function using zp2tf.
4.Transform the filter to the desired cutoff frequency using lp2lp.
5.Obtain the discrete-time filter using the bilinear transformation method.
6.Plot the magnitude and phase responses of the designed filter.
Source Codes:
Close all;

% Define filter specifications

fs = 80000; % Sampling frequency


fc = 4000; % Cutoff frequency
stop_atten = 45; % Stopband attenuation

% Define the passband and stopband ripple values


ripple_passband = 0.5; % Passband ripple in dB
ripple_stopband = stop_atten; % Stopband attenuation in dB

% Design analog prototype Elliptic filter


[z, p, k] = ellipap(10, ripple_passband, ripple_stopband); % Design analog
prototype

% Relative cutoff frequency


Wp = fc / (fs/2);

% Convert poles and zeros to transfer function


[b, a] = zp2tf(z, p, k);

% Transform filter to desired cutoff


[b, a] = lp2lp(b, a, Wp);

% Get the discrete-time filter using bilinear transformation


[bd, ad] = bilinear(b, a, fs);
% Plot magnitude and phase response
[H, w] = freqz(bd, ad, [], fs);
figure;
subplot(2,1,1);
plot(w/(2*pi), 20*log10(abs(H)));
title('Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
subplot(2,1,2);
plot(w/(2*pi), angle(H)*180/pi);
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
Results:
The designed Elliptic lowpass filter successfully meets the specifications with a cutoff
frequency of 4 kHz and a minimum stopband attenuation of 45 dB at 20 kHz. The
magnitude and phase responses exhibit the desired characteristics, demonstrating
the effectiveness of the design approach.

Conclusion:
In conclusion, the design of the Elliptic lowpass filter using the bilinear
transformation method in MATLAB has been successful in meeting the specified
requirements. The filter's performance in terms of magnitude and phase responses
aligns with the desired characteristics, indicating its suitability for the intended signal
processing application. Elliptic filters provide a valuable tool for achieving sharp
cutoffs and precise frequency response shaping in digital signal processing systems.

You might also like