0% found this document useful (0 votes)
15 views22 pages

Him (1) 122

study

Uploaded by

rahulrkl856
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)
15 views22 pages

Him (1) 122

study

Uploaded by

rahulrkl856
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/ 22

Department of Electronics and communication

University of Allahabad

LAB ASSIGNMENT
for
B.TECH. 6th SEMESTER C.S.E (2023-24)
of
BEC 607: Digital Signal Processing Lab

NAME: - Rahul kumar


ROLL NO.- 10
Enrolment Number: - U2151022

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 Linear convolution of two function 5


3 Circular convolution of two function 6
4 Cross Correlation between two sequences. 7
5 N-point DFT sequence with Power spectral density 9
6 N point DIT-FFT of a given sequence and frequency response 10
7 N- point IFFT of a given sequence 12
8 Gaussian number generation 14
9 FIR lowpass filter with given specification and verify the magnitude, 15
phase and impulse response using FDA toolbox
10 FIR filter (Low Pass Filter /High Pass Filter) using windowing technique. 16
Using (i) rectangular window (ii). Hamming window (iii). Kaiser window
11 IIR lowpass Butterworth filter with following specification and verify 18
magnitude, phase and impulse response using FDA tool
12 Linear convolution of two sequences using 19
overlap and add method.
13 Compute the decimation and interpolation for the given signal. 20
14 Impulse response of first order and second order systems. 21

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:

Continuous time unit impulse signal Unit step signal


amplitude--->

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];

% Perform circular convolution (code remains the same)

% Plot the results


figure; % Create a new figure window
stem(0:length(y_circ)-1, y_circ); % Adjust x-axis range if needed
hold on;
stem(0:length(y_verify)-1, y_verify); % Adjust x-axis range if needed
legend('Custom', 'Verification');
xlabel('Time Index (n)');
ylabel('Amplitude');
title('Circular Convolution Results');
grid on;

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];

% Perform cross-correlation using built-in function


corr_result = xcorr(x, h);

% Plot sequences x(n) and h(n)


subplot(3,1,1);
stem(0:length(x)-1, x);
title('Sequence x(n)');
xlabel('n');
ylabel('Amplitude');

subplot(3,1,2);
stem(0:length(h)-1, h);
title('Sequence h(n)');
xlabel('n');
ylabel('Amplitude');

% Plot cross-correlation result


subplot(3,1,3);
stem(-(length(x)-1):(length(h)-1), corr_result);
title('Cross-correlation Result');
xlabel('Lag (L)');
ylabel('Correlation');

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];

% Compute the N-point DFT using FFT


N = length(x);
X = fft(x, N);

% Compute the power density spectrum


P = abs(X).^2 / N^2;

% Plot the power density spectrum


frequencies = (0:N-1) / N; % Frequency axis
stem(frequencies, P);
title('Power Density Spectrum');
xlabel('Frequency (cycles/sample)');
ylabel('Power');

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

% Generate Gaussian distributed numbers


gaussian_numbers = normrnd(mean_value, sqrt(variance_value), num_samples, 1);

% Plot the PDF


histogram(gaussian_numbers, 'Normalization', 'pdf');
title('Probability Density Function (PDF)');
xlabel('Value');
ylabel('Probability Density');

14
Experiment 9:
Design a FIR lowpass filter with given specification and verify the magnitude, phase
and impulse response using FDA toolbox.

% Define filter specifications


filter_order = 40; % Filter order
cutoff_frequency = 0.2; % Cutoff frequency (normalized frequency)
transition_width = 0.1; % Transition width (normalized frequency)
% Design FIR lowpass filter
b = firpm(filter_order, [0, cutoff_frequency, cutoff_frequency + transition_width, 0.5], [1, 1,
0, 0]);
% Plot magnitude response
figure;
freqz(b, 1);
% Plot phase response
figure;
freqz(b, 1, 'whole');
% Plot impulse response
figure;
impz(b, 1);

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

% Design FIR LPF using Rectangular Window


lpf_rect = fir1(filter_order, cutoff_frequency);

% Design FIR HPF using Rectangular Window


hpf_rect = fir1(filter_order, cutoff_frequency, 'high');

% Hamming Window
hamming_window = hamming(filter_order+1); % Hamming window coefficients

% Design FIR LPF using Hamming Window


lpf_hamming = fir1(filter_order, cutoff_frequency, hamming_window);

% Design FIR HPF using Hamming Window


hpf_hamming = fir1(filter_order, cutoff_frequency, 'high', hamming_window);
beta = 5; % Kaiser window parameter
kaiser_window = kaiser(filter_order+1, beta); % Kaiser window coefficients
lpf_kaiser = fir1(filter_order, cutoff_frequency, kaiser_window);
hpf_kaiser = fir1(filter_order, cutoff_frequency, 'high', kaiser_window);

% Plot frequency responses


figure;
subplot(3, 2, 1);
freqz(lpf_rect);
title('LPF using Rectangular Window');
subplot(3, 2, 2);
freqz(hpf_rect);
title('HPF using Rectangular Window');

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)

% Design Butterworth lowpass filter


[b, a] = butter(filter_order, cutoff_frequency);

% Plot magnitude response


figure;
freqz(b, a);

% Plot phase response


figure;
freqz(b, a, 'whole');

% Plot impulse response


figure;
impz(b, a);

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);

% Block size (must be greater than or equal to Nh)


if L < Nh
error('Block size L must be greater than or equal to filter length Nh');
end

% Number of blocks (rounded up)


Nb = ceil((Nx + L - Nh) / L);

% Overlap (same as block size L)


Ov = L;Ny = Nx + Nh - 1;

% 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

% Overlap-and-add to the output


n_out = (i - 1) * Ov + 1 : (i - 1) * Ov + L;
y(n_out) = y(n_out) + y_block(1:L);
end
end
x = [1 2 3 4 5]; % Your sequence (replace with your data)
h = [1 0 2 1]; % Your filter (replace with your data)
L = 4; % Block size (adjust as needed)

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.

function [y_decimated, y_interpolated] = decimate_interpolate(x, N)


% Decimation
y_decimated = x(1:N:end);

% 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];

% Define the decimation/interpolation factor


N = 2;

% Perform decimation and interpolation


[y_decimated, y_interpolated] = decimate_interpolate(x, N);

% Display the results


disp('Decimated Signal:');
disp(y_decimated);

disp('Interpolated Signal:');
disp(y_interpolated);

20
Experiment 14:- Impulse response of first order and second order systems

Impulse response of dynamic systems:


% MATLAB code for defining state variables
a = [-0.45572,-0.732814; 0.732814,0];
b = [-1, 1; 2 -3];
c = [0.2 -3.543];

% Creating state-space system using ss function.


sys = ss(a, b, c, 0);

% Calculating impulse response for the above system;


impulse(sys)

Output:

This would show the impulse response as a graphical signal.

Impulse Response of a Digital Filter:


% MATLAB code for Digital filter
[b,a] = ellip(5,0.23,23,0.55);

% Calculating impulse response


% with 75 sample points
impz(b,a,75)

21
Output:

This calculates impulse response at of the elliptic filter at fifth


order for 75 sample points.

21

You might also like