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

DSPZ6

The document contains MATLAB code for a Digital Signal Processing lab, focusing on generating sinusoids and applying a notch filter to remove an 80 Hz component. It includes time and frequency domain analyses of the input and filtered signals, comparing outputs from standard filtering and zero-phase filtering methods. The results are visualized through plots showing both time and frequency domain representations.

Uploaded by

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

DSPZ6

The document contains MATLAB code for a Digital Signal Processing lab, focusing on generating sinusoids and applying a notch filter to remove an 80 Hz component. It includes time and frequency domain analyses of the input and filtered signals, comparing outputs from standard filtering and zero-phase filtering methods. The results are visualized through plots showing both time and frequency domain representations.

Uploaded by

Ahmed Bawani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ZUBAIR KHAN 02-133222-048 BEE 6-B

DIGITAL SIGNAL PROCESSING LAB


LAB NO. 06
QUESTION NO. 01
MATLAB CODE
clc;
% Sampling frequency and time vector
Fs = 1000; % Sampling frequency
n = 0:1023; % Time samples
t = n/Fs; % Time vector (seconds)
% Generate three sinusoids: 10 Hz, 80 Hz, 130 Hz
x1 = sin(2*pi*10*t); % 10 Hz
x2 = sin(2*pi*80*t); % 80 Hz
x3 = sin(2*pi*130*t); % 130 Hz
% Combined input signal
x = x1 + x2 + x3;
% Design Notch filter to remove 80 Hz
w = 2*pi*80/Fs; % Digital frequency
b = [1 -2*cos(w) 1]; % Numerator coefficients
a = [1 -0.9*2*cos(w) 0.81];% Denominator coefficients
% Filter the signal
y = filter(b,a,x);
% --- Time Domain Analysis ---
figure;
subplot(2,1,1);
plot(t,x);
title('Input Signal (Time Domain)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t,y);
title('Output Signal after Notch Filter (Time Domain)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
% --- Frequency Domain Analysis ---
ZUBAIR KHAN 02-133222-048 BEE 6-B
NFFT = 1024;
f = (-NFFT/2:NFFT/2-1)*(Fs/NFFT);
X = fftshift(fft(x,NFFT));
Y = fftshift(fft(y,NFFT));
figure;
subplot(2,1,1);
plot(f, abs(X));
title('Input Signal Spectrum (Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;
subplot(2,1,2);
plot(f, abs(Y));
title('Output Signal Spectrum after Notch Filter (Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
grid on;

FIGURE
ZUBAIR KHAN 02-133222-048 BEE 6-B

x---------------x---------------x
QUESTION NO. 02
MATLAB CODE
% Sampling frequency and time vector
Fs = 1000;
n = 0:1023;
t = n/Fs;
% Generate three sinusoids: 10 Hz, 80 Hz, 130 Hz
x1 = sin(2*pi*10*t);
x2 = sin(2*pi*80*t);
x3 = sin(2*pi*130*t);
% Combined input signal
x = x1 + x2 + x3;
% Design Notch filter to remove 80 Hz
w = 2*pi*80/Fs;
b = [1 -2*cos(w) 1];
a = [1 -0.9*2*cos(w) 0.81];
% Apply normal filter (with phase delay)
y_filter = filter(b,a,x);
% Apply filtfilt (zero-phase filtering)
y_filtfilt = filtfilt(b,a,x);
ZUBAIR KHAN 02-133222-048 BEE 6-B
% --- Time Domain Comparison ---
figure;
subplot(3,1,1);
plot(t,x);
title('Input Signal (Time Domain)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
plot(t,y_filter);
title('Output using filter() (Time Domain)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
subplot(3,1,3);
plot(t,y_filtfilt);
title('Output using filtfilt() (Time Domain)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
% --- Frequency Domain Comparison ---
NFFT = 1024;
f = (-NFFT/2:NFFT/2-1)*(Fs/NFFT);
X = fftshift(fft(x,NFFT));
Y_filter = fftshift(fft(y_filter,NFFT));
Y_filtfilt = fftshift(fft(y_filtfilt,NFFT));
figure;
subplot(3,1,1);
plot(f, abs(X));
title('Input Signal Spectrum (Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;
subplot(3,1,2);
plot(f, abs(Y_filter));
title('Filtered Signal Spectrum using filter()');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
grid on;
ZUBAIR KHAN 02-133222-048 BEE 6-B
subplot(3,1,3);
plot(f, abs(Y_filtfilt));
title('Filtered Signal Spectrum using filtfilt()');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
grid on;

FIGURE

You might also like