0% found this document useful (0 votes)
46 views71 pages

DSP LAB DOC (Sur)

This document provides an introduction to MATLAB for a digital signal processing lab. It outlines 10 key topics: 1) Defining vectors and matrices 2) Performing arithmetic operations 3) Relations and logical operations 4) Special matrices 5) Help, documentation, and demos 6) Viewing matrices as one-dimensional arrays 7) Working with memory 8) Control structures 9) Generating and plotting basic signals 10) Post-lab exercises to develop MATLAB code for various signals and exponential functions.

Uploaded by

Thota sivasri
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)
46 views71 pages

DSP LAB DOC (Sur)

This document provides an introduction to MATLAB for a digital signal processing lab. It outlines 10 key topics: 1) Defining vectors and matrices 2) Performing arithmetic operations 3) Relations and logical operations 4) Special matrices 5) Help, documentation, and demos 6) Viewing matrices as one-dimensional arrays 7) Working with memory 8) Control structures 9) Generating and plotting basic signals 10) Post-lab exercises to develop MATLAB code for various signals and exponential functions.

Uploaded by

Thota sivasri
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/ 71

Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India.

Student Id No:

Name: K. BINDU SRI Branch: ECE Lab Section: S(63)


Id No: 2100040287
Pre-lab In-Lab Session Post Lab Viva Total Marks
Session work work (15M) session work (10M) 50M
(15M) (10M)

Remarks:

Date: Signature of the Instructor Marks awarded

Digital Signal Processing-Lab-(21EC 3112)


Lab-1: Introduction to Matlab

Introduction: MATLAB is an environment for performing calculations and


simulations of a variety of types. MATLAB, short for matrix laboratory, was
developed and founded MathWorks by Cleve Moler, a professor of mathematics
and computer science. In the earliest version of MATLAB, there were about 80
commands, and they allowed for matrix calculations. Now there are thousands of
commands, and there are many, many types of calculations that one can
perform. During the course of this lab, the student will learn how to make
calculations using MATLAB and will learn a little about simulating systems using
the simulation tools provided by MATLAB.
Objectives:
1. To familiar with the Matlab environment.
2. Write the simple Matlab code to perform certain operations.
Requirements: Digital Computer with MATLAB software.MATLAB (short for
MATrix LABoratory) is a powerful computing environment that handles anything
from simple arithmetic to advanced data analysis. At its core is the matrix as its
basic data type. Combined with extensive maths and graphics functions,
complicated calculations can be carried out by specifying only a few simple
instructions. MATLAB can be used to do anything your scientific calculator can

1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

do, and more. The installations in the computer labs include tool boxes that
include functions for electrical engineering related tasks, such as signal
processing and system analysis. The installations in the computer labs include
tool boxes that include functions for electrical engineering related tasks, such as
signal processing and system analysis. You can plot your data in a multitude of
visualizations as well. Matlab is basically a high level language which has many
specialized toolboxes for making things easier for us

Matlab is too broad for our purposes in this course. The features we are going to
require is

Computations can be carried out in one of three ways:


1. Directly from the command line,
2. by writing a script that carries out predefined instructions, or
3. by writing your own functions.

2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Writing your own functions is much like programming in other languages, except
that you have the full resources of MATLAB's functions at your disposal, making for very
compact code. The MATLAB-6 and above environment has several windows at your
disposal.

Command Window: The main window is the command window, where you will type
all your commands, for small programs.

1. Definition of Vectors & Matrices: MATLAB is based on matrix and vector


algebra; even scalars are treated as 1x1 matrices. Therefore, vector and matrix
operations are as simple as common calculator operations. Vectors can be defined
in two ways.
Method1: The first method is used for arbitrary elements:
>> v = [1 3 5 7]; %creates a 1x4 vector with elements 1,3, 5 and 7.

* Note that commas could have been used in place of spaces to separate the
elements. that is

>> v = [1,3,5,7];

• Additional elements can be added to the vector:

>> v(5) = 8 % yields the vector v = [1 3 5 7 8].

Previously defined vectors can be used to define a new vector. For example, with ' v '
defined above

>> a = [9 10];
>> b = [v a] % creates the vector b = [1 3 5 7 8 9 10].
Method2: The second method is used for creating vectors with equally spaced
elements:
t = 0: 0.1:10 % creates a 1x101 vector with the elements 0, .1, .2, .3,...,10. Note
that the middle number defines the increment.

If only two numbers are given, then the increment is set to a default of 1: For
example.
k = 0:10 % creates a 1x11 vector with the elements 0, 1, 2, ..., 10.
2. Matrices: Matrices are defined by entering the elements row by row

3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

>> M = [1 2 4; 3 6 8; 2 6 5] % creates a 3X3 matrix


>> M' % Transpose of matrix M
*The inverse of M is M-1 denoted in Matlab as M^-1
>> M^-1
>> M(2,3) % displays the element of second row and third column

3. Arithmetic Operations: When applying addition, subtraction, multiplica-tion


and division between a scalar (that is a single number) and a vector we use
+, -, *, and / respectively.
% Let
>> a = [1 2 3;4 5 6;7 8 9]
>> b = [9 8 7;6 5 4;3 2 1]
% Then
>> a + b % addition of two matrices
>> a - b % Subtraction of two matrices
>> a*b % Multiplication
>> a+2 % addition of a constant to matrix ‘a ‘
>> a .*b % Element wise multiplication
4. Relations and logical operations:

5. Special Matrices
M=[]; % null matrix:
M = zeros(n,m); % n x m matrix of zeros:
M = ones(n,m); % n x m matrix of ones:

4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

M = eye(n); % n x n identity matrix:


6.Help, Document and Demos :
Matlab provides excellent tutorials that are accessible by typing >> demo
The Basic matrix operations tutorial under the Matrices tutorial, the Image
Processing and Signal Processing tutorial under Toolboxes are highly recommended.
To get information on a particular function of Matlab, we type help function_name
>> help fft % help for Fast Fourier Transform
>> help mean % help for mean or average value
Comments in Matlab must be proceeded by % .
To define a function in Matlab, we first create a function with the name of the
function. We then define the function in the file. For example, the Matlab documentation
recommends stat.m written as below for calculating mean and standard deviation of a
signal ‘ x ’.
function [mean,stdev] = stat(x)
% This comment is printed out with help stat
n = length(x); % assumes that x is a vector.
mean = sum(x) / n; % sum adds up all elements.
stdev = sqrt(sum((x - mean).^2)/n);
7.Viewing Matlab Matrices as one Dimensional Arrays :
Convert multi-dimensional to a one-dimensional array by simply using array_name (:)
. For example as previously defined matrix a=[1 2 3;4 5 6;7 8 9]
>> a(:) % results 147258369
Note that the elements in the one-dimensional array are arranged column by
column, not row by row. This is the same convention that is used for two
dimensional arrays in Fortran, and this will also be the convention that we will adopt
for representing two dimensional arrays in C++.
8.Working with Memory in Matlab:
To keep track of how memory is allocated, we use command ‘whos’
b=[34 54 56];
a=[2 3 56];
whos

5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

9.Control Structures:

10.Generation and plotting of basic signals:


>> Plot([3 4 5 3 2 2])
To make a graph of y = sin(t) on the interval t = 0 to t = 10, we do the
following:
>> t = 0:0.3:10;
>> y = sin(t);
>> plot (t , y) ;
Another example:
x = 0:pi/100:2*pi;

y = s in(x);

plot (x, y) ; xlabel ( ' x = 0 : 2 \ p i ' ) ; ylabel('Sine of x'); title('Plot of the Sine Function');

Multiple Graphs :

t = 0: pi/100:2*pi;
y1=sin(t) ;
y2=s i n( t + pi / 2) ; p l o t ( t , y1 , t , y2); g rid on

Multiple Plots
t = 0:pi/100:2*pi;
y1=sin (t);
y2=s i n ( t + p i / 2);
s u b p l o t ( 2 , 2 ,1 ) ; p lo t (t, y1);
s u b p l o t ( 2 , 2 , 2 ) ; p lot(t,y2);

6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Post lab:
1) Develop Matlab codes, simulate, and plot the following signals.
(a) sin(200 t )
PROGRAM:
clc;
close all;
t=2:pi/50:5*pi;
y1=sin(220*pi*t);
plot(t,y1,'g',LineWidth=3);
xlabel('time');
ylabel('amplitude');
grid on;
title('sin(220*pi*t)');
legend('2100040287’);

(b) sin(200 t   )
6
PROGRAM:
clc;
close all;
t=0:pi/30:5*pi;
y=sin((200*pi*t)+(pi/6));
plot(t,y,'g',LineWidth=2);
xlabel('time');
ylabel('amplitude');
title('sin((200*pi*t)+(pi/6))')
legend('2100040287');

(c) cos(200 t   )
6
PROGRAM:
clc;
close all;
t=0:pi/30:5*pi;
y=cos((200*pi*t)-(pi/6));
plot(t,y,'b',LineWidth=3);
xlabel('time');
ylabel('amplitude');
title('cos((200*pi*t)-(pi/6))');
legend('2100040287');

7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

2) Consider an exponential signal x (t )  k e  at u (t ) for the cases (a)

k  1 , and a  0.35 (b) k  1.2 and a  0.45 . Develop Matlab codes,


simulate, and plot the results.
a)
PROGRAM:
clc;
close all;
t=0:2:10;
k=1;
a=0.35;
y=k*exp(-a*t);
plot(t,y,'c',linewidth=4);
xlabel('time');
ylabel('x(t)');
title('x(t)=k*exp(-a*t)');
legend=('2100040287');

b)
PROGRAM:
clc;
close all;
t=0:2:10;
k=1.2;
a=-0.45;
y=k*exp(-a*t);
plot(t,y,'k',linewidth=4)
legend('2100040287');
xlabel('time');
ylabel('x(t)');
title('x(t)=k*exp(-a*t)');

8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

3) Explain the following


a) What is the purpose of command ‘clear all’ ?
Clear all command will clear entire data from workspace.
b) What is the purpose of command ‘close all’ ?
Close all closes all figures.
c) What is the purpose of command ‘clc’ ?
CLC clear all the text from command window .which resulting in a clear
screen.
d) What is the purpose of command ‘clf’ ?
Clear current figure.
clf deletes all children of the current figure with visible handles.
e) What is the purpose of symbol ‘;’ ?. If we remove this symbol what
will happen ?
This symbol is known as semicolon. It is used at end of statement to
suppress output to print on command window. If we did not specify (;) then
when we run the script , output of statement is displayed on command
window
f) What is the purpose of symbol ‘:’? Explain the meaning of the
following (i) 1:10, (ii) 1:1:10 (iii) 1:0.1:10.
This symbol is known as colon.it is used create a vector and used for
dividing a vector. (i)1 :10 -> creates a vector numbered from 1 to 10 by
incrementing 1 (ii) 1:1:10 -> here also it creates vector numbered from 1 to
10 by incrementing 1 (iii)1:0.1:10.-> here vector is created from 1 to 10 by
incrementing 0.1. like 1.0, 1.1, 1.2, 1.3 … ..10
g) What is the meaning of ‘pi’? What is its value?
Pi gives value of mathematical constant =3.141
h) What is the purpose of command ‘subplot’ ? Differentiate from ‘plot’
command?
Subplot(m,n,p) m->means number of rows, n->means number of columns
,it will create m*n small grids and p->means at which position we need to

9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

plot .and plot command means only single graph we can plot but using
subplot we can plot multiple graphs at a time.
i) What is the purpose of command ‘figure’ ?
Figure command create a figure window where graphs are plotted.
j) What is the meaning of letters ‘r’, ‘g’, ‘b’, ‘m’, and ‘c’ in the ‘plot’
command?
In plot command ‘r’->means red colour. ‘g’->means green colour.
‘b’->means blue colour . ‘m’->means magenta and ‘c’->means cyan
colour.
k) To plot the curve in black color, what is the letter in the plot command
to be used ?
To plot curve in black color we need to use->’k’ alphabet. K->represents
black. C-> cyan. M->magenta. Y-> yellow
l) What is the meaning of ‘‘LineWidth’, 1.5 ‘ in the ‘plot’ command?
What is the meaning of numeric value 1.5 ? If this value changes,
what will happen ?
The linewidth command used to adjust the width of curve. The default
value is 0.5 . ‘‘LineWidth’, 1.5 ‘ set the width of curve as 1.5.
As the value increases the width of curve also increases as value
decreases the width of curve will also decrease.
m) What are the purpose of commands ‘xlabel’ and ‘ylabel’ ?
Xlabel is used to label the x-axis in graph ex: xlabel(‘time’)
Ylabel is used to label the y-axis in graph ex: ylabel(‘amplitude’)
n) What is the purpose of command ‘title’ ?
The title command adds a title to figure example:title(‘sine wave’).
o) What is the purpose of command ‘ legend’ ? If we remove this
command, what will happen ?
Legend command is used to add labels on graphs the legend shows of
line type weather it is a dooted line or circle line and color beside the text.
if we remove legend command the text which we have written will not
appear in graph.

10
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

p) What is the purpose of command ‘grid on’? If we remove this


command, what will happen ?
The grid on command displays the grid lines in graph. If we remove this
command the grid lines inside the graph will disappear.

11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Name: K. BINDU SRI Branch : ECE Lab Section: s(63)


Id No: 2100040287
Pre-lab Session In-Lab Session Post Lab session Viva Total Marks
work (15M) work (15M) work (10M) (10M) 50M

Remarks:

Date: Signature of the lab Instructor Marks awarded

Digital Signal Processing-Lab (21EC3112)


Lab-2: Generation of Elementary Signals
Lab Report
Description: The purpose of this lab experiment is to explore the continuous time
signals using digital computers and the Matlab software environment. A continuous-
time signal takes on a value at every point in time. The basic elementary signals place
an important role in analyzing signals and testing the systems.

Objectives:
 To understand the basic singularity functions such as impulse, step and ramp
functions
 To generate and display various useful signals such as square, triangular pulse
type signals.
Requirements: Digital Computer with MATLAB software.

Basic theory: The basic elementary signals are much useful in signal processing for
analysis purpose. These signals are described both in mathematical and graphical
representations as below.

Pre-Lab:

1.Describe the steps involved in generating a unit step signal in MATLAB.

To generate a unit step signal we can use a function called us.

us(t,0).it will generate unit step from 0.

1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

2. Explain how to generate a square wave signal with a specific frequency in


MATLAB.

square(t) generates a square wave with period 2 π for the elements of the time array t.
x = square (t , duty) generates a square wave with specified duty cycle . The duty cycle
is the percent of the signal period in which the square wave is positive.

3. Discuss the process of generating a sinusoidal signal with amplitude,


frequency, and phase shift in MATLAB.

sin(t)we can generate simple sine sinusoidal signal.Y=A*sin(2*pi*f*t + r),here a is the


amplitude and f is the frequency of the signal, which is the number of cycles per second
and r is phase of signal.

4. Elaborate on how to generate a random signal with a specified length in


MATLAB.

We can generate a random signal by using rand function.

Y=rand(20,1).here it will generate a random signal of length 20.

5. Explain the steps involved in generating a chirp signal in MATLAB

A chirp is a signal in which the frequency increases (up-chirp) or decreases (down-


chirp) with time. Generate the chirp using the step function.

chirpData = (step(hchirp))';
evenFlag = mod(minute(datetime('now')),2);
if evenFlag
chirpData = fliplr(chirpData);
end

2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

In-Lab:

Develop Matlab code for display the unit impulse function by using following
data. The Unit Impulse Function: A continuous time impulse signal is defined as

The Singularity Functions:

USING SEQUENCE METHOD:


Program:
clc;
clear all;
close all;
t=-2:1:10;
y=[0,0,1,0,0,0,0,0,0,0,0,0,0]
stem(t,y,'g',LineWidth=3);

xlabel('time');
ylabel('amplitude');
title('unit impulse using sequence');
legend('2100040287');

USING UD FUNCTION
PROGRAM:
clc;
clear all;
close all;
t=-5:1:5;
y=ud(t,0);
stem(t,y,'m',LineWidth=3);
xlabel('time');
ylabel('amplitude');
title('unit impulse using (ud) function');
legend('2100040287');

3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Develop Matlab code for display the unit step function by


using following data. The Unit Step Function: A
continuous time unit signal is defined as

1, t  0
u (t )  
0, t  0

CONTINUOUS SIGNAL
USING SEQUENCE METHOD:
PROGRAM:
clc; clear all;close all;
t=-2:1:10;
y=[0,0,0,1,1,1,1,1,1,1,1,1,1];
plot(t,y,'g',LineWidth=4);
xlabel('time');
ylabel('amplitude');
title('unitstep using sequence continuous');
legend('2100040287');

USING US_FUNCTION:
PROGRAM:
clc;
clear all;
close all;
t=-2:1:10;
y=us(t,1);
plot(t,y,'m',LineWidth=4);
xlabel('time');
ylabel('amplitude');
title('unitstep using (us)function discrete');
legend('2100040287');

4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

DISCRETE SIGNAL:
USING SEQUENCE METHOD:
PROGRAM:
clc;
clear all;
close all;
t=-2:1:10;
y=[0,0,1,1,1,1,1,1,1,1,1,1,1];
stem(t,y,'g',LineWidth=2);
xlabel('time');
ylabel('amplitude');
title('unitstep using sequence discrete');
legend('2100040287');

USING US_FUNCTION:
PROGRAM:
clc;
clear all;
close all;
t=-2:1:10;
y=us(t,0);
stem(t,y,'m',LineWidth=2);
xlabel('time');
ylabel('amplitude');
title('unitstep using (us)function discrete');
legend('2100040287');
Develop Matlab code for display the unit ramp function. by using following data.
.(Both CT and DT) The Unit Ramp Function: A continuous time
ramp signal is is defined as
 t, t  0
r (t )  
0, t  0

CONTINUOUS SIGNAL
USING SEQUENCE:
PROGRAM:
clc;
clear all;
close all;
t=0:1:10;
y=t;
plot(t,y,'G',LineWidth=3)

5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

xlabel('time');
ylabel('amplitude');
title('ramp using sequence continuous');
legend('2100040287');

USING UR_FUNCTION:
PROGRAM:
clc;
clear all;
close all;
t=-2:1:10;
y=ur(t,0);
plot(t,y,'m',LineWidth=3)
xlabel('time');
ylabel('amplitude');
title('ramp continuous using (ur)function');
legend('2100040096');

DISCRETE SIGNAL
USING SEQUENCE METHOD:
PROGAM:
clc;
clear all;
close all;
t=0:1:10;
y=t;
stem(t,y,'G',LineWidth=3)
xlabel('time');
ylabel('amplitude');
title('ramp using sequence discrite');
legend('2100040287');

USING UR_FUNCTION:
PROGRAM:
clc;
clear all;
close all;
t=-2:1:10;
y=ur(t,0);
stem(t,y,'m',LineWidth=3)
xlabel('time');
ylabel('amplitude');
title('ramp discrete using (ur)function');
legend('2100040287');

6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Develop Matlab code for display the unit ramp function. by using following data.
.(Both CT and DT) The Unit Ramp Function: A continuous time ramp signal is

Gate function: A gate function is denoted by rect (t ) or  (t ) of height A and width ,


centered at the origin. The mathematical expression is defined as

 A, for    t    A, for | t |  / 2

rect (t )   2 2 or rect (t )  

0, elsewhere  0, for | t |  / 2

RECTANGULAR PULSE
PROGRAM:
Clc;
clear all;
close all;
t=-3:0.1:3;
y=rectpuls(t,1);
plot(t,y,'G',LineWidth=4)
set(gca);
grid on;
axis([-1 1 -1.5 1.5]);
xlabel('time');
ylabel('amplitude');
title('rectangular pulse');
legend('2100040287')

Triangular function: A triangular function is denoted by (t ) , of height A and


width  , centered at the origin. The mathematical expression is
 2 A t  A, for    t  0
  2
defined as (t )  
 2 A t  A, for 0  t  
  2
TRIANGULAR PULSE
PROGRAM:
clc;
clear all;
close all;
t=-3:0.1:3;
y=tripuls(t,1);
plot(t,y,'g',LineWidth=3);
grid on;

7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

axis([-1.5 1.5 -0.5 1.5])


xlabel('time');
ylabel('amplitude');
title('triangular pulse');
legend('2100040287');

Develop Matlab code for display a sinc signal.


Interpolation function: sinc(x) or Sa(x). The function sin x is the ‘sine over argument’
x
function denoted by sinc(x). It is also known as filtering or
interpolating function.
 sinc(x) is an even function.
 Using L’Hospital’ rule, sinc(0) = 1.
 sinc(x) is also denoted as Sa(x) in the literature.
sin  x
Some authors define as .
x

SINC SIGNAL
PROGRAM:
clc;
clear all;
close all;
t=(-pi:0.001:pi)/100;
f=100;
y=sin(2*pi*f*t)./(2*pi*f*t);
plot(t,y,'g',LineWidth=3);
grid on;
xlabel('time');
ylabel('amplitude');
title('sinc signal');
legend('2100040287');

8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

VIVA-VOCE:
1. How can you generate a unit impulse signal in MATLAB?
A. impulse = [1; zeros(length(t)-1,1)];

2. How do you generate a unit step signal in MATLAB?


A. unitstep = t>=0;

3. How can you generate a sinusoidal signal in MATLAB?


A. f = 100; % frequency in Hz

t = 0:1/1000:1; % time vector in seconds

y = sin(2*pi*f*t);

4.How do you generate a square wave signal in MATLAB?


A. f = 100;

t = 0:1/1000:1;

y = square(2*pi*f*t);

5. How do you generate a random signal in MATLAB?


A. to generate a random signal with a length of 100 samples,
y = rand(100, 1);

9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Name:K.BINDU SRI Branch:ECE Lab Section: S(63)


Id No: 2100040287
Pre-lab Session In-Lab Session Post Lab session Viva Total Marks
work (15M) work (15M) work (10M) (10M) 50M

Remarks:

Date: Signature of the Instructor Marks awarded

Digital Signal Processing Lab (21EC3112)


Lab-3: Operations on Signals
Lab Report
Objectives: The main objective of this lab experiment is to explore the basic operations
on continuous time signals. These operations are essential in signal processing based
applications.

 To compute and display the following basic operations on continuous-time signals.


Amplitude scaling
Time shifting
Time scaling
Time reversal
Combined operations
Requirements: Digital Computer with MATLAB software.

Description:

Basic Operations on signals: The operations performed on signals can be broadly


classified into two types: Operations on dependent variables, and Operations on
independent variables

Operations on dependent variables: The operations of the dependent variable can be


classified into five types: amplitude scaling, addition, multiplication, integration and
differentiation.
Amplitude scaling: Amplitude scaling of a signal x(t ) given by equation

y (t )  ax(t )

1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

results in amplification of x(t ) if a >1, and attenuation if a <1.

Signal Addition: The addition of signals is given by equation y(t )  x1(t )  x2 (t ) .

Signal Multiplication: The multiplication of signals is given by the simple equation


x(t )  x1(t ) x2 (t ) .
Operations on independent variables: There are various kind of operations on
independent variables illustrated below.
Time scaling: Time scaling operation is given by equation y (t )  x(at ) . This operation

results in expansion in time for a  1 , and compression in time for a  1 .

Time reflection: Time reflection is given by equation y (t )  x( t ) .

Time shifting: The equation representing time shifting operation is given by


y(t )  x(t  t0 ) . If t0 is positive constant, the operation is right shift. If t0 is negative the
operation is left shift.

Time shifting and scaling: The combined transformation of shifting and scaling is
represented by an equation y(t )  x(at  t0 ) . The time shifting operation is performed
first and time scaling operation will be done in the second step.

Even (or Symmetric) and Odd (anti-symmetric) signals

x(t )  xe (t )  xo (t ) , where xe (t )  1  x(t )  x(t ) and xo (t )  1  x(t )  x(t )


2 2
where again, xe (t ) is an even signal and xo (t ) is an odd signal.

Pre-Lab:
1.Explain the concept of time-domain representation of a signal and its
significance in signal processing.
Time domain refers to the analysis of mathematical functions, physical signals
or time series of economic or environmental data, with respect to time A time-domain
graph shows how a signal changes with time

2. Describe the process of sampling a continuous-time signal to obtain a discrete-


time representation. Discuss the factors that affect the sampling process.

2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Sampling a continuous time signal produces a discrete time signal by selecting the
values of the continuous time signal at equally spaced points in time. the continuous
signal is sampled using an analog-to-digital converter (ADC)

3. Discuss the importance of the Fourier Transform in signal processing and how
it helps analyze the frequency components of a signal.
Fourier Transform is a mathematical model which helps to transform the signals
between two different domains, such as transforming signal from frequency domain to
time domain or vice versa. The inverse Fourier transform converts the frequency domain
function back to a time function.

4. Explain the concept of convolution and its role in filtering and system analysis.
Provide an example of how convolution is performed on signals in MATLAB.
Convolution is a mathematical tool to combining two signals to form a third signal.
Convolution is performed in matlab using conv function
Ex: conv(x,y)

5. Describe the purpose and application of the Fast Fourier Transform (FFT)
algorithm in MATLAB. Explain how it enables efficient computation of the
frequency components of a signal

A fast Fourier transform (FFT) is a highly optimized implementation of the discrete


Fourier transform (DFT), which convert discrete signals from the time domain to the
frequency domain. FFT computations provide information about the frequency content,
phase, and other properties of the signal. used for signal filtering, spectral estimation,
data compression, and other applications.

Examples:

Scalar Multiplication: Amplification and Attenuation.


(a) Develop Matlab codes to sketch and label the following signals.
(i) 𝛿(𝑡) (ii) 1.2 (t ) (iii) 2 (t )

3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

PROGRAM:
clc;
clear all;
close all;
t=-3:0.01:3;
y=ud(t,0);
subplot(1,3,1);
plot(t,y,'m',LineWidth=3);
axis([-2.8 2.8 -0.2 1.1])
title('delta');
legend('2100040287');
subplot(1,3,2);
y1=1.2*ud(t,0);
plot(t,y1,'m',LineWidth=3);
title('1.2 delta');
axis([-2.8 2.8 -0.2 1.3])
subplot(1,3,3)
y3=-2*ud(t,0);
plot(t,y3,'m',LineWidth=3);
axis([-2.8 2.8 -2.2 0.2]);
title('-2 delta');

(B) Sketch and label the following signals using Matlab


(i) 𝑢(n) (ii) −𝑢(n) (iii) 2𝑢(n)

PROGRAM:
clc;
clear all;
close all;
t=-3:0.01:3;
y=us(t,0);
subplot(3,1,1);
plot(t,y,'g',LineWidth=4);
title('u(n)');
subplot(3,1,2);
plot(t,-y,'b','LineWidth',4);
title('-u(n)');
subplot(3,1,3);
plot(t,2*y,'r','LineWidth',4);
title('2u(n)');
legend('2100040287');

4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

(C) Sketch and label the following signals using Matlab


(i) r (t ) (ii) −𝑟(n) (iii) 1.2 r (t )

PROGRAM:
clc;
clear all;
close all;
t=-2:1:5;
y=ur(t,0);
y1=-ur(t,0);
y2=1.2*ur(t,0);
subplot(3,1,1);
plot(t,y,'g',LineWidth=3);
axis([-2.1 3 0 4]);
title('r(t)');
legend('2100040287);
subplot(3,1,2);
plot(t,y1,'b','LineWidth',3);
axis([-2.1 3 -3 0]);
title('-r(t)');
subplot(3,1,3);
plot(t,y2,'r','LineWidth',3);
axis([-2.1 3 0 3]);
title('1.2r(t)');

Time Shifting of CT Sequences:


(a) Develop Matlab codes to sketch and label the following signals.
(i)  (t ) (ii) 𝛿(n−1) (iii) 𝛿(n+2)

PROGRAM:
clc;
clear all;
close all;
t=-4:0.1:3;
y=ud(t,0);
y1=ud(t,1);
y2=ud(t,-2);
subplot(1,3,1);
plot(t,y,'g',linewidth=3);
axis([-3 3 -0.2 1.2])
title('delta(t)');
legend('2100040287');
subplot(1,3,3);
plot(t,y1,'r',linewidth=3);
axis([-3 3 -0.2 1.2])
title('delta(t-1)');
subplot(1,3,2);
plot(t,y2,'b',linewidth=3);
axis([-3 3 -0.2 1.2])
title('delta(t+2)');

5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

(b) Sketch and label the following signals using Matlab


(ii) 𝑢(n) (ii) 𝑢(n−2) (iii) 𝑢(n+1)

PROGRAM:
clc;
clear all;
close all;
t=-4:0.01:3;
y=us(t,0);
y1=us(t,1);
y2=us(t,-2);
subplot(1,3,1);
plot(t,y,'g',linewidth=3);
axis([-3 3 -0.2 1.2])
title('u(t)');
legend('2100040287);
subplot(1,3,2);
plot(t,y2,'b',linewidth=3);
axis([-3 3 -0.2 1.2])
title('u(t+2)');
subplot(1,3,3);
plot(t,y1,'r',linewidth=3);
axis([-3 3 -0.2 1.2])
title('u(t-1)');

(C) Sketch and label the following signals using Matlab


(ii) 𝑟(n) (ii) 𝑟(n−1) (iii) 𝑟(n+1)

PROGRAM:
clc; clear all; close all;
t=-3:0.001:3;
y=ur(t,0);
y1=ur(t,1);
y2=ur(t,-1);
subplot(1,3,1);
plot(t,y,'g',linewidth=3);
title('r(t)');
legend('2100040287');
axis([-1.8 3 -0.1 4]);
subplot(1,3,2);
plot(t,y1,'r',linewidth=3);
title('r(t-1)');
axis([-1.8 3 -0.1 4]);
subplot(1,3,3);
plot(t,y2,'b',linewidth=3);
title('r(t+1)');
axis([-1.8 3 -0.1 4]);

6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Time Scaling: Compression and Expansion


(a) Consider a rectangular pulse signal x(t ) having unit height and unit width
centered at origin. Use Matlab built in function rectpuls.m. Sketch and
label the following signals using Matlab
(i) x(2t ) (ii) x(t / 4)

PROGRAM:
clc; clear all; close all;
t=-3:0.01:3;
y=rectpuls(t,1);
y1=rectpuls(2*t,1);
y2=rectpuls(t/4,1);
plot(t,y,'G',LineWidth=4)
hold on;
grid on;
plot(t,y1,'b',LineWidth=4,LineStyle=':');
hold on;
plot(t,y2,'m',LineWidth=4,LineStyle='--');
legend('x(t)' ,'x(2t)', 'x(t/4)');
axis([-2.2 2.2 -0.2 1.5]);
legend('2100040287');
(OR)
PROGRAM:
clc; clear all; close all;
t=-3:0.01:3;
y=rectpuls(t,1);
y1=rectpuls(2*t,1);
y2=rectpuls(t/4,1);
subplot(3,1,1);
plot(t,y,'G',LineWidth=4)
title('x(t)');
grid on;
axis([-1.2 1.2 -0.2 1.5]);
subplot(3,1,2);
plot(t,y1,'b',LineWidth=4);
title('x(2t)');
grid on;
axis([-1.2 1.2 -0.2 1.5]);
subplot(3,1,3);
plot(t,y2,'G',LineWidth=4);
title('x(t/4)');
axis([-2.2 2.2 -0.2 1.5]);
grid on; legend('2100040287')

7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

(b) Consider a triangular pulse signal x(t ) having unit height and unit width
centered at origin. Use Matlab built in function tripuls.m. Sketch and label
the following signals using Matlab
(ii) x(2t ) (ii) x(t / 4)

PROGRAM:
clc;
clear all;
close all;
t=-3:0.01:3;
y=tripuls(t,1);
y1=tripuls(2*t,1);
y2=tripuls(t/4,1);
plot(t,y,'G',LineWidth=4)
hold on;
grid on;
plot(t,y1,'b',LineWidth=4,LineStyle=':');
hold on;
plot(t,y2,'m',LineWidth=4,LineStyle='--');
legend('x(t)' ,'x(2t)', 'x(t/4)','2100040287');
title('tripuls scaling');
axis([-2.2 2.2 -0.2 1.5]);
(OR)
PROGRAM:
clc; clear all; close all;
t=-3:0.01:3;
y=tripuls(t,1);
y1=tripuls(2*t,1);
y2=tripuls(t/4,1);
subplot(3,1,1);
plot(t,y,'G',LineWidth=4)
legend('2100040287');
title('x(t)');
grid on;
axis([-1.2 1.2 -0.2 1.5]);
subplot(3,1,2);
plot(t,y1,'b',LineWidth=4);
title('x(2t)');
grid on;
axis([-1.2 1.2 -0.2 1.5]);
subplot(3,1,3);
plot(t,y2,'m',LineWidth=4);
title('x(t/4)');
axis([-2.2 2.2 -0.2 1.5]);
grid on;

8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Folding operation or Time Reversal operation


Sketch and label the time reversal operation of a ramp signal using Matlab

PROGRAM:
clc;
clear all;
close all;
t=-4:1:4;
y=ur(t,0);
y1=ur(-t,0);
subplot(1,2,1);
stem(t,y,'g',LineWidth=3);
title('r(t)');
legend('210040287);
axis([-4.1 4.1 -0.1 4.1]);
subplot(1,2,2);
stem(t,y1,'c',LineWidth=3);
title('r(-t)');
axis([-4.1 4.1 -0.1 4.1]);
(OR)
PROGRAM:
clc;
clear all;
close all;
t=-4:1:4;
y=ur(t,0);
y1=ur(-t,0);
stem(t,y,'b',LineWidth=3);
hold on;
axis([-4.1 4.1 0 4.1]);
stem(t,y1,'r',LineWidth=3);
legend('r(t)','r(-t)');
title('time reversal of ramp');
xlabel('time');
ylabel('amplitude');
legend('210040287);

Combined folding, scalling and shifting operation


(a) Consider a rectangular pulse signal x(t ) having unit height and unit width
centered at origin. Use Matlab built in function rectpuls.m. Sketch and label
the following signals using Matlab
(i) x(2t  2) (ii) x (t / 2  1)

9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

PROGRAM:
clc; clear all; close all;
x=-3:0.0001:7.5;
y=rectpuls(x,1);
y1=rectpuls(2*x+2,1);
y2=rectpuls(x/2-1,1)
subplot(1,3,1);
plot(x,y,'g',LineWidth=4);
title('x(t)');
legend('2100040287');
axis([-2 4 -0.2 1.1]);
subplot(1,3,2);
plot(x,y1,'r',LineWidth=4);
title('2*t+2');
axis([-2 4 -0.2 1.1]);
subplot(1,3,3);
plot(x,y2,'b',LineWidth=4);
axis ([-2. 4 -0.2 1.1])
title('t/2-1');
(OR)
PROGRAM:
clc;
clear all;
close all;
x=-3:0.0001:7.5;
y=rectpuls(x,1);
y1=rectpuls(2*x+2,1);
y2=rectpuls(x/2-1,1)
plot(x,y,'g',LineWidth=4);
hold on;
axis([-2 4 -0.2 1.2]);
plot(x,y1,'r',LineWidth=4);
hold on;
plot(x,y2,'b',LineWidth=4);
axis ([-2. 4 -0.1 1.2])
legend('x(t)','2*x+2','x/2-1');
title('rectangular pulse scaling and shifting');
legend('2100040287');

10
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

(b) Consider a triangular pulse signal x(t ) having unit height and unit width
centered at origin. Use Matlab built in function tripuls.m. Sketch and label
the following signals using Matlab
(i) x (2t  5) (ii) x(t / 3  1)

PROGRAM:
clc; clear all; close all;
t=-3:0.01:5;
y=tripuls(t,1);

y1=tripuls(2*t+5,1);
y2=tripuls(t/3-1,1);
plot(t,y,'c',LineWidth=4);
hold on;
plot(t,y1,'b',LineWidth=4);
hold on;
plot(t,y2,'r',LineWidth=4);
hold on;
axis([-3 5 -0.1 1.3]);
legend('x(t)','x(2t+5)','x(t/3-1)');
title('tripuls scaling and shifting');
legend('2100040287');

Consider a signal shown in figure:


Determine analytically the following signals.
(a) x(t  1) (b) x(t  1) (c) x(2t )
(d ) x(2t  1) (e) x( 2t  1)
Then develop Matlab scripts and plot them.
Solution: The mathematical equation for given signal is
 1, 1  t  0
x(t )  
t  1, 0  t  1
For this equation we write a Matlab code as a function named ‘sr.m’ (square ramp) as
below:
function y = sr(t)

% using functional representation


y = zeros(size(t)); % Initialization
i = find((t>-1) & (t<1));

11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

y(i) = 1; % x(t) = 1, -1 < t < 0


i = find((t>0) & (t<1));
y(i) = -t(i)+1; % x(t) = -t+1, 0 < t < 1

% Using step function


y = (us(t,-1)-us(t,0))+(us(t,0)-us(t,1)).*(-t+1);

PROGRAM:
clear all; close all; clc;
t=-3:0.001:3;
y=sr(t);
y1=sr(t-1);
y2=sr(t+1);
y3=sr(2*t);
y4=sr(-2*t+1);
y5=sr(2*t-1);
subplot(3,2,1);
plot(t,y,'g',LineWidth=4);
title('x(t)');
legend('2100040287);
axis([-2.2 2.2 -0.1 1.3]);
subplot(3,2,2);
plot(t,y1,'y',LineWidth=4);
title('x(t-1)');
axis([-2.2 2.2 -0.1 1.3]);
subplot(3,2,3);
plot(t,y2,'r',LineWidth=4);
title('x(t+1)');
axis([-2.2 2.2 -0.1 1.3]);
subplot(3,2,4);
plot(t,y3,'b',LineWidth=4);
title('x(2*t)');
axis([-2.2 2.2 -0.1 1.3]);
subplot(3,2,5);
plot(t,y4,'c',LineWidth=4);
title('(-2*t+1)');
axis([-2.2 2.2 -0.1 1.3]);
subplot(3,2,6);
plot(t,y5,'m',LineWidth=4);
title('(2*t-1)');
axis([-2.2 2.2 -0.1 1.3]);

12
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

POST LAB

Develop Matlab codes, simulate and show the results for the following signals.
(𝑎) −2𝛿(n+2)
PROGRAM:
clc;
clear all;
close all;
t=-3:1:3;
y=ud(t,0);
y1=-2*ud(t+2,0);
stem(t,y,'r',LineWidth=4);
hold on;
stem(t,y1,'b',LineWidth=4);
axis([-3 2 -2.1 1.3]);
legend('delta(n)','−2𝛿(n+2)');
legend('2100040287');

(𝑏) 𝑢(n)+𝑢(−n)
PROGRAM:
clc;
clear all;
close all;
t=-4:0.01:4;
y=us(t,0);
y1=us(-t,0);
y2=us(t,0)+us(-t,0);
subplot(3,1,1);
plot(t,y,'y',LineWidth=4);
title('u(n)');
legend('2100040287');
axis([-4 4 -0.1 1.3] );
subplot(3,1,2);
plot(t,y1,'M',LineWidth=4);
axis([-4 4 -0.1 1.3] );
title('u(-n)');
subplot(3,1,3);
plot(t,y2,'g',LineWidth=4);
axis([-4 4 0 2.2]);
title('u(n)+u(-n)');

13
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Consider the following signal shown below.

(i) Write the mathematical equation for the signal in functional form. Then develop
Matlab scripts and plot the following operations.
(𝑎) 𝑥(𝑡−1) (𝑏) 𝑥(𝑡+1)
PROGRAM:
clc;
clear all;
close all;
t=-3:0.001:4;
x=us(-t+2,0).*us(t,0);
x1=us(-t+3,0).*us(t-1,0);
x2=us(-t+1,0).*us(t+1,0);
subplot(3,1,1);
plot(t,x,’g’,linewidth=4);
title(‘x(t)’);
legend(‘2100040287’);
axis([-4 4 -0.1 1.2]);
subplot(3,1,2);
plot(t,x1,’r’,linewidth=4);
title(‘x(t-1)’);
axis([-4 4 -0.1 1.2]);
subplot(3,1,3);
plot(t,x2,’b’,linewidth=4);
axis([-4 4 -0.1 1.2]);
title(‘x(t+1)’);

14
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

15
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Name: K. BINDU SRI Branch: ECE Lab Section: S(63)


Id No: 2100040287
Pre-lab In-Lab Post Lab Viva Total Marks
Session work Session work session work (10M) 50M
(15M) (15M) (10M)

Remarks:

Date: Signature of the Instructor Marks awarded

Digital Signal Processing-Lab (21 EC 3112)


Lab-4 Linear Convolution
Lab Report
AIM/Objectives: The aim of the experiment on linear convolution in MATLAB is to
understand and implement the process of linear convolution between two signals. The
experiment focuses on the following objectives:
1. To demonstrate the concept of linear convolution and its application in signal
processing.
2. To understand how the convolution operation combines two signals to produce a third
signal.
3.To implement the convolution operation using MATLAB's built-in functions or by writing
custom code
Description:

Introduction: Linear and time invariant LTI systems are particularly important class of
systems has significant signal processing applications. These systems satisfy both the
linearity and time-invariant properties. The processing of signals / sequences in time
domain through discrete time systems are usually referred to as convolution or filtering
operation. A mathematical operation that closely resembles convolution is called
correlation. The correlation operation is used to measure the similarity between two
sequences.
Convolution: The block schematic of CT system is illustrated in the following figure.

Let x(t ) is an input sequence applied to an CT, LTI system characterized by an impulse
response h(t ) . Then the output of the system is described mathematically by,
 
y(t )   x( ) h(t   ) d   h( ) x(t   ) d
 
y(t )  x(t )  h(t )  h(t )  x(t )

1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

is known as convolution integral equation.


Pre-Requisites: Digital Computer with MATLAB software

Pre-Lab:

1. Describe the concept of linear convolution and its application in signal


processing. Explain how it combines two signals to produce a third signal.
Linear convolution is a mathematical operation done to calculate the output of
any Linear-Time Invariant (LTI) system given its input and impulse response. It is
applicable for both continuous and discrete-time signals.
We can represent Linear Convolution as
y(n)=x(n)*h(n)
Here, y(n) is the output (also known as convolution sum). x(n) is the input signal,
and h(n) is the impulse response of the LTI system.

2. Discuss the steps involved in performing linear convolution between two


signals using MATLAB. Explain the role of indexing and summation in the
convolution process
To perform linear convolution in MATLAB .
First declare the time interval t,x(t)and h(t). By using conv function we can
perform convolution.i.e conv(x,y). It will give the resultant output

3. Explain the significance of the impulse response in linear convolution. How


is the impulse response related to the system or filter being convolved with
the input signal?
For both discrete- and continuous-time systems, the impulse response is useful
because it allows us to calculate the output of these systems for any input signal;
the output is simply the input signal convolved with the impulse response
function. The impulse response describes how each pointin the input signal
affects the output signal.

4. Describe the difference between linear convolution and circular


convolution. When would you choose one over the other, and how are they
implemented in MATLAB?
in circular convolution, the signals are all periodic. Thus the shifting can be
thought of as actually being a rotation.
Linear convolution is a mathematical operation done to calculate the output of
any Linear-Time Invariant (LTI) system given its input and impulse response.

5. Discuss the Convolution Theorem and its implications for efficient


convolution calculations using the Fast Fourier Transform (FFT). Explain
how MATLAB leverages the Convolution Theorem for faster convolution.

2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Fourier Transform is a mathematical model which helps to transform the signals


between two different domains, such as
transforming signal from frequency domain to time domain or vice versa.
The inverse Fourier transform converts the frequency domain function back
to a time function.

IN-LAB:

Let x(t ) be the input to an LTI system with unit impulse response h(t ) , where
and h(t )  u (t ) . Find the response of the system using
convolution operation.

Solution: Given that x(t ) and h(t ) . Then the response of the system is computed using
convolution integral equation as below.
 
y (t )   x( ) h(t   ) d   e  a u ( ) u (t   ) d
 
t 1  a t
  e  a d  
0
e 0
a
1
 (1  e  at ) u (t )
a

PROGRAM:

clc;
clear all;
close all;
t=-1:0.001:5;
x=exp(-2*t).*us(t,0);
h=us(t,0);
y=conv(x,h);
t2=-2:0.001:10;
subplot(3,1,1);plot(t,x,'r',LineWidth=4);
legend('2100040287');
title('e^(-at)u(t)');
subplot(3,1,2);plot(t,h,'g',LineWidth=4);
title('u(t)');
subplot(3,1,3);plot(t2,y,'b',LineWidth=4);
title('conv(x,h)');

3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Determine the convolution analytically for the signals shown below. Then develop
Matlab code for convolution and plot them.

Solution: The mathematical expressions for the given signals are


 1, 0  t 1  t, 0  t 1
x(t )   and h(t )  
0, Otherwise 0, Otherwise
PROGRAM:
clc;
clear all;
close all;
t=-1:0.001:5;
x=us(t,0)-us(t,1)
h=ur(t,0)-ur(t,1)-us(t,1);
y=conv(x,h);
t1=-2:0.001:10;
subplot(3,1,1);
plot(t,x,'c',LineWidth=3);
axis([-0.2,5,-0.1,1.2]);
legend('2100040287');
title('x(t)');
subplot(3,1,2);
plot(t,h,'g',LineWidth=3);
axis([-0.2,5,-0.1,1.2]);
title('h(t)');
subplot(3,1,3);
plot(t1, y,'r','LineWidth',3);
title('conv(x,y)');

4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Sample Viva voce questions (in lab):


1. What is linear convolution and how does it differ from circular convolution?
2. Explain the process of linear convolution between two signals. How is it implemented
in MATLAB?
3. What is the role of the impulse response in linear convolution? How is it related to the
system being convolved with the input signal?
4. Describe the steps involved in performing linear convolution using MATLAB's built-in
functions.
5. How does zero-padding affect the linear convolution process? What is its purpose?
6. What is the Convolution Theorem, and how does it enable efficient convolution
calculations using the Fast Fourier Transform (FFT)?
7. Explain the concept of overlap-add and overlap-save methods in linear convolution.
What are their advantages?
8. Discuss the limitations and challenges of linear convolution, particularly in terms of
computational complexity and signal length.
9. How can linear convolution be used in system analysis and filtering applications?
Provide examples.
10. What are some MATLAB functions and tools available for linear convolution and
signal processing tasks?

POST-LAB:

Determine analytically the convolution of the following signals, and verify your
answers using the Matlab.
(a) and

PROGRAM:
clc;
clear all;
close all;
t=-3:0.001:5;
t1=-6:0.001:10;
x=exp(-t).*us(t,0);
h=us(t,0)-us(t,1);
y=conv(x,h);
subplot(3,1,1);
plot(t,x,'b',LineWidth=3);
axis([-1,5,-0.2,1.5]);
legend('2100040287');
title('x(t)=e^(-t) u(t) ')
subplot(3,1,2);
plot(t,h,'y',LineWidth=3);
axis([-1,5,-0.2,1.5]);
title(' u(t)-u(t-1)');

5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

subplot(3,1,3);
plot(t1,y,'r',LineWidth=3);
title('conv(x,h)');
(b) and
PROGRAM:

clc;
clear all;
close all;
t=-3:0.01:5;
t1=-6:0.01:10;
x=us(t,0);
h=2*us(t,1)-2*us(t,4);
y=conv(x,h);
subplot(3,1,1);
plot(t,x,'b',LineWidth=3);
axis([-2,4,-0.5,2]);
legend('2100040287');
title('u(t)')
subplot(3,1,2);
plot(t,h,'g',LineWidth=3);
axis([-2,4,-0.5,2]);
title('2u(t-1)-2u(t-4)');
subplot(3,1,3);
plot(t1,y,'r',LineWidth=3);
axis([-2,4,-2,1000]);
title('conv(x,h)');

Consider a continuous time signal shown below. Convolve the signal itself i.e.,
y (t )  x(t )  x(t ) . Determine analytically the convolution, and verify your answers
using the Matlab.

6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

PROGRAM:

clc;
clear all;
close all;
t=-3:0.01:5;
t1=-6:0.01:10;
x=us(t,0)-us(t,1);
h=us(t,0)-us(t,1);
y=conv(x,h);
subplot(3,1,1);
plot(t,x,'b',LineWidth=3);
axis([-1,4,-0.5,2]);
legend('2100040287');
title('x(t)')
subplot(3,1,2);
plot(t,h,'m',LineWidth=3);
axis([-1,4,-0.5,2]);
title('x(t)');
subplot(3,1,3);
plot(t1,y,'r',LineWidth=3);
axis([-1,4,-0.5,105]);
title('conv(x,h)');

Determine the convolution for the sequences given below


X(n) = { 1 2 -1 4 2} and h(n) = { -1 2 -1 }

PROGRAM:
clc;
clear all;
close all;
t=-1:1:6;
t1=-2:1:12;
x=[0,1,2,-1,4,2,0,0];
h=[0,-1,2,1,0,0,0,0];
y=conv(x,h);
subplot(3,1,1);
stem(t,x,'b',LineWidth=3);
axis([-1.2,5.2,-1,2]);
legend('2100040287');
title('{ 1 2 -1 4 2}')
subplot(3,1,2);
stem(t,h,'g',LineWidth=3);

7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

axis([-1.2,5.2,-1,2]);
title('{ -1 2 -1 }');
subplot(3,1,3);
stem(t1,y,'r',LineWidth=3);
axis([-1.2,5.2,-1,6]);
title('conv(x,h)');
Determine the convolution for the sequences given below

PROGRAM:
clc;
clear all;
close all;
t=-2:1:4;
t1=-4:1:8;
x=[3,1,2,-1,4,2,0];
h=[0,2,3,0,-1,2,0];
y=conv(x,h);
subplot(3,1,1);
stem(t,x,'b',LineWidth=3);
axis([-1.2,5.2,-1,2]);
legend('2100040287');
title('{ 3 1 2 -1 4 2 0}')
subplot(3,1,2);
stem(t,h,'g',LineWidth=3);
axis([-1.2,5.2,-1,2]);
title('{0 2 3 0 -1 2 }');
subplot(3,1,3);
stem(t1,y,'r',LineWidth=3);
axis([-4,8,-1,15]);
title('conv(x,h)');

8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Experiment 05 Student ID 2100040287


Date Student Name K. BINDU SRI

Experiment title: DT Sequences - Frequency-Domain Representation (DTFT)

Aim/Objectives:

(a) To compute the discrete time Fourier transform (DTFT) for DT sequences and
LTI systems.
(b) To determine and display the Magnitude and phase spectrum of given
sequences and LTI systems.

(c) To find out real part and imaginary part of the spectrum.

Description:

A linear and time-invariant system can be represented using its response to the unit
sample sequence. This response, called the unit impulse response h[ n ] , allows us to
compute the system response to any arbitrary input x[ n ] using the linear convolution.
This convolution representation is based on the fact that any signal can be represented
by a linear combination of scaled and delayed unit samples. Similarly, we can also
represent any arbitrary discrete signal as a linear combination of basis signals. Each
basis signal set provides a new signal representation. Each representation has some
advantages and some disadvantages depending upon the type of system under
consideration. However, when the system is linear and time-invariant, only one
representation stands out as the most useful. It is based on the complex exponential
signal set {e jn } and is called the discrete-time Fourier transform (DTFT).

If x[ n ] is absolutely summable, that is, 


 | x[n] |   , then its discrete time Fourier
transform (DTFT) is given by


X [e jω ]  
n
x[n] e jωn

The inverse discrete-time Fourier transform (IDTFT) of X [e j ] is given by

1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:


1
2 
x[n]  X [e jω ] e jωn dω .

In general X [e j ] is a complex function of the real variable ω and can be written as

X [e jω ]  X re [e jω ]  j X im[e jω ]

where X re [e jω ] and X im [e jω ] are, respectively, the real and imaginary parts of

X [e j ] , and are real functions of ω . X [e j ] can alternately be expressed in the form

X [e jω ]  | X [e jω ] | e j [ω]


where  [ω]  arg X [e jω ] 
The quantity | X [e jω ] | is called the magnitude spectrum and the quantity  [ω] is called
the phase function, with both functions again being real functions of ω. In many
applications, the Fourier transform is called the Fourier spectrum and, likewise,
| X [e jω ] | and  [ω] are referred to as the magnitude spectrum and phase spectrum,
respectively.
The Fourier Domain Representation of LTI Systems:
The response of an LTI system for any arbitrary
sequences in time domain can be represented by using
a convolution sum y[n]  x[n]  h[n] , where x[ n ] is input Fig.1 An LTI System

sequence, h[ n ] is the impulse response of the system and y[ n] is the response of the
system. According to the convolution theorem, the convolution in time domain is
multiplication in frequency domain, Y [e jω ]  H [e jω ] X [e jω ] , where X [e jω ] is the

spectrum of the input sequence and H [e jω ] is the system (or Transfer) function.

Pre-Requisites: Digital Computer with MATLAB software.


Pre-Lab:
1) Describe the concept of the Discrete-Time Fourier Transform (DTFT) and its
significance in analyzing the frequency content of discrete-time signals. Explain
how the DTFT converts a discrete time signal into the frequency domain.

2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

In mathematics, the discrete-time Fourier transform (DTFT), also called the finite Fourier
transform, is a form of Fourier analysis that is applicable to a sequence of values. The
DTFT is often used to analyze samples of a continuous function.

2) Discuss the properties of the DTFT, such as linearity, time shifting, frequency
shifting, and convolution. Explain how these properties are useful in signal
analysis and processing.

Linearity
if one takes the Fourier transform of a linear combination of signals then it will be the
same as the linear combination of the Fourier transforms of each of the individual
signals.
Symmetry
Basically what this property says is that since a rectangular function in time is a sinc
function in frequency, then a sinc function in time will be a rectangular function in
frequency.
Time Scaling
This property deals with the effect on the frequency-domain representation of a signal if
the time variable is altered.
Time Shifting
Time shifting shows that a shift in time is equivalent to a linear phase shift in frequency.

3) Explain the relationship between the DTFT and the Discrete Fourier Transform
(DFT). How can the DFT be used to approximate the DTFT in practice?

DTFT is an infinite continuous sequence where the time signal (x(n)) is a discrete signal.
DFT is a finite non-continuous discrete sequence. DFT, too, is calculated using a
discrete-time signal.

4)Describe the process of calculating the DTFT of a discrete-time signal using


MATLAB. Explain the role of the `freqz` function and the interpretation of the
output.

3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

freqz(b,a,n) returns the n-point frequency response vector h and the corresponding
angular frequency vector w for the digital filter with transfer function coefficients stored
in b and a.

5) Discuss the limitations and challenges of the DTFT. What are the implications
of the infinite nature of the DTFT spectrum? How can windowing techniques be
used to mitigate some of these challenges

DTFT assumes infinite-duration signals: The DTFT is defined for infinite-duration discrete-
time signals. However, in practice, many real-world signals are finite-duration. When
applying the DTFT to such signals, we need to truncate or window the signal, which
introduces artifacts in the frequency domain and affects the accuracy of the analysis. The
implications of the infinite nature of the Discrete-Time Fourier Transform (DTFT) spectrum
are as follows

In-Lab:
Determine the DTFT of x[n]  (0.5)n u[n] analytically. Develop Matlab script for the
same and plot its magnitude, angle, real and imaginary parts. Also show that
DTFT is periodic sequence.
Ans: Analytical Solution
 
X [e jω ]  
n 
x[n] e  jωn  
n 0
(0.5) n e  jωn


(0.5e jω ) n 
1
 
n 0  jω
1 0.5e

1
Matlab Script for direct evaluation of the equation X [e jω ] 
 jω
1 0.5e

4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

PROGRAM:

clear all; close all; clc;


k = -300:300;
w = (pi/100)*k;
X = exp(j*w)./ (exp(j*w) - 0.5);
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');
subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');

5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Matlab Script for DTFT of a given sequence using freqz.m function


From the magnitude and phase spectrums, it is concluded that the spectrum of given
aperiodic sequence is a periodic sequence with period 2 .
PROGRAM:

clear all; close all; clc;


k = -300:300;
w = (pi/100)*k;
num = [1];
den = [ 1 -0.5];
X = freqz(num, den, w);
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');
subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');

6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Determine the frequency response H [e jω ] of a system characterized

by h[n]   0.9  u[n] . Plot the magnitude and the phase responses.
n

1
Ans: Analytical Solution: H [e jω ] 
1 0.9e  jω

1 1
| H [e jω ] |   , and
(1 0.9 cos ω) 2 +(0.9 cos ω) 2 1.811.8 cos ω

 0.9 sin ω 
H [e jω ]   arctan  
1 0.9 cos ω 
 
PROGRAM:

clear all; close all; clc;


k = -300:300;
w = (pi/100)*k;
H = exp(j*w) ./ (exp(j*w) - 0.9);
magH = abs(H);
angH = angle(H);
subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

An LTI system is specified by the difference equation y[n]  0.8y[n  1]  x[n]

(a) Determine H [e jω ] .

1
H [e jω ] 
1 0.8e  jω
PROGRAM:

clear all; close all; clc;


k = -300:300;
w = (pi/100)*k
H = exp(j*w) ./ (exp(j*w) - 0.8*ones(size(w)));
magH = abs(H);
angH = angle(H);
figure();
subplot(2,1,1); plot(w/pi,magH,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,1,2); plot(w/pi,angH,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Sample VIVA-VOCE questions (In lab):


1. What is the Discrete-Time Fourier Transform (DTFT), and how does
it differ from the Discrete Fourier Transform (DFT)?
A. DTFT is continuous in itself, though it's a transformation of a discrete
signal. DFT is discrete in nature; it's not continuous, and is also finite in
length.
2. Explain the significance of the DTFT in signal processing. How does it
help in an alyzing the frequency content of discrete-time signals?
A. The discrete-time Fourier transform X(ω) of a discrete-time sequence x(n)
represents the frequency content of the sequence x(n) . Therefore, by taking the
Fourier transform of the discrete-time sequence, the sequence is decomposed
into its frequency components.
3. What are the properties of the DTFT? Discuss the linearity, time shifting,
frequency shifting, and convolution properties with examples.
The Discrete Time Fourier Transform (DTFT) has several important properties,
including linearity, time shifting, frequency shifting, convolution, and duality.
4. How is the DTFT computed in MATLAB? Describe the role of the `freqz`
function and the interpretation of its output.
The freqz function in MATLAB takes two main inputs: the numerator coefficients
of the filter's transfer function (b) and the denominator coefficients (a). These
coefficients define the filter's transfer function in the z-domain.
5. What are the advantages and limitations of the DTFT? How does the
infinite nature of the DTFT spectrum affect practical implementations?
Advantages of DTFT:
1. It provides a complete representation of the frequency content of a
discrete-time signal, including both magnitude and phase information.
2. The DTFT is a linear transformation, which means it can be used to
analyze and manipulate signals using various algebraic operations.
Limitations of DTFT:
1. The DTFT assumes that the input signal is infinite in duration, which is
often not the case in practical applications. In practice, signals are usually
sampled for a finite duration, leading to a finite number of samples. This
can result in spectral leakage and distortion when applying the DTFT
directly to finite-duration signals.
2. The DTFT produces a continuous frequency spectrum, which makes it
difficult to analyze individual frequency components in a signal with high
spectral resolution. The spectrum is sampled at equally spaced
frequencies, and the resolution is determined by the number of samples
used in the analysis.

9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Post - lab:
Determine the DTFT analytically for following sequences.
Develop Matlab scripts for determining DTFT using Matlab. Plot its magnitude,
angle, real and imaginary parts. Verify the periodicity for each case.
(A) x[n]  {2  1 0 1 2}

PROGRAM:
clear all; close all; clc;
k = -300:300;
w = (pi/100)*k
X = -2*exp(2*j*w)-exp(j*w)+exp(-j*w)+2*exp(-2*j*w);
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');

 
n
(b) x[n]  1 u[n  2]
2
PRO\GRAM:
clear all; close all; clc;
k = -300:300
w = (pi/100)*k
X = exp(-j*w) ./ (exp(j*w) - 0.5*ones(size(w)));
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid

10
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

xlabel('frequency in pi units---->'); ylabel('Magnitude---->');


title('Magnitude Spectrum');
legend('2100040287');
subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');
subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');

(c) x[n]  (0.8) | n |


PROGRAM:
clear all; close all; clc;
k = -300:300;
w = (pi/100)*k;
X = -1+1./(1-(0.8*exp(j*w)))+1./(1-(0.8*exp(-j*w)));
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1); plot(w/pi,magX,'r','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Magnitude---->');
title('Magnitude Spectrum');
legend('2100040287');
subplot(2,2,2); plot(w/pi,angX,'b','LineWidth',1.5); grid
xlabel('frequency in pi units---->');ylabel('Radians---->') ;
title('Phase Spectrum');
subplot(2,2,3); plot(w/pi,realX,'m','LineWidth',1.5); grid
xlabel('frequency in pi units---->'); ylabel('Real');
title('Real Part--->');
subplot(2,2,4); plot(w/pi,imagX,'k','LineWidth',1.5); grid

11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

xlabel('frequency in pi units---->');ylabel('Imaginary---->');
title('Imaginary Part');

Evaluator Remark (if Any):


Marks Secured: out of 50

12
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Experiment 6 Student ID 2100040287


Date Student Name K. BINDU SRI

Experiment Title: Discrete Fourier Transform (DFT)


Aim/objectives:
The aim of an experiment involving the Discrete Fourier Transform (DFT) in MATLAB can vary
depending on the specific context and objectives of the experiment. However, in general, the
aim of a DFT experiment in MATLAB is to explore and analyze the frequency content of a
discrete signal using the DFT algorithm. 1. Understanding the DFT algorithm: The aim might be
to gain a better understanding of how the DFT works by implementing the algorithm in MATLAB
and analyzing its output. 2. Frequency analysis of signals. By applying the DFT to the signals, you
can examine the magnitude and phase information of the frequency components
Description:
Frequency analysis of DT sequences is usually and most conveniently performed on a digital
Signal Processor, which may be a general purpose computer or specially designed digital
hardware. To perform frequency analysis on DT sequences x[ n ] , a discrete time Fourier
transform (DTFT) , X [e j ] is used. However X [e j ] continuous function of frequency and
therefore it is not a computationally convenient representation of the sequence x[ n ] .
To overcome this difficulty, the frequency spectrum of an aperiodic sequence is discretized.
Such a frequency-domain represented leads to the discrete Fourier transform (DFT), which is a
powerful computational tool for performing frequency analysis of discrete-time sequences.
Discrete Fourier Transform: The analysis and Synthesis equations for N-point DFT are defined as
N 1
Analysis equation: X [k ]  
n0
x[n] WNkn , k  0, 1, ... , N  1 ,

1 N 1
Synthesis equation: x[n]  
N k 0
X [k ] WNkn , n  0, 1, ... , N  1

j 2 k
where WNk  e N is known as twiddle factor.

Pre-requisites: Digital Computer with MATLAB software


Pre-lab
1) How do I compute the DFT of a signal in MATLAB?
To compute the Discrete Fourier Transform (DFT) of a signal in MATLAB, you can use the built-in
function fft. Here's an example of how you can use it:
2)How can I visualize the frequency spectrum obtained from the DFT?
To visualize the frequency spectrum obtained from the Discrete Fourier Transform (DFT), you can
plot the magnitude or power spectrum. we plot the magnitude spectrum by plotting the absolute
values of the DFT coefficients (abs(X)) against the corresponding frequencies.
3)How can I obtain the frequency values corresponding to the DFT coefficients?

1
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

To obtain the frequency values corresponding to the DFT coefficients, you can use the sampling
rate and the length of the DFT. Frequency=(index/N)*sample_rate
4)How can I filter a signal using the DFT in MATLAB?
To filter a signal using the DFT in MATLAB, you can follow these steps:
1)Compute the DFT of the input signal using the fft function.
2)Manipulate the frequency domain representation of the signal by applying a desired filter
operation.
5)How can I compute the DFT of a real-valued signal efficiently?
Computing the Discrete Fourier Transform (DFT) of a real-valued signal efficiently can be done
using the Fast Fourier Transform (FFT) algorithm, which takes advantage of the symmetry
properties of the DFT for real signals.

IN LAB:
Let x[ n ] be a 4-point sequence:
 1, 0  n  3
x[n]  
0, Otherwise
(a) Compute the N-point DFT of x[ n ] , where the cases (i) N = 4, (ii) N =8.
(b) Develop Matlab codes for the part(a) and plot the magnitude and phase response

(i) MATLAB CODE


clc; clear all; close all;
x = [1,1,1,1];
N = 4;
n = 0:N-1; % Time axis
X = fft (x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->');title('Original Sequence');
legend("2100040287");
axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);

OUTPUT WAVEFORM:

2
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

(ii) MATLAB CODE


clc; clear all; close all;
x = [1,1,1,1,0,0,0,0];
N = 8;
n = 0:N-1; % Time axis
X = fft(x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->');title('Original Sequence'); legend('2100040287');
axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);
OUTPUT WAVEFORM:

Develop Matlab codes for the results in Ex1 for inverse DFT. plot the corresponding
sequences.
i)MATLAB CODE:
clc; clear all; close all;
X = [4 0 0 0];
N = length(X);
k = 0:N-1; % Frequency axis
x = ifft(X,N); % Inverse DFT
n = 0:N-1; % Time axis
figure();
subplot(2,1,1); stem(k,abs(X),'r','fill','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->');title('Original Sequence');legend('2100040287');
axis([-1 N -0.2 4.2]);
subplot(2,1,2); stem(n,abs(x),'b','fill','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 1.2]);

3
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

OUTPUT WAVEFORM:

(ii)MATLAB CODE:
clc; clear all; close all;
X = [4 1-2.4142i 0 1-0.4142i 0 1+0.4142i 0 1+2.4142i];
N = length(X);
k = 0:N-1; % Frequency axis
x = ifft(X,N); % Inverse DFT
n = 0:N-1; % Time axis
figure();
subplot(2,1,1); stem(k,abs(X),'r','fill','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->'); title('Original Sequence');
legend("2100040287");
axis([-1 N -0.2 4.2]);
subplot(2,1,2); stem(n,abs(x),'b','fill','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ; title('Magnitude Spectrzum');
axis([-1 N -0.2 1.2]);
Output Waveform:

Sample Viva-Voce questions:


1. What is the purpose of the Discrete Fourier Transform (DFT) in MATLAB?
The discrete Fourier transform, or DFT, is the primary tool of digital signal
processing. The foundation of the product is the fast Fourier transform (FFT), a
method for computing the DFT with reduced execution time.

4
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

2. How can you obtain the frequency components of a signal using the DFT in
MATLAB?
 Define your signal
 Apply the DFT using the fft function
 Generate the frequency axis
3. What is the significance of zero-padding in the DFT computation in
MATLAB?
. Zero padding enables you to obtain more accurate amplitude estimates of
resolvable signal components. On the other hand, zero padding does not
improve the spectral (frequency) resolution of the DFT. The resolution is
determined by the number of samples and the sample rate.
4. How can you visualize the frequency spectrum obtained from the DFT in
MATLAB?
You can visualize the frequency spectrum obtained from the Discrete Fourier
Transform (DFT) in MATLAB using various plotting functions. Here are a few
common methods:
 Plotting the magnitude spectrum
 Plotting the power spectrum:
 Plotting the phase spectrum:
 Plotting the real and imaginary components
POST LAB

Consider the following sequences.


(i) x[n]  {2  1 0 1 2}
Determine the N-point DFT using direct DFT dft.m for the cases N = 8
(a) Verify the results by computing analytically for N = 8.
(b) Plot the Magnitude phase spectrum for each.
Matlab code:
clc; clear all; close all;
x = [-2,-1,0,1,2,0,0,0];
N = 8;
n = 0:N-1; % Time axis
X = fft(x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->'); title('Original Sequence');
legend('2100040287');
axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);

5
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Determine the Inverse DFT using idft.m function for the following sequences.
(a) x[n]  0 4 - j9.6569 0 4 - j1.6569 0 4+ j1.6569 0 4+ j9.6569
(b) x[n]  2 0.5- j1.2071 0 0.5- j0.2071 0 0.5+ j0.2071 0 0.5+ j1.2071

(a) MATLAB CODE:


clc; clear all; close all;
x=[0,4-9.6569i, 0,4-1.6569i,0,4+1.6569i,0,4+9.6569i]
N=length(x);
n=0:N-1;
X=ifft(x,N);
k=0:N-1;
magX=abs(X);
phaX=angle(X)*180/pi;
subplot(2,1,1);
stem(n,x,'g',LineWidth=3);grid
xlabel('n---->');ylabel('magnitude---->');title('original
sequence');
legend("2100040287");
axis([-1 8 -0.2 1.2]);
subplot(2,1,2);
stem(k,magX,'r',LineWidth=3); hold on;
plot(k,magX,'---k',Linewidth,1);
xlabel('frequency k-->');ylabel('magnitude---->');title('Magnitude spectrum');
grid
axis([-1 N -0.2 max(magX)+1]);
xlabel('frequency K----->');ylabel('magnitude ------->');title('magnitude spectrum');
axis([ -1 N -0.2 1.2]);

(B) MATLAB CODE:


clc; clear all; close all;
x=[2,0.5-1.2071i,0,0.5-0.271i,0,0.5+0.2071i,0,0.5+1.2071i]
N=length(x);
n=0:N-1;
X=ifft(x,N);
k=0:N-1;
magX=abs(X);
phaX=angle(X)*180/pi;
subplot(2,1,1);
stem(n,x,lineWidth=3);
grid ;
legend("2100040287");
xlabel('n---->');ylabel('magnitude---->');title('original sequence');
axis([-1 8 -0.2 1.2]);
subplot(2,1,2);

6
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

stem(k,magX,lineWidth=3);
hold on;
xlabel('frequency k-->');ylabel('magnitude---->');title('Magnitude spectrum');grid
axis([-1 N -0.2 max(magX)+1]);
xlabel('frequency K----->');ylabel('magnitude ------->');title('magnitude spectrum');
axis([ -1 N -0.2 1.2]);

OUTPUT WAVEFORM:

Evaluator Remark (if Any):


Marks Secured: out of 50

Signature of the Evaluator with Date

7
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

8
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Experiment 7 Student ID 2100040287


Date Student Name K. BINDU SRI

Experiment Title: Fast Fourier Transform (FFT)

Aim/objectives: The aim of an FFT experiment in MATLAB is to explore and analyze the
frequency content of a signal efficiently using the FFT algorithm.
objectives :
1. Time-frequency analysis: The aim might be to analyze the time-varying frequency content of a
signal. By applying the FFT to different segments of the signal, you can observe how the
frequency components change over time and identify any transient or evolving patterns.
2. Spectral analysis: The aim might be to perform spectral analysis of a signal using the FFT. This
involves estimating the power spectral density (PSD) or the amplitude spectrum of the signal to
identify dominant frequencies and their magnitudes.
Description:
FFT, which stands for Fast Fourier Transform, is a widely used algorithm in digital signal
processing and mathematics. It is an efficient method for computing the discrete Fourier
transform (DFT) and its inverse (IDFT). The DFT is a mathematical transform that converts a
time-domain signal into its frequency-domain representation, revealing the underlying
frequency components.
The basic idea behind the FFT is to exploit the symmetry properties of complex exponentials and
divide the DFT computation into smaller, simpler subproblems. The algorithm recursively divides
the input sequence into halves, applies the DFT to each half, and then combines the results to
obtain the final frequency-domain representation.
In conclusion, the Fast Fourier Transform (FFT) is a powerful algorithm for efficiently computing
the discrete Fourier transform of a signal. It has had a profound impact on the field of signal
processing and is widely used in various domains to analyze, manipulate, and understand signals
in the frequency domain.
FFT: The FFT is an algorithm that efficiently computes DFT. The direct DFT is inefficient
as it does not exploit the symmetry and periodicity properties of the phase / twiddle
factor W N . This approach depends on the decomposition of an N-point DFT into
successively smaller size DFTs. The total number of complex multiplications is N log 2 N
2
and total number of additions is N log 2 N required to compute N-point DFT.
1idea is that you first take the FFT of the input sequence. Next, you multiply the
transformed signal by the desired frequency response. Finally, you take the inverse FFT.
Pre-requisites: Digital Computer with MATLAB software

1
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Pre-Lab:
1) Describe the concept of the Fast Fourier Transform (FFT) and its advantages
over the Discrete Fourier Transform (DFT).
Here are some key advantages of the FFT over the DFT: 1)Faster Computation: The FFT
algorithm has a complexity of O(N log N), whereas the DFT has a complexity of O(N^2), where
N is the size of the input sequence. As a result, the FFT can be much faster, especially for large
input sizes.
2)Memory Efficiency: The FFT does not require additional memory for intermediate calculations,
unlike the DFT. This is because the FFT algorithm performs in-place calculations, using only the
original memory space.
2. Explain the process of zero-padding in the context of FFT computations. How does it
affect the frequency resolution of the resulting spectrum?
zero-padding refers to the technique of appending additional zeros to the original input sequence
before performing the FFT. This is done to increase the length of the input sequence, usually to a
power of two, which can result in certain benefits.When zero-padding is applied, the original input
sequence is extended with zeros to match the desired length.
3)Discuss the importance of windowing in FFT analysis. What types of window
functions are commonly used and why?
Windowing is a technique used in signal processing to reduce the effects of spectral leakage
when performing a Fourier transform (FT) on a finite-length signal. Spectral leakage is the
phenomenon of energy from one frequency component of a signal being spread out to other
frequency components due to the truncation of the signal.
4)Describe the relationship between time-domain and frequency-domain
representations of a signal when using the FFT. How does the FFT facilitate this
transformation?
The Fast Fourier Transform (FFT) is a mathematical algorithm that can be used to convert a
signal from the time domain to the frequency domain, and vice versa. The time domain is a
representation of the signal as a function of time, while the frequency domain is a
representation of the signal as a function of frequency.
5. Discuss the applications of FFT in various fields such as audio processing, image
analysis, and signal processing. Provide examples of how FFT is used in practical
scenarios
1)Audio processing: The FFT is used in audio processing for a variety of tasks, such as:

2)Spectral analysis: This is the process of determining the frequency components of a


sound signal.

3)Noise reduction: This is the process of removing unwanted noise from a sound signal.

2
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

In-lab
Let x[ n ] be a 4-point sequence:
 1, 0  n  3
x[n]  
0, Otherwise
(a) Compute the N-point FFT of x[ n ] , where the cases (i) N = 4, (ii) N =8.
(b) Develop Matlab codes for the part(a) and plot the magnitude and phase response
(i) MATLAB CODE
clc; clear all; close all;
x = [1,1,1,1]; N = 4;
n = 0:N-1; % Time axis
X = fft (x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->');
title('Original Sequence');
legend("2100040287");axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);

ii)MATLAB CODE:
clc; clear all; close all;
x = [1,1,1,1,0,0,0,0];
N = 8;
n = 0:N-1; % Time axis
X = fft(x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid

3
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

xlabel('n---->'); ylabel('Magnitude---->');title('Original Sequence');


legend('2100040287');
axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);

OUTPUT WAVEFORM:

Sample viva voce questions:


1. What does the term "FFT" stand for, and what is its significance in signal
processing?
The "Fast Fourier Transform" (FFT) is an important measurement method in the science
of audio and acoustics measurement. It converts a signal into individual spectral
components and thereby provides frequency information about the signal.
2. Explain the basic steps involved in computing the FFT of a signal using MATLAB.
 Define your signal
 Choose the desired FFT length
 Apply zero-padding if necessary
 Compute the FFT using the fft function
 Generate the frequency axis
3. How does the length of the input signal affect the FFT computation in MATLAB?
Can the input signal length be arbitrary, or are there specific requirements?
Efficiency: The FFT algorithm is most efficient when the length of the input signal is a
power of 2 (e.g., 2, 4, 8, 16, etc.).
Zero-padding: In MATLAB, you can apply zero-padding to the input signal to achieve a
desired FFT length. Zero-padding involves appending zeros to the end of the input signal
to match the desired length.
Frequency resolution: The length of the input signal affects the frequency resolution of
the FFT output. The frequency resolution is the minimum frequency difference that can
be resolved by the FFT.

4. Describe the concept of frequency resolution in the context of FFT analysis. How
is it determined, and what factors can affect it?
Frequency resolution is determined by the formula: frequency resolution = sampling
frequency / length of the input signal

4
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

Post-Lab:
Consider the following sequences.
(i) x[n]  {2  1 0 1 2}
Determine the FFT using fft.m Matlab functions for the cases N = 8
(a) Verify the results by computing analytically for N = 8.
(b) Plot the Magnitude phase spectrum for each.
Matlab code:
clc; clear all; close all;
x = [-2,-1,0,1,2,0,0,0];
N = 8;
n = 0:N-1; % Time axis
X = fft(x,N);
k = 0:N-1; % Frequency axis
magX = abs(X); phaX = angle(round(X))*180/pi;
subplot(3,1,1); stem(n,x,'r','LineWidth',1.5); grid
xlabel('n---->'); ylabel('Magnitude---->'); title('Original Sequence');
legend('2100040287');
axis([-1 N -0.2 1.2]);
subplot(3,1,2); stem(k,magX,'b','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Magnitude ---->') ;title('Magnitude Spectrum');
axis([-1 N -0.2 4.2]);
subplot(3,1,3); stem(k,phaX,'m','LineWidth',1.5); grid
xlabel('frequency K ---->'); ylabel('Radians---->');title('Phase Spectrum');
axis([-1 N min(phaX)-10 max(phaX)+10]);

Output Waveform:

Determine the Inverse FFT using ifft.m functions for the following sequences.
(a) x[n]  0 4 - j9.6569 0 4 - j1.6569 0 4+ j1.6569 0 4+ j9.6569
(b) x[n]  2 0.5- j1.2071 0 0.5- j0.2071 0 0.5+ j0.2071 0 0.5+ j1.2071

(a)MATLAB CODE:
clc; clear all; close all;
x=[0,4-9.6569i, 0,4-1.6569i,0,4+1.6569i,0,4+9.6569i]

5
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

N=length(x);
n=0:N-1;
X=ifft(x,N);
k=0:N-1;
magX=abs(X);
phaX=angle(X)*180/pi;
subplot(2,1,1);
stem(n,x,'g',LineWidth=3);grid
legend("2100040287");
xlabel('n---->');ylabel('magnitude---->');title('original sequence');
axis([-1 8 -0.2 1.2]);
subplot(2,1,2);
stem(k,magX,'r',LineWidth=3); hold on;
plot(k,magX,'---k',Linewidth,1);
xlabel('frequency k-->');ylabel('magnitude---->');title('Magnitude spectrum');
grid
axis([-1 N -0.2 max(magX)+1]);
xlabel('frequency K----->');ylabel('magnitude ------->');title('magnitude spectrum');
axis([ -1 N -0.2 1.2]);

OUTPUT WAVE FORM:

(B)MATLAB CODE:
clc; clear all; close all;
x=[2,0.5-1.2071i,0,0.5-0.271i,0,0.5+0.2071i,0,0.5+1.2071i]
N=length(x);
n=0:N-1;
X=ifft(x,N);
k=0:N-1;
magX=abs(X);
phaX=angle(X)*180/pi;
subplot(2,1,1);
stem(n,x,lineWidth=3); grid
legend("2100040287");
xlabel('n---->');ylabel('magnitude---->');title('original sequence');
axis([-1 8 -0.2 1.2]);
subplot(2,1,2);

6
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

stem(k,magX,lineWidth=3);
hold on;
xlabel('frequency k-->');ylabel('magnitude---->');title('Magnitude spectrum');grid
axis([-1 N -0.2 max(magX)+1]);
xlabel('frequency K----->');ylabel('magnitude ------->');title('magnitude spectrum');
axis([ -1 N -0.2 1.2]);

OUTPUT WAVEFORM:

Evaluator Remark (if Any):


Marks Secured: out of 50

Signature of the Evaluator with Date

You might also like