DSP Lab Manual
DSP Lab Manual
(Approved by AICTE, New Delhi, Accredited by NBA, New Delhi & Affiliated to VTU, Belgaum)
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
LAB MANUAL
Mission
CO.1 Analyse the different types of signals and systems used in digital signal processing.
CO.2 Compute the response of an LTI system using time and frequency domain
techniques.
CO.3 Develop algorithms for the efficient computations of DFT and IDFT.
CO.4 Design of digital FIR filters for the given specifications using different window
methods.
CO.5 Design of digital IIR digital filters using bilinear transformation method.
CO-PO MAPPING
PO P0- P0- P0- P0- P0- P0- P0- P0- P0- P0- P0- P0-
CO 1 2 3 4 5 6 7 8 9 10 11 12
CO1 2 1 - 1 - - - - - - - 1
CO2 3 2 2 1 - - - - - - - 1
CO3 2 1 - 1 - - - - - - - 1
CO4 3 2 2 1 - - - - - - - 1
CO5 2 1 - 1 - - - - - - - 1
CO-PSO MAPPING
CO PSO1 PSO2 PSO3
CO1 1 - -
CO2 1 - -
CO3 1 - -
CO4 1 - -
CO5 1 - -
The Oxford College of Engineering, Bommanahalli, Bangalore
Syllabus
The Oxford College of Engineering, Bommanahalli, Bangalore
MATLAB
MATLAB is a high-performance language for technical computing. It integrates computation,
visualization, and programming in an easy-to-use environment where problems and solutions are
expressed in familiar mathematical notation. Typical uses include: Math and computation .
Experiment No:1
a.Unit Sample Sequence: δ[n]=1 for n=0, and δ[n]=0 for all other values of n
b.Unit Step Sequence: u[n]=1 for n≥0, and u[n]=0 for n<0.
8
The Oxford College of Engineering, Bommanahalli, Bangalore
A = 1; % Amplitude
alpha = 0.3; % Exponential rate
exp_seq = A * exp(alpha * n);
figure;
stem(n, exp_seq);
title('Exponential Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;
e.Random Sequence
n = 0:20; % Range for n
random_seq = rand(1, length(n)); % Generate random numbers between 0 and 1
figure;
stem(n, random_seq);
title('Random Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;
9
The Oxford College of Engineering, Bommanahalli, Bangalore
Result:
10
The Oxford College of Engineering, Bommanahalli, Bangalore
11
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:2
2. Program to perform the following operations on signals.
a) Signal addition,
b) Signal multiplication,
c)Scaling,
d) Shifting,
e)Folding
a.Signal Addition
n = 0:10; % Time index
% Signal Addition
x_add = x1 + x2;
% Plot
figure;
subplot(3,1,1);
stem(n, x1);
title('Signal 1: sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
subplot(3,1,2);
stem(n, x2);
title('Signal 2: cos(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
subplot(3,1,3);
12
The Oxford College of Engineering, Bommanahalli, Bangalore
stem(n, x_add);
title('Signal Addition: x_1[n] + x_2[n]');
xlabel('n');
ylabel('Amplitude');
grid on;
b.Signal Multiplication
% Signal Multiplication
x_mul = x1 .* x2; % Element-wise multiplication
% Plot
figure;
subplot(3,1,1);
stem(n, x1);
title('Signal 1: sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
stem(n, x2);
title('Signal 2: cos(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(3,1,3);
stem(n, x_mul);
title('Signal Multiplication: x_1[n] \cdot x_2[n]');
xlabel('n');
ylabel('Amplitude');
grid on;
13
The Oxford College of Engineering, Bommanahalli, Bangalore
% Signal Scaling
scale_factor = 2;
x_scaled = scale_factor * x1;
% Plot
figure;
subplot(2,1,1);
stem(n, x1);
title('Original Signal: sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, x_scaled);
title('Scaled Signal: 2 \cdot sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
% Plot
figure;
subplot(2,1,1);
stem(n, x1);
title('Original Signal: sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
14
The Oxford College of Engineering, Bommanahalli, Bangalore
subplot(2,1,2);
stem(n, x_shifted);
title('Shifted Signal: sin(0.2 \pi (n-3))');
xlabel('n');
ylabel('Amplitude');
grid on;
% Plot
figure;
subplot(2,1,1);
stem(n, x1);
title('Original Signal: sin(0.2 \pi n)');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, x_folded);
title('Folded Signal: sin(0.2 \pi (-n))');
xlabel('n');
ylabel('Amplitude');
grid on;
15
The Oxford College of Engineering, Bommanahalli, Bangalore
Results:
16
The Oxford College of Engineering, Bommanahalli, Bangalore
17
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:3
3. Program to perform convolution of two given sequences (without using built-in function)
and display the signals
18
The Oxford College of Engineering, Bommanahalli, Bangalore
for j = 1:N1
if (i - j + 1 > 0 && i - j + 1 <= N2)
y(i) = y(i) + x1(j) * x2(i - j + 1);
end
end
end
grid on;
Results:
Experiment No:4
Consider a causal system y(n) = 0.9y(n-1) +x(n).
a) Determine H(z) and sketch its pole zero plot.
b) Plot |H(ejω)| and ∠ H(ejω)
c) Determine the impulse response h(n).
This system represents a recursive relationship where the current output depends on the previous
output and the current input.
Determine H(z)H(z)H(z) and sketch its pole-zero plot
20
The Oxford College of Engineering, Bommanahalli, Bangalore
21
The Oxford College of Engineering, Bommanahalli, Bangalore
grid on;
Plot |H(ejω)| and ∠ H(ejω)
% Frequency range
omega = linspace(-pi, pi, 1000);
22
The Oxford College of Engineering, Bommanahalli, Bangalore
23
The Oxford College of Engineering, Bommanahalli, Bangalore
24
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:5
Computation of N point DFT of a given sequence (without using built-in function) and to
plot the magnitude and phase spectrum.
The Discrete Fourier Transform (DFT) of a sequence can be computed manually without using the
built-in fft function. Here's how to compute the N-point DFT of a given sequence and plot its
magnitude and phase spectra.
% Given sequence
x = [1, 2, 3, 4, 8, 3, 1]; % Example input sequence
N = length(x); % Length of the sequence (can modify this for N-point DFT)
25
The Oxford College of Engineering, Bommanahalli, Bangalore
26
The Oxford College of Engineering, Bommanahalli, Bangalore
Results:
Experiment No:6
Using the DFT and IDFT, compute the following for any two given sequences
a) Circular convolution
b) Linear convolution
Circular Convolution:
The sequences are zero-padded to the length of the longest sequence.
The DFT of both sequences is computed using the fft() function.
The element-wise product of the DFTs is taken to perform circular convolution.
Finally, the IDFT of the result is computed using ifft() to get the circular convolution
output.
Linear Convolution:
The sequences are zero-padded to the length N1+N2−1 to avoid overlap and to ensure linear
convolution.
The DFT of both zero-padded sequences is computed.
The element-wise product of the DFTs is taken, followed by the IDFT of the result to
obtain the linear convolution.
% Define two sequences
x = [1, 2, 3]; % First sequence
h = [4, 5, 6]; % Second sequence
N1 = length(x);
N2 = length(h);
%% Circular Convolution
% Choose N as the maximum length between the two sequences
N_circular = N1+N2-1;
%% Linear Convolution
% Choose N for linear convolution as N1 + N2 - 1 (full length)
N_linear = N1 + N2 - 1;
29
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:7.
Verification of Linearity property, circular time shift property & circular frequency shift
property of DFT.
30
The Oxford College of Engineering, Bommanahalli, Bangalore
% Length of sequences
N = length(x);
%% Linearity Property
a = 2; % Constant multiplier for x
b = 3; % Constant multiplier for y
% DFT of x and y
X = fft(x);
Y = fft(y);
% Verification of linearity
disp('Linearity Property Verification:');
disp('DFT of (a*x + b*y):');
disp(left_side);
disp('a*DFT(x) + b*DFT(y):');
disp(right_side);
31
The Oxford College of Engineering, Bommanahalli, Bangalore
X[k] * exp(-j*2*pi*k*m/N):
10.0000 + 0.0000i 2.0000 + 2.0000i 2.0000 + 0.0000i 2.0000 - 2.0000i
Experiment No 8
Develop decimation in time radix-2 FFT algorithm without using built-in functions.
The Decimation in Time (DIT) Radix-2 Fast Fourier Transform (FFT) is an efficient algorithm for
computing the Discrete Fourier Transform (DFT) by recursively breaking down the DFT of a
sequence into smaller DFTs. This algorithm is designed for sequences whose length NNN is a
power of 2. Here is a step-by-step explanation and MATLAB implementation of the DIT Radix-2
FFT without using built-in functions.
Steps of the DIT Radix-2 FFT Algorithm
1. Bit-Reversal Reordering: First, rearrange the input sequence into bit-reversed order to
prepare for the butterfly calculations.
2. Butterfly Calculations: Use butterfly operations to combine the results of smaller DFTs
into larger ones.
3. Recursive Decimation in Time: Process the even and odd parts of the signal separately at
each stage and combine them using the butterfly structure.
close all
clc
% dit_radix2_fft.m
x = [1, 2, 3, 4, 5, 6, 7, 8]; % Input signal (length should be a power of 2)
X = dit_radix2_fft(x); % Compute DFT using custom FFT
disp('Input Sequence');
disp(x)
disp('DFT of the input sequence:');
disp(X);
function X = dit_radix2_fft(x)
% DIT Radix-2 FFT Implementation without built-in functions
% Input: x - input sequence (length must be a power of 2)
% Output: X - DFT of the input sequence
if mod(log2(N), 1) ~= 0
error('Length of input sequence must be a power of 2');
end
% Bit-reversal ordering
X = bit_reverse_reorder(x);
for s = 1:stages
% Number of butterflies in this stage
m = 2^s;
% Twiddle factor (complex exponential for FFT)
wm = exp(-2i * pi / m);
34
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:9.
Design and implementation of digital low pass FIR filter using a window to meet the given
specifications
Step-by-Step Design
1. Filter Specifications: Define key parameters:
Sampling Frequency (fs): Determines the Nyquist frequency (fN=fs/2).
Cutoff Frequency (fc): The desired maximum frequency to pass.
Filter Order (N): Determines the sharpness of the transition band.
Window Type: Choose a window function (e.g., Hamming, Hanning, Kaiser).
2. Window Method:
35
The Oxford College of Engineering, Bommanahalli, Bangalore
MATLAB Implementation
Example Specifications
Sampling Frequency (fs=2000 Hz)
Cutoff Frequency (fc=300 Hz)
Filter Order (N=50)
Window: Hamming
% Specifications
fs = 2000; % Sampling frequency in Hz
fc = 300; % Cutoff frequency in Hz
N = 50; % Filter order (should be even for linear phase)
Wn = fc / (fs / 2); % Normalized cutoff frequency
% Frequency response
[H, f] = freqz(b, 1, 1024, fs); % 1024-point FFT for frequency response
36
The Oxford College of Engineering, Bommanahalli, Bangalore
figure;
plot(f, abs(H));
title('Magnitude Response of FIR Low-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
37
The Oxford College of Engineering, Bommanahalli, Bangalore
Results:
38
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:10.
Design and implementation of digital high pass FIR filter using a window to meet the given
specifications.
Steps for High-Pass FIR Filter Design
1. Filter Specifications:
Sampling frequency (fs)
Cutoff frequency (fc) above which frequencies should pass
Filter order (N), affecting transition width and ripple
Window type (e.g., Hamming, Hanning, Kaiser)
2. Normalized Frequency:
Normalize the cutoff frequency to the Nyquist frequency: Wn=fc/(fs/2).
3. Ideal Impulse Response:
High-pass filter's impulse response is derived from the sinc function by subtracting
the low-pass response from an impulse (δ[n]−sinc(t)).
4. Window Application:
Multiply the ideal impulse response by a window function to reduce ripples.
5. Implementation and Plotting:
Compute and plot the impulse response, magnitude response, and phase response.
MATLAB Code
Example Specifications
Sampling Frequency (fs=2000Hz)
Cutoff Frequency (fc=500Hz)
Filter Order (N=50)
Window: Hamming
% Filter Specifications
fs = 2000; % Sampling frequency in Hz
fc = 500; % Cutoff frequency in Hz
N = 50; % Filter order (even for linear phase FIR)
Wn = fc / (fs / 2); % Normalized cutoff frequency
39
The Oxford College of Engineering, Bommanahalli, Bangalore
% Frequency Response
[H, f] = freqz(b, 1, 1024, fs); % Frequency response using 1024-point FFT
40
The Oxford College of Engineering, Bommanahalli, Bangalore
41
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:11.
Design and implementation of digital IIR Butterworth low pass filter to meet the given
specifications.
An IIR Butterworth filter has a maximally flat frequency response in the passband and is
commonly used for applications where a smooth and monotonic filter response is required.
Specifications to Define
1. Filter Type: Low-pass.
2. Filter Order (N): Determines the roll-off steepness.
3. Cutoff Frequency (fc): The frequency below which signals pass.
4. Sampling Frequency (fs): For digital implementation.
5. Passband and Stopband Characteristics:
Passband ripple (ϵ).
Stopband attenuation (As).
Steps to Design Butterworth Filter
1. Convert Specifications to Digital Domain:
Normalize the cutoff frequency: Wn=fc/(fs/2).
2. Determine Filter Order:
Based on passband ripple and stopband attenuation.
3. Compute Filter Coefficients:
Use the butter function in MATLAB.
4. Analyze the Filter:
Plot frequency response (magnitude and phase).
42
The Oxford College of Engineering, Bommanahalli, Bangalore
MATLAB Implementation
Example Specifications
Sampling Frequency (fs=1000Hz)
Cutoff Frequency (fc=200Hz)
Filter Order (N=4)
% Specifications
fs = 1000; % Sampling frequency (Hz)
fc = 200; % Cutoff frequency (Hz)
N = 4; % Filter order
Wn = fc / (fs / 2); % Normalized cutoff frequency
% Frequency Response
[H, f] = freqz(b, a, 1024, fs); % Frequency response
% Impulse Response
impulse = [1, zeros(1, 49)]; % Delta function (impulse)
h = filter(b, a, impulse); % Impulse response
figure;
stem(0:49, h, 'filled');
title('Impulse Response of Butterworth Low-Pass Filter');
xlabel('n');
ylabel('Amplitude');
grid on;
% Step Response
step = ones(1, 50); % Unit step function
s = filter(b, a, step); % Step response
figure;
stem(0:49, s, 'filled');
title('Step Response of Butterworth Low-Pass Filter');
xlabel('n');
ylabel('Amplitude');
grid on;
Results:
44
The Oxford College of Engineering, Bommanahalli, Bangalore
45
The Oxford College of Engineering, Bommanahalli, Bangalore
Experiment No:12.
Design and implementation of digital IIR Butterworth high pass filter to meet the given
specifications
MATLAB Implementation
Example Specifications:
Sampling Frequency: fs=1000Hz
Cutoff Frequency: fc=200 Hz
Filter Order: N=4
% Specifications
fs = 1000; % Sampling frequency (Hz)
fc = 200; % Cutoff frequency (Hz)
N = 4; % Filter order
Wn = fc / (fs / 2); % Normalized cutoff frequency
% Frequency Response
[H, f] = freqz(b, a, 1024, fs); % Frequency response
46
The Oxford College of Engineering, Bommanahalli, Bangalore
figure;
plot(f, abs(H));
title('Magnitude Response of Butterworth High-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
% Impulse Response
impulse = [1, zeros(1, 49)]; % Delta function (impulse)
h = filter(b, a, impulse); % Impulse response
figure;
stem(0:49, h, 'filled');
title('Impulse Response of Butterworth High-Pass Filter');
xlabel('n');
ylabel('Amplitude');
grid on;
% Step Response
step = ones(1, 50); % Unit step function
s = filter(b, a, step); % Step response
figure;
stem(0:49, s, 'filled');
title('Step Response of Butterworth High-Pass Filter');
xlabel('n');
ylabel('Amplitude');
grid on;
47
The Oxford College of Engineering, Bommanahalli, Bangalore
Customizations
1. Stopband Attenuation:
Increase N to achieve higher stopband attenuation but at the cost of computational
complexity.
2. Different Filter Types:
Replace 'high' with 'low', 'bandpass', or 'stop' for other filter types.
3. Windowed Design:
For a finite impulse response (FIR) alternative, consider designing using window
methods (like Hamming or Kaiser).
Results:
48
The Oxford College of Engineering, Bommanahalli, Bangalore
49