0% found this document useful (0 votes)
13 views

Dtsp Assignment

The document outlines the implementation of Butterworth and Chebyshev highpass filters using MATLAB code. It includes specifications for filter design, signal generation, filtering process, and plotting of frequency responses and Fourier transforms for both input and output signals. The code segments demonstrate the steps for designing and analyzing the filters, providing visual representations of their performance.

Uploaded by

50Sakshi Mhaske
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Dtsp Assignment

The document outlines the implementation of Butterworth and Chebyshev highpass filters using MATLAB code. It includes specifications for filter design, signal generation, filtering process, and plotting of frequency responses and Fourier transforms for both input and output signals. The code segments demonstrate the steps for designing and analyzing the filters, providing visual representations of their performance.

Uploaded by

50Sakshi Mhaske
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

SET-1.

Sakshi Mhaske

3022167
a)Butterworth using IIV
Code:-
clc;
close
all;
clear
all;

% Sampling frequency
fsamp = 20000;

% Filter design specifications wp = 0.7*pi; %


Passband edge frequency in radians/sec ws =
0.2*pi; % Stopband edge frequency in
radians/sec
Rp = 2; % Passband ripple in dB Rs =
30; % Stopband attenuation in Db
fp=(wp*fsamp)/(2*pi);% normalised
frequencies..
fs=(ws*fsamp)/(2*pi); t = (0:1/fsamp:1); x1 =
sin(2*pi*8000*t); % Sine wave at 8000 Hz (in the
passband) x2 = sin(2*pi*500*t); % Sine wave at
500 Hz (in the stopband) x = x1 + x2; %
Combined signal
L = length(x); % Length of the signal
% Filter design using Butterworth filter

[n, wn] = buttord(wp/pi, ws/pi, Rp, Rs); % Get filter order and cutoff
(normalized)

[b, a] = butter(n, wn, 'high'); % Highpass Butterworth filter in


z-domain

% Filter the
signal y =
filter(b, a, x);

% Frequency response of the filter

[H, w] = freqz(b, a, L, fsamp); % Get the frequency response of the


digital filter

% Fourier Transform of input signal x[n]

X= fft(x, L); f = (0:L-1)*(fsamp/L); % Frequency axis


for FFT

% Fourier Transform of output signal y[n]

Y = fft(y, L);

% Plot the magnitude and phase response of


H(w) figure;

% Magnitude of the filter's frequency


response |H(w)| subplot(4, 1, 1); plot(w,
abs(H)); % Plot the magnitude |H(w)|
title('Magnitude of H(\omega)');
xlabel('Frequency (Hz)'); ylabel('|H(\
omega)|'); grid on;

% Phase (Angle) of the filter's frequency


response H(w) subplot(4, 1, 2); plot(w,
angle(H)); % Plot the phase H(w) title('Phase
of H(\omega)');
xlabel('Frequency (Hz)');
ylabel( 'H(\omega)
(radians)'); grid on;

% Magnitude of the input signal's Fourier


Transform |X(w)| subplot(4, 1, 3); plot(f, abs(X));
% Plot the magnitude |X(w)| title('Magnitude
Spectrum of X(\omega)'); xlabel('Frequency
(Hz)'); ylabel('|X(\omega)|'); grid on;

% Magnitude of the output signal's Fourier


Transform |Y(w)| subplot(4, 1, 4); plot(f, abs(Y));
% Plot the magnitude |Y(w)| title('Magnitude
Spectrum of Y(\omega)'); xlabel('Frequency
(Hz)'); ylabel('|Y(\omega)|'); grid on;

OUTPUT:-
B)Chebyshev using BLT

clc;
close
all;
clear
all;

% Sampling frequency
fsamp = 20000;

% Filter design specifications (convert to normalized frequencies) wp


= 2*8000/fsamp; % Passband edge frequency (8000 Hz, normalized
by fsamp) ws = 2*500/fsamp; % Stopband edge frequency (500 Hz,
normalized by fsamp)
Rp = 2; % Passband ripple in dB
Rs = 40; % Stopband attenuation in dB

% Generate input signals (same as before) t =


(0:1/fsamp:1); % Time vector x1 =
sin(2*pi*8000*t); % Sine wave at 8000 Hz (in the
passband) x2 = sin(2*pi*500*t); % Sine wave at
500 Hz (in the stopband) x = x1 + x2; %
Combined signal
L = length(x); % Length of the signal

% Filter design using Chebyshev Type I filter

[n, wn] = cheb1ord(wp, ws, Rp, Rs); % Get filter order and cutoff
(normalized) [b, a] = cheby1(n, Rp, wn, 'high'); % Highpass
Chebyshev Type I filter (digital)

% Filter the
signal y =
filter(b, a, x);

% Frequency response of the filter

[H, w] = freqz(b, a, L, fsamp); % Get the frequency response of the


digital filter

% Fourier Transform of input signal x[n]

X= fft(x, L); f = (0:L-1)*(fsamp/L); % Frequency axis


for FFT

% Fourier Transform of output signal y[n]

Y = fft(y, L);
% Plot the magnitude and phase response of
H(w) figure;

% Magnitude of the filter's frequency response |H(w)|


subplot(4, 1, 1); plot(w, abs(H)); % Plot
the magnitude |H(w)| title('Magnitude of
Chebyshev Filter H(\omega)');
xlabel('Frequency (Hz)'); ylabel('|H(\
omega)|'); grid on;

% Phase (Angle) of the filter's frequency


response H(w) subplot(4, 1, 2); plot(w,
angle(H)); % Plot the phase H(w) title('Phase
of Chebyshev Filter H(\omega)');
xlabel('Frequency (Hz)'); ylabel(' H(\omega)
(radians)'); grid on;

% Magnitude of the input signal's Fourier


Transform |X(w)| subplot(4, 1, 3); plot(f, abs(X));
% Plot the magnitude |X(w)| title('Magnitude
Spectrum of X(\omega)'); xlabel('Frequency
(Hz)'); ylabel('|X(\omega)|'); grid on;

% Magnitude of the output signal's Fourier


Transform |Y(w)| subplot(4, 1, 4); plot(f, abs(Y));
% Plot the magnitude |Y(\omega)|');
title('Magnitude Spectrum of Y(\omega)');
xlabel('Frequency (Hz)');
ylabel('|Y(\omega)|');
grid on;
OUTPUT:
-

You might also like