0% found this document useful (0 votes)
52 views3 pages

Digital Butterworth IIR Filter Code File

Uploaded by

Himanshu Patil
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)
52 views3 pages

Digital Butterworth IIR Filter Code File

Uploaded by

Himanshu Patil
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/ 3

Name: Amey Parab

UID:2022200091

Branch : EXTC-B2

Digital Butterworth IIR Filter Code file

% Input Specifications
Ap = 3; % Passband Attenuation in dB
As = 40; % Stopband Attenuation in dB
Fp = 1000; % Passband Frequency in Hz
Fs = 2000; % Stopband Frequency in Hz
F = 19000; % Sampling Frequency in Hz

% Case 1: Low Pass Filter Design


Wp = 2 * Fp / F;
disp(Wp);
Ws = 2 * Fs / F;
disp(Ws);
[n, Wn] = buttord(Wp, Ws, Ap, As);
[b, a] = butter(n, Wn);
% Plot Magnitude Spectrum
freqz(b, a)
title('Butterworth LPF - Magnitude Spectrum')
% Pole-Zero Plot
figure;
zplane(b, a);
title('Pole-Zero Plot for Butterworth LPF')

% Case 2: High Pass Filter Design


Wp = 2 * 3500 / 19000;
disp(Wp);
Ws = 2 * 3000/ F;
disp(Ws);
[n, Wn] = buttord(Wp, Ws, Ap, As);
[b, a] = butter(n, Wn, 'high');
% Plot Magnitude Spectrum
figure;
freqz(b, a)
title('Butterworth HPF - Magnitude Spectrum')
% Pole-Zero Plot
figure;
zplane(b, a);
title('Pole-Zero Plot for Butterworth HPF')
% Input Specifications
Ap = 3; % Passband Attenuation in dB
As = 40; % Stopband Attenuation in dB
Fp = 1000; % Passband Frequency in Hz
Fs = 2000; % Stopband Frequency in H
F = 19000; % Sampling Frequency in Hz

% Design an analog Butterworth filter


[n, Wn] = buttord(2*Fp/F, 2*Fs/F, Ap, As, 's'); % Calculate filter order and cutoff
frequency
[B, A] = butter(n, Wn, 'low'); % Design analog Butterworth filter

% Convert to a digital filter using the Bilinear Transformation (BLT)


[Bc, Ac] = bilinear(B, A, F);

% Compute frequency response


[H, w] = freqz(Bc, Ac);

% Calculate magnitude and phase


magnitude_response = abs(H);
phase_response = angle(H);

% Convert the phase to degrees


phase_response_deg = rad2deg(phase_response);

% Create frequency vector in Hz


frequency_vector = w * F / (2 * pi);

% Plot magnitude response


subplot(2, 1, 1);
plot(frequency_vector, 20 * log10(magnitude_response));
axis([30 330 -200 200])
title('Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
% Plot phase response
subplot(2, 1, 2);
plot(frequency_vector, phase_response_deg);
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
%set(gca,'xtick', 0:0.1:200)
axis([30 330 -200 200])
sgtitle('Digital Butterworth Filter Response');
% Input Specifications for High-Pass Filter
Ap = 3; % Passband Attenuation in dB
As = 40; % Stopband Attenuation in dB
Fp = 2000; % Passband Frequency in Hz (changed for HPF)
Fs = 1000; % Stopband Frequency in Hz (changed for HPF)
F = 19000; % Sampling Frequency in Hz

% Design an analog Butterworth high-pass filter


[n, Wn] = buttord(2*Fs/F, 2*Fp/F, Ap, As, 's'); % Calculate filter order and cutoff
frequency
[B, A] = butter(n, Wn, 'high'); % Design analog Butterworth high-pass filter

% Convert to a digital filter using the Bilinear Transformation (BLT)


[Bd, Ad] = bilinear(B, A, F);

% Compute frequency response


[H, w] = freqz(Bd, Ad);

% Calculate magnitude and phase


magnitude_response = abs(H);
phase_response = angle(H);

% Convert the phase to degrees


phase_response_deg = rad2deg(phase_response);

% Create frequency vector in Hz


frequency_vector = w * F / (2 * pi);

% Plot magnitude response


subplot(2, 1, 1);
plot(frequency_vector, 20 * log10(magnitude_response));
axis([10 230 -50 -10])
title('Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;

% Plot phase response


subplot(2, 1, 2);
plot(frequency_vector, phase_response_deg);
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
axis([10 230 -10 90])
sgtitle('Digital Butterworth High-Pass Filter Response');

You might also like