Him (1) 122
Him (1) 122
University of Allahabad
LAB ASSIGNMENT
for
B.TECH. 6th SEMESTER C.S.E (2023-24)
of
BEC 607: Digital Signal Processing Lab
1
Index: -
S.No Index Page
No.
1 Representation of 3
(i) Unit sample sequence, (ii) Unit step sequence, (iii) Ramp sequence (iv)
Exponential sequence (v) sine sequence (vi) cosine sequence.
2
Experiment 1 :-
1. Plot the following sequences(i) Unit sample sequence, (ii) Unit step sequence, (iii) Ramp
sequence (iv)Exponential sequence (v) sine sequence (vi) cosine sequence.
Also, down sample each of the above sequences and plot.
clc;
clear all;
close all;
t=-10:0.01:10;
L=length(t);
for i=1:L
% to generate a continuous time impulse function
if t(i)==0
x1(i)=1;
else
x1(i)=0;
end;
% to generate a continuous time unit step signal
if t(i)>=0
x2(i)=1;
% to generate a continuous time ramp signal
x3(i)=t(i);
else
x2(i)=0;
x3(i)=0;
end;
end;
% to generate a continuous time exponential signal
a=0.85;
x4=a.^t;
figure;
subplot(3,2,1);
plot(t,x1);
grid on;
xlabel('continuous time t --- >');
ylabel('amplitude --- >');
title('Continuous time unit impulse signal');
subplot(3,2,2);
plot(t,x2);
grid on;
xlabel('continuous time t --- >');
ylabel('amplitude --- >');
title('Unit step signal')
subplot(3,2,3);
plot(t,x3);
grid on;
xlabel('continuous time t --- >');
ylabel('amplitude --- >');
title(' Unit ramp signal');
3
subplot(3,2,4);
plot(t,x4);xlabel('continuous time t ---- >');
grid on;
ylabel('amplitude --- >');
title('continuous time exponential signal');
% to generate a continuous time signum function
a=sign(t);
subplot(3,2,[5,6]);
plot(t,a);grid on;
xlabel('continuous time t ----- >');
ylabel('amplitude ---->');
title('continuous time signum function');
figure;
% to generate a continuous time sinc function
t=-10:.1:10;
Wt=sinc(t);
plot(t,Wt);
grid on;
xlabel('continuous time t ------->');
ylabel('amplitude ---->');
title('continuous time sinc function');
RESULTS:
1 1
amplitude--->
0.5 0.5
0 0
-10 -5 0 5 10 -10 -5 0 5 10
continuous time t ---- > continuous time t --- >
Unit ramp signal continuous time exponential signal
amplitude --->
10
amplitude --->
10
5 5
0 0
-10 -5 0 5 10 -10 -5 0 5 10
continuous time ct o--n-t-i>nuous time signum funccotniotin uous time t ----- >
1
amplitude---- >
-1
-10 -8 -6 -4 -2 0 2 4 6 8 10
continuous time t ------>
4
Experiment 2:-
Write a MATLAB program to perform linear convolution of two sequences x(n) and h(n).
Also verify the result using inbuilt functions.
p=input('Enter the limit for x');
q=input('Enter the limit for y');
x=input('Enter the elements for x');
y=input('Enter the elements for y');
n1=0:p ;
n2=0:q;
subplot(3,1,1);
stem(n1,x);
title('Signal - x(n)');
subplot(3,1,2);
stem(n2,y);
title('Signal - h(n)');
z=conv(x,y);
t=length(n1)+length(n2)-1;
s=0:t-1;
subplot(3,1,3);
stem(s,z);
title('Output - y(n)');
OUTPUT:
5
Experiment 3 :-
Write a MATLAB program to perform circular convolution of two sequences x(n) and
h(n). Also verify the result using inbuilt functions.
% Define sequences x(n) and h(n) (same as before)
n = 0:9;
x = [1 2 3 0 0 1 2 3 1];
h = [1 0 2 1];
6
Experiment 4:-
Write a MATLAB program to perform cross correlation between two sequences x(n) and h(n). Also verify
the result using inbuilt functions.
% Definesequences x(n) and h(n)
x = [1, 2, 1, 1];
h = [1, -1, 1];
subplot(3,1,2);
stem(0:length(h)-1, h);
title('Sequence h(n)');
xlabel('n');
ylabel('Amplitude');
7
8
Experiment 5 :-
Compute and implement the N-point DFT of a given sequence and compute the power
density spectrum of the sequence.
% Define the sequence
x = [1, 2, 3, 4,6];
9
10
11
12
13
Experiment 8:-
Write a MATLAB program to generate Gaussian numbers with given mean and
variance. Plot the PDF of the generated numbers.
% Parameters
mean_value = 2; % Mean of the Gaussian distribution
variance_value = 3; % Variance of the Gaussian distribution
num_samples = 1000; % Number of samples to generate
14
Experiment 9:
Design a FIR lowpass filter with given specification and verify the magnitude, phase
and impulse response using FDA toolbox.
15
Experiment 10
Design FIR filter (Low Pass Filter /High Pass Filter) using windowing technique.
Using (i) rectangular window (ii). Hamming window (iii). Kaiser window
filter_order = 50; % Filter order
cutoff_frequency = 0.2; % Cutoff frequency (normalized frequency)
transition_width = 0.1; % Transition width (normalized frequency)
% Rectangular Window
rect_window = ones(filter_order+1, 1); % Rectangular window coefficients
% Hamming Window
hamming_window = hamming(filter_order+1); % Hamming window coefficients
subplot(3, 2, 3);
freqz(lpf_hamming);
title('LPF using Hamming Window');
subplot(3, 2, 4);
freqz(hpf_hamming);
title('HPF using Hamming Window');
subplot(3, 2, 5);
freqz(lpf_kaiser);
title('LPF using Kaiser Window');
subplot(3, 2, 6);
16
freqz(hpf_kaiser);
tite('HPF using Kaiser Window');
17
Experiment 11:-
Design a IIR lowpass Butterworth filter with following specification and verify
magnitude, phase and impulse response using FDA tool.
% Define filter specifications
filter_order = 4; % Filter order
cutoff_frequency = 0.2; % Cutoff frequency (normalized frequency)
18
Experiment 12
Write a MATLAB program to perform linear convolution of two sequences using
overlap and add method
function y = overlap_add(x, h, L)
% Performs linear convolution of x(n) and h(n) using overlap-add method
% Lengths of sequences
Nx = length(x);
Nh = length(h);
% Initialize output
y = zeros(1, Ny);
for i = 1:Nb
n_start = (i - 1) * L + 1;
x_start = max(1, n_start - Ov + 1);
h_start = 1;
n_end = min(Nx, n_start + L - 1);
x_block = zeros(1, L);
x_block(x_start:n_end) = x(x_start:n_end);
X_block = fft(x_block, L);
H = fft(h, L);
Y_block = X_block .* H;
y_block = real(ifft(Y_block, L)); % Take real part for linear convolution
y = overlap_add(x, h, L);
y_verify = conv(x, h);
disp('Output using Overlap-Add Method:');
disp(y);
19
Q.13 Compute the decimation and interpolation for the given signal.
% Interpolation
x_interpolated = zeros(1, length(x)*N);
x_interpolated(1:N:end) = x;
y_interpolated = conv(x_interpolated, ones(1, N), 'same') / N;
end
% Define the input signal
x = [1, 2, 3, 4, 5, 6, 7, 8];
disp('Interpolated Signal:');
disp(y_interpolated);
20
Experiment 14:- Impulse response of first order and second order systems
Output:
21
Output:
21