DSP LAB DOC (Sur)
DSP LAB DOC (Sur)
Student Id No:
Remarks:
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
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.
* Note that commas could have been used in place of spaces to separate the
elements. that is
>> v = [1,3,5,7];
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:
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:
5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
9.Control Structures:
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:
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:
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:
11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
Remarks:
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
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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.
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
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:
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
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')
7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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)];
y = sin(2*pi*f*t);
t = 0:1/1000:1;
y = square(2*pi*f*t);
9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
Remarks:
Description:
y (t ) ax(t )
1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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.
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
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
Examples:
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');
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:
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)');
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:
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)');
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:
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:
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);
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');
11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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:
(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:
Remarks:
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:
Pre-Lab:
2
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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.
4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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)');
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:
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 jn } and is called the discrete-time Fourier transform (DTFT).
X [e jω ]
n
x[n] e jωn
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ω .
X [e jω ] X re [e jω ] j X im[e jω ]
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.
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.
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:
5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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.811.8 cos ω
0.9 sin ω
H [e jω ] arctan
1 0.9 cos ω
PROGRAM:
7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
(a) Determine H [e jω ] .
1
H [e jω ]
1 0.8e jω
PROGRAM:
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:
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:
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');
12
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
1 N 1
Synthesis equation: x[n]
N k 0
X [k ] WNkn , n 0, 1, ... , N 1
j 2 k
where WNk e N is known as twiddle factor.
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
OUTPUT WAVEFORM:
2
Digital Signal Prpcessing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
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:
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
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
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:
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:
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:
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:
OUTPUT WAVEFORM:
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]);
(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: