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

DSP - LAB-2, 3, 4 and 5 - Report

Uploaded by

test
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

DSP - LAB-2, 3, 4 and 5 - Report

Uploaded by

test
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Name: - Aayush Aamod Dixit

PRN number: - 20190802024


Subject: - Digital Signal Processing
Course: - B.Tech CSE

Lab Experiment – 02

Aim: IMPLEMENTATION OF OPERATION ON SEQUENCES (ADDITION,


MULTIPLICATION, SCALING, SHIFTING, FOLDING ETC).

Apparatus: MATLAB

Program:

1) Addition of two Sinusoidal Sequences

a) Code

%Q1. Addition of Sinusoidal Sequences

clc;
clear all;
close all;
N=40;
n=0:1:N-1;
eq1 = sin(0.5*pi*n);
eq2 = sin(0.7*pi*n);
sm = eq1 + eq2;
subplot(2,1,1),stem(n, sm);
subplot(2,1,2),plot(n, sm);
xlabel('n');ylabel('sm');
title('Addition of two Sinusoidal Sequences');

b) Code and Output Screenshot


2) Multiplication of two Sinusoidal Sequences

a) Code

%Q2. Multiplication of Sinusoidal Sequences

clc;
clear all;
close all;
N=40;
n=0:1:N-1;
eq1 = sin(0.5*pi*n);
eq2 = sin(0.7*pi*n);
ml = eq1 .* eq2;
subplot(2,1,1),stem(n, ml);
subplot(2,1,2),plot(n, ml);
xlabel('n');ylabel('ml');
title('Multiplication of two Sinusoidal Sequences');

b) Code and Output Screenshot


3) Scaling of Signal

a) Code

%Q3. Scaling of Signal

clc;
clear all;
close all;
N=5;
l1=[1 2 3 4 5 6 7 8];
a=length(l1);
n=0:1:a-1;
subplot(3,1,1);
stem(l1);
xlabel('Number of Samples');ylabel('Amplitude');
title('Input Signal');
l2=N*l1;
subplot(3,1,2);
stem(l2);
xlabel('Number of Samples');ylabel('Amplitude');
title('Amplified Signal');
l3=l1/N;
subplot(3,1,3);
stem(l3);
xlabel('Number of Samples');ylabel('Amplitude');
title('Attenuated Signal');
display(l1);
display(l2);
display(l3);
b) Code and Output Screenshot

4) Shifting and Non-function Discrete-Time Signal

a) Code

%Q4. Shifting a Non-Function Discrete-Time Signal

clc;
clear all;
close all;
n = 0:8;
x = [0 1 6 3 2 7 1 4 5];
subplot(2,1,1);
stem(n,x);
title('x(n) Signal');
xlabel('n'); ylabel('x(n)');
m=n+2;
y=x;
subplot(2,1,2);
stem(m,y);
title('y(n)=x(n-2) Signal');
xlabel('n'); ylabel('y(n)');
b) Code and Output Screenshot

5) Folding or Flipping of Sequence

a) Code

%Q5. Folding or Flipping of Sequence

clc;
clear all;
close all;
n=0:8;
x=[0 2 4 6 3 1 7 5 3];
subplot(2,1,1);
stem(n,x),title('x(n) Signal');
xlabel('n');ylabel('x(n)');
m=fliplr(n);
y=fliplr(x);
subplot(2,1,2);
stem(m,y),title('y(n) = - x(n) Signal');
xlabel('n');ylabel('y(n)');
b) Code and Output Screenshot

6) Subtraction of two Sinusoidal Sequences

a) Code

%Q6. Subtraction of two Sinusoidal Sequences

clc;
clear all;
close all;
N=40;
n=0:1:N-1;
eq1 = sin(0.5*pi*n);
eq2 = sin(0.7*pi*n);
sb = eq1 - eq2;
subplot(2,1,1),stem(n, sb);
subplot(2,1,2),plot(n, sb);
xlabel('n');ylabel('sb');
title('Subtraction of two Sinusoidal Sequences');
b) Code and Output Screenshot

7) Division of two Sinusoidal Sequences

a) Code

%Q7. Division of two Sinusoidal Sequences

clc;
clear all;
close all;
N=40;
n=0:1:N-1;
eq1 = sin(0.5*pi*n);
eq2 = sin(0.7*pi*n);
dv = eq1 ./ eq2;
subplot(2,1,1),stem(n, dv);
subplot(2,1,2),plot(n, dv);
xlabel('n');ylabel('dv');
title('Division of two Sinusoidal Sequences');
b) Code and Output Screenshot

Conclusion:
Thus, we have successfully implemented all the signals in MATLAB.
Lab Experiment – 03
IMPLEMENTATION OF DISCRETE-TIME SYSTEMS

Aim: To find the impulse response of a system with the transfer function
y(n)+1/2y(n-1) + 1/3y(n-2) = x(n).

Apparatus: MATLAB

Program:
IMPULSE RESPONSE OF SYSTEM FOR GIVEN TRANSFER FUNCTION
y(n)+1/2y(n-1) + 1/3y(n-2) = x(n).

a) Code
% IMPULSE RESPONSE OF SYSTEM FOR GIVEN TRANSFER
FUNCTION
% y(n)+1/2y(n-1) + 1/3y(n-2) = x(n).

clc;
clear all;
close all;
b=[1];
a=[1;1/2;1/3];
h=impz(a,b,4);
disp('Impulse Response h(n)');
disp(h);
n1=0:1:length(h)-1;
subplot(2,1,1);
stem(n1,h);
xlabel('n1');ylabel('x(n)');
title('Impulse Response h(n)');
x=[1,2];
y=conv(h,x);
disp('Output y(n)');
disp(y);
n2=0:1:length(y)-1;
subplot(2,1,2);
stem(n2,y);
xlabel('n2');ylabel('Amplitude');
title('Output y(n)');

b) Code and Output Screenshot

Conclusion:
Thus, the generation of impulse sequence for given difference
equation is simulated using MATLAB.

VIVA

1. What is meant by impulse response of a system?

2. How to generate impulses using MATLAB?

3. What is the role of convolution in finding the impulse response of a


system?
4. What is an LTI system?

ANSWERS:

1. In signal processing, the impulse response, or impulse response


function (IRF), of a dynamic system is its output when presented
with a brief input signal, called an impulse.

2. >> freq = fft(impulse Train, Len);


>> stem([(0:Len-1)/(Len*Ts)], abs(freq)).

3. Convolution is a very powerful technique that can be used to


calculate the zero state response (i.e., the response to an input
when the system has zero initial conditions) of a system to an
arbitrary input by using the impulse response of a system.

4. Linear time-invariant system theory, commonly known as LTI


system theory, comes from applied mathematics and has direct
applications in NMR spectroscopy, seismology, circuits, signal
processing, control theory, and other technical areas. It investigates
the response of a linear and time-invariant system to an arbitrary
input signal. Trajectories of these systems are commonly measured
and tracked as they move through time (e.g., an acoustic
waveform)
Lab Experiment – 04

Aim: To generate Convolution from the given sequences.

Apparatus: MATLAB

Program:
1. Question 1

a) Code

%1

clc ;
clear all ;
close all ;
x=[1,1,1,1];
N1=length(x);
n1=0:1:N1-1;
subplot(2,2,1),
stem(n1,x);
xlabel('n1');
ylabel('x(n1)');
title('Input sequence 1');
x2=[1,1,1,1];
N2=length(x2);
n2=0:1:N2-1;
subplot(2,2,2),
stem(n2,x2);
xlabel('n2');
ylabel('x(n2)');
title('Input sequence 2');
y=conv(x,x2);
n=0:1:length(y)-1;
subplot(2,1,2),stem(n,y);
xlabel('n');
ylabel('y(n)');
title('Convolution of x(n)*x2(n)');

b) Code and Output Screenshot


2. Question 2

a) Code

%2

clc ;
clear all ;
close all ;
x=[1,1,0,1,1];
N1=length(x);
n1=-2:1:2;
subplot(2,2,1),
stem(n1,x);
xlabel('n1');
ylabel('x(n1)');
title('Input Sequence 1');
h=[1,-2,-3,4];
N2=length(h);
n2=-3:1:0;
subplot(2,2,2),
stem(n2,h);
xlabel('n2');
ylabel('x(n2)');
title('Input Sequence 2');
y=conv(x,h);
n=0:1:length(y)-1;
subplot(2,1,2),stem(n,y);
xlabel('n');
ylabel('y(n)');
title('Convolution of x(n)*h(n)');
b) Code and Output Screenshot

Conclusion:
Thus, we have successfully implemented Convolution on the
given sequences in MATLAB.

VIVA:

1. Write the properties of linear convolution.


a) x(n)*y(n)= y(n)*x(n)
b) [x(n)+y(n)] *z(n)=x(n)*z(n)+y(n)*z(n)
c) [x(n)y(n)] *z(n) =x(n)[y(n)*z(n)]
2. Define circular convolution.
Circular convolution is same as linear convolution but circular is for
periodic signals.

3. What is the importance of linear and circular convolution in signals and


systems?
Convolution is used to calculate a LTI system's response for a given
excitation.

4. How will you perform linear convolution via circular convolution?


Circular convolution with the length of linear convolution length (l+m-1)
results linear convolution.

5. What is sectioned convolution? Why is it performed?


If any one of the given two sequences length is very high then we have to
go for sectioned convolution.

6. What are the two methods of sectioned convolution?


a) Overlap-Add method.
b) Overlap-Save method.
Lab Experiment – 05

Aim: To find Discrete Fourier Transform and Inverse Discrete Fourier


Transform of given digital signal.
a) Using function
b) Without Function

Apparatus: MATLAB

Using a function
a) Code

%Using a function

clc;
clear all;
close all;
x1=input("Enter 1st Sequence:");
x2=input("Enter 2nd Sequence:");
N=max(length(x1),length(x2));
X1=fft(x1,N);
X2= fft(x2,N);
X3= X1.*X2;
x3= ifft(X3,N);
disp('Circular Convolution');
disp(x3);
N=0:1:N-1;
subplot(2,1,1);
stem(N,x3);
xlabel("Range");ylabel("Magnitude");
subplot(2,1,2);
stem(N,abs(X1));
xlabel("Range");ylabel("Magnitude");
b) Code and Output Screenshot

Without a function
• DFT

a) Code

%Without a function

clc;
clear all;
close all;
xn = input("Enter Sequence: ");
N = input("Enter Length: ");
Xk = dft_fun(xn, N);
k=0:N-1;
subplot(2,1,1)
stem(k, abs(Xk))
xlabel("Frequency");ylabel('Magnitude |Xk|')
title('Magnitude Plot')
subplot(2,1,2)
stem(k, angle(Xk))
xlabel("Frequency");ylabel('Angle (Xk)')
title('Phase Plot')
function [Xk] = dft_fun(xn, N)
L = length(xn);
if(N<L)
error("Length should be greater than or equal to
sequence length")
end
xn = [xn zeros(1, N-L)];
for k=0:1:N-1
for n=0:1:N-1
Wn=exp(-j*2*pi*k*n/N);
X1(k+1,n+1)=Wn;
end
end
disp('Transformation matrix for DFT')
disp(xn);
disp(X1);
Xk=X1*xn.';
end

b) Code and Output Screenshot


• IDFT

a) Code

xn = input("Enter Sequence: ");


N = input("Enter Length: ");
Xk = idft_fun(xn, N);
k=0:N-1;
subplot(2,1,1)
stem(k, abs(Xk))
xlabel("Frequency");
ylabel('Magnitude |Xk|')
title('Magnitude Plot')
subplot(2,1,2)
stem(k, angle(Xk))
xlabel("Frequency");ylabel('Angle (Xk)')
title('Phase Plot')
function [Xk] = idft_fun(xn, N)
L = length(xn);
if(N<L)
error("Length should be greater than or equal to
sequence length")
end
xn = [xn zeros(1, N-L)];
for k=0:1:N-1
for n=0:1:N-1
Wn=exp(1i*2*pi*k*n/N);
X1(k+1,n+1)=Wn;
end
end
disp('Transformation matrix for IDFT')
disp(xn);
disp(X1);
Xk=X1*(xn')/N;
end
b) Code and Output Screenshot

Conclusion:
Thus, we have successfully implemented DFT and IDFT in
MATLAB.

VIVA:

1. Define DFT and IDFT (or) what are the analysis and synthesis equations of
DFT?
DFT (Analysis Equation)
IDFT (Synthesis Equation)
2. What is magnitude and phase spectrum?
Magnitude spectrum is the graph between Fourier transform
magnitudes and frequency. Phase spectrum is the graph between
Fourier transform phases and frequency.

3. What is the drawback in Fourier transform and how is it overcome?


Fourier transform is that it is not truly realizable in practice but we can
get closer, it is not applicable to all signals, so we go for Laplace in
continuous, Z in discrete.

4. Define Circular convolution.


Let x1(n) and x2(n) are finite duration sequences both of length N with
DFTs X1(k) and X2(k). If X3(k) = X1(k) X2(k) then the sequence x3(n) can
be obtained by circular convolution.

5. Difference between DFT and DTFT?


DFT DTFT
1. Limited number of samples of periodic signal 1. Unlimited number of
samples.
2. Input is always periodic 2. Input may not always
periodic.
3. Physically realizable 3. Mathematically precise
4. Frequency becomes discrete 4. Frequency is continuous

5. State the properties of DFT


i. Periodicity
ii. Linearity and symmetry
iii. Multiplication of two DFTs
iv. Circular convolution
v. Time reversal
vi. Circular time shift and frequency shift
vii. Complex conjugate
viii. Circular correlation

You might also like