Laboratory Manual 2021-2022: Digital Signal Processing Laboratory
Laboratory Manual 2021-2022: Digital Signal Processing Laboratory
Laboratory Manual 2021-2022: Digital Signal Processing Laboratory
LABORATORY MANUAL
2021-2022
VI Semester B.E. (Electrical & Electronics Engg.)
Don’ts
1. Download and /or installation of any software / program/game on any of the computers is
PROHIBITED without taking permission from your laboratory instructor/ teaching staff.
2. Students should not attempt to repair, open, tamper or interfere with any of the computers,
printers cabling or any other equipment in the laboratory.
3. Do not tamper the equipment in lab.
4. Do not damage the connecting pins.
5. Do not plug in external devices (e.g. pen drive, cell phone etc)
S. S. Education Trust’s CET Code: E-175 (UG)/T-942 (PG)
CO-PO/PSO Mapping
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
C307.1 1 - - - 1 - - 1 1 1 - - - -
C307.2 1 2 2 - 1 - - 1 1 1 - - - -
C307.3 1 2 2 - 1 - - 1 1 1 - - - -
C307.4 1 2 2 - 1 - - 1 1 1 - - - -
C307.5 1 2 2 - 1 - - 1 1 1 - - - -
C307.6 1 2 2 - 1 - - 1 1 1 - - - -
C307 1 2 2 - 1 - - 1 1 1 - - - -
Index
Sl. No Experiment Page No
Verification of Sampling Theorem both in time and
1. 15-18
frequency domains.
To impart Quality Education with Human values and emerge as one of the Nation’s leading Institutions
in the field of Technical Education and Research.
MISSION:
VISION
To impart quality Electrical and Electronics Engineering education and empower students with
technical, innovative and professional skills to compete with rapid changing global challenges.
MISSION
Mission 1: To develop creativity, innovation, problem solving skills and academic excellence in
Electrical and Electronics Engineering.
Mission 2: To foster research and development activities in the fields of Electrical and Electronics
Engineering.
Mission 3: To inculcate leadership qualities and team spirit by encouraging participation in various
events in Electrical and Electronics Engineering.
Mission 4: To encourage development of entrepreneurial skills and professional ethics in the field of
Electrical and Electronics Engineering.
PO2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
PO4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, andsynthesis
of the information to provide valid conclusions.
PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilitiesrelevant
to the professional engineering practice.
PO7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
PO11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
EEE DEPT, S.G.B.I.T, BELAGAVI-10 2
DIGITAL SIGNAL PROCESSING LAB 18EEL67
PEO1: Be successful in their professional career, higher studies and research in the field of Electrical
and Electronics Engineering by providing contextually relevant academic environment.
PEO2: Adapt to the changing technologies and market trends in the field of Electrical and Electronics
Engineering by providing appropriate awareness and practices.
PEO3: Present technological concepts and theories in Electrical and Electronics Engineering by
enabling logical thinking, leadership qualities and entrepreneurial skills through effective
communication.
PEO4: Practice Engineering profession with ethics to serve the society.
PEO5: Demonstrate leadership qualities and managerial skills in a heterogeneous team globally.
VTU SYLLABUS
SCILAB: SCILAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for technical
computation, graphics and animation. The diagram 1 shows the main features and capabilities of
SCILAB.
SCILAB
TOOL BOX
Signal Processing Image Processing
Statistics Control Systems
Neural Network Communications
It also allows you to put a list of your processing requests together in a file and save that
combined list with a name so that you can run all of those commands in the same order at some
later time. Furthermore, it allows you to run such lists of commands such that you pass in data
and/or get data back out (i.e. the list of commands is like a function in most programming
languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you as
if it were part of the basic toolbox that you started with).
For those with computer programming backgrounds: Note that SCILAB runs as an
interpretive language (like the old BASIC). That is, it does not need to be compiled. It simply reads
through each line of the function, executes it, and then goes on to the next line. (In practice,a form
of compilation occurs when you first run a function, so that it can run faster the next time you run
it.
SCILAB Windows:
SCILAB works with through three basic windows
Command Window: This is the main window. It is characterized by SCILAB command prompt
>> when you launch the application program SCILAB puts you in this window all commands
including those for user-written programs ,are typed in this window at the SCILAB prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called M
files.
INPUT-OUTPUT:
SCILAB supports interactive computation taking the input from the screen and flushing,
the output to the screen. In addition, it can read input files and write output files
Data Type: the fundamental data –type in SCILAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells. There is no
need to declare variables as real or complex, SCILAB automatically sets the variable to be real.
Dimensioning: Dimensioning is automatic in SCILAB. No dimension statements are required for
vectors or arrays. We can find the dimensions of an existing matrix or a vector with the size and
length commands.
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an increment
of 1. Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 ……… 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. Zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. Ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 1 1
11
11
11
11
6. Zeros (2, 4)
Output = 0 0 0 0
0000
7. a = [ 1 2 3] , b = [4 5 6]
THEN a.*b = [4 10 18]
i.e. [4*1 5*2 6*3]
8. if C= [2 2 2] and b = [4 5 6]
b.*C results in [8 10 12]
9. Plot (t, x)
If x = [6 7 8 9] and t = [1 2 3 4]; this instruction will display a figure window which indicates the
plot of x versus t as shown in the figure 2
Ramp Signal
Exponential Signal
Sine wave
x(n) = Sin n
x(n) = Sin t
Cosine wave
x(n) = Cos n
x(n) = Cos t
PROGRAM
clc; % clear screen
clear all; % clear workspace
close all; % close all figure windows
% to generate unit impulse signal
subplot (2,2,3);
% to generate exponential
N2 = input ('enter the length N2 = '); % define the length of unit step signal
a = input ('enter the value of a = '); % if a is +ve –Rising exponential, a is –ve decaying
Exponential
OUTPUT:
Enter the value of N = 10
enter the value of N1 = 10
enter the length N2 = 6
enter the value of a = 3
VIVA QUESTIONS:
1. Define Signal.
A signal is defined as any physical quantity that varies with time, space or any other
independent variable or variables
The discrete signal is a function of a discrete independent variable which is an integer. The
independent variable is divided into uniform intervals and each interval is represented by an integer.
The discrete signal is defined for every integer value of the independent variable. The magnitude of
The digital signal is same as discrete signal except that the magnitude of the signal is
quantized. The magnitude of the signal can take one of the values in a set of quantized values.
Here quantization is necessary to represent the signal in binary codes.
6. How will you classify the discrete time signals?
The discrete time signals are classified depending on their characteristics. Some ways
of classifying discrete time signals are (a) Energy signals and Power signals, (b) Periodic and
Aperiodic signals, (c) Symmetric and Anti symmetric signals.
SAMPLING THEOREM
AIM: Verification of sampling theorem.
Objectives:
• After completing this experiment, student will be able to verify sampling theorem using
SCILAB.
• Study the importance of Sampling Theorem with its conditions.
• Study the plotting of frequency spectrum for all the cases of sampling theorem.
THEORY:
Sampling: Is the process of converting a continuous time signal into a discrete time signal. It is
the first step in conversion from analog signal to digital signal.
Sampling theorem: Sampling theorem states that “Exact reconstruction of a continuous time base-
band signal from its samples is possible, if the signal is band-limited and the sampling frequency
is greater than twice the signal bandwidth” i.e., fs> 2W, where W is the signal bandwidth.
Nyquist Rate Sampling: The Nyquist rate is the minimum sampling rate required to avoid
aliasing, equal to the highest modulating frequency contained within the signal. In other words,
Nyquist rate is equal to two-sided bandwidth of the signal (Upper and lower sidebands) i.e., fs =
2W. To avoid aliasing, the sampling rate must exceed the Nyquist rate. i.e., fs>fN, where fN =2W.
PROGRAM LOGIC:
1. Select the frequency of analog signal f Hz
2. To generate sine wave of f Hz define a closely spaced time vector
3. Generate the sinusoid and plot the signal Select the sampling frequency fs= 10f samples/sec.
Generate a suitable time scale for this sampling signal
4. Sample the analog signal at the instant specified by n.
OUTCOMES:
The advantages of DSP are (i) programs can be modified easily for better performance;
(ii) Better accuracy can be achieved by using adaptive algorithms, (iii) digital signals can be
easily stored and transported, (iv)digital systems are cheaper than analog equivalent.
When a discrete time signal x(n) satisfies the condition x(n) = x(n+N), then it is
called periodic, with periodicity of N samples.
When processing the analog signal using DSP System, it is sampled at some rate depending
upon the bandwidth. The rate of sampling is decided by the Nyquist criterion. However, signals that
are found in physical systems will never be strictly band limited. To eliminate signal content beyond
the desired bandwidth, anti-aliasing filter is used. The filter cannot be a digital filter. This is because
anti-alias filtering is required to be performed in the analog domain prior to applying the signal to
A/D converter where aliasing would take place.
AIM: Write a program to find the impulse response of first order and second order systems
THEORY:
• The impulse response of a system is an important response. The impulse response is the response
to a unit impulse.
• The unit impulse has a Laplace transform of unity (1). That gives the unit impulse a unique stature.
If a system has a unit impulse input, the output transform is G(s), where G(s) is the transfer function
of the system. The unit impulse response is therefore the inverse transform of G(s), i.e. g(t), the
time function you get by inverse transforming G(s). If you haven't begun to study Laplace
transforms yet, you can just file these last statements away until you begin to learn about Laplace
transforms. Still there is an important fact buried in all of this.
• Knowing that the impulse response is the inverse transform of the transfer function of a system can
be useful in identifying systems (getting system parameters from measured responses).
ALGORITHM:
PROGRAM LOGIC:
PROGRAM
clc;
clear;
Impulse Response of first order system described by difference equation y(n)+2y (n-1) = x(n)
a1= input ('enter the coefficients of input vector of first order system a1=');
b1= input ('enter the coefficients of output vector of first order system b1=');
n1= input ('enter the lower of impulse response n1=');
n2= input ('enter the upper of impulse response n2=');
n=n1: n2
//generate the impulse input function
x=zeros (1, length (n));
for i=1: length (n)
if n(i) ==0
x(i)=1;
end
end
h1= filter (a1, b1, x); // find the impulse response of first order system
disp (h1); // display the values of impulse response in console window
subplot (2 ,1 ,1)
plot2d3 (n, h1); // to plot the impulse response of system in graphical window
xlabel ('discrete time n');
ylabel ('amplitude');
title ('impulse response of first order system h1 (n)');
// Impulse Response of Second order system described by difference equation
// y(n)+0.5y(n-1) + 0.3 y(n-2) = x (n)+5x (n-1)
a2= input ('enter the coefficients of input vector of second order system a2=');
b2= input ('enter the coefficients of output vector of second order system b2=');
h2= filter (a2, b2, x); // find the impulse response of system
disp (h2); // display the values of impulse response in console window
subplot (2 ,1 ,2)
plot2d3 (n, h2); // to plot the impulse response of system in graphical window
xlabel ('discrete time n');
ylabel ('amplitude');
title ('impulse response of second order system h2(n)');
Output:
// enter the coefficients of input vector of first order system a1 = [ 1]
// enter the coefficients of output vector of first order system b1 = [12]
// enter the lower of impulse response n1=0
// enter the upper of impulse response n2=5
// 1. -2. 4. -8. 16. -32.
// enter the coefficients of input vector of second order system a2 = [15]
// enter the coefficients of output vector of second order system b2 = [1 0.5 0.3]
// column 1 to 5
// 1. 4.5 -2.55 -0.075 0.8025
// column 6
// -0.37875
Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
ALGORITHM:
1. Input the two sequences x1 and x2
2. Use conv to get convoluted output.
3. Plot the sequences.
PROGRAM LOGIC:
The convolution Sum is given by
1. The impulse response h[k] is time reversed (that is reflected about the origin) to obtain h[-k]
and then shifted by n to form h[n-k] = h[-(k-n)] which is a function of K with Parameter n.
2. Two sequences x[k] and h[n-k] are multiplied together for all values of k with n fixed at some
value
3. The product x[k]h[n-k] is summed over all k to produce a single output sample y[n]
4. Steps 1 to 3 are repeated as n varies over -∞ to +∞ o produce the entire output y[n]
CALCULATION:
On simplification we get,
OUTPUT:
enter the first sequence x1(n) = [1 2 3 4]
enter the second sequence x2(n) = [3 6 7 2]
Linear convolution of x1 and x2 is = 3 12 28 46 49 34 8
CIRCULAR CONVOLUTION
THEORY: Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)] where X3(k) = X1(k) X2(k)
𝑁−1
𝑥3(𝑛) = ∑ 𝑥1(𝑚)𝑥2((𝑛 − 𝑚)) 𝑁
𝑚=0
ALGORITHM:
1. Input the two sequences x and h
2. Circularly convolve both to get the output of y.
3. Plot the sequences.
PROGRAM LOGIC:
1.Read the first input sequence, x[n] and plot.
7. For each output sample access the samples of y[n] in cyclic order.
8. Find the sum of products of x[n] and cyclically folded and shifted h[n] to get circular
convoluted output.
9. Display and plot the output.
EXAMPLE:
Let’s take x1(n) = {1, 1, 2, 1} and x2(n) = {1, 2, 3, 4}
x3(0) = x1(m) x2(-m)
EEE DEPT, S.G.B.I.T, BELAGAVI-10 25
DIGITAL SIGNAL PROCESSING LAB 18EEL67
i=i+N;
end
y(n+1) =y(n+1) + hn(m+1) * xn(i+1);
end
end
disp ('Circular convolution in Time Domain =');
disp(y); % display the output
subplot (2,2,1); % graphical plot the first input sequence
plot2d3 (xn);
xlabel('n');
ylabel('x(n)');
title ('Plot of x(n)');
subplot (2,2,2); % graphical plot the second input sequence
plot2d3 (hn);
xlabel('n');
ylabel('h(n)');
title ('Plot of h(n)');
subplot (2,2,3); % graphical plot the output sequence
plot2d3 (y);
xlabel('n');
ylabel('y(n)');
title ('Circular Convolution Output');
OUTPUT:
enter the first sequence x(n) = [1 2 3]
enter the second sequence h(n) = [1 5 6 7]
Circular convolution in Time Domain =
33 28 19 34
OUTCOMES:
• To Study the importance of linear and circular convolution with its mathematical
expression.
• To calculate the output for any linear time invariant system given its input and its impulse
response linear convolution is used as basic operation.
Viva Questions:
1. What is the length of linearly convolved signals?
Length of linearly convolved signal is always equal to N = L + M - 1 where L is length of
first signal and M is length of second signal.
The response or output of LTI discrete time system for any input x(n) is given by linear
convolution of the input x(n) and the impulse response h(n) of the system. This means that if the
impulse response of a system is known, then the response of the system for any input can be
determined by convolution operation.
The Discrete Fourier Transform (DFT) is used for the analysis and design of discrete time
systems using digital computers. The DFT supports only circular convolution. Hence when
DFT techniques are employed, the results of linear convolution are obtained only via circular
convolution.
N-point DFT
AIM: To compute N-point DFT of a given sequence and to plot magnitude and phase spectrum.
OBJECTIVES:
After completion of this experiment the students are able to compute the N point DFT of a given sequence
and to plot magnitude and phase spectrum.
THEORY: Discrete Fourier Transform is a powerful computation tool which allows us to evaluate
the Fourier Transform X(ejω) on a digital computer or specially designed digital hardware. Since
X(ejω) is continuous and periodic, the DFT is obtained by sampling one period of the Fourier
Transform at a finite number of frequency points. Apart from determining the frequency content of
a signal, DFT is used to perform linear filtering operations in the frequency domain. The sequence
of N complex numbers x0,...,xN−1 is transformed into the sequence of N complex numbers X0, ..., XN−1
by the DFT according to the formula:
𝑁−1
X(k) = ∑ x(n)e − j2πnk/N
n=0
k = 0,1, …. N-1
EXAMPLE:
Let us assume the input sequence x[n] = [1 1 0 0] we have, For k = 0
𝑁−1
X(k) = ∑ x(n)e − j2πnk/N
k = 0,1, …. N-1
For k = 1, 3
X(0) = ∑ x(n)
𝑛=0
For k = 2
3
𝑛=0
PROGRAM LOGIC:
The analysis equations for Calculating DFT is given by
𝑁−1
X(k) = ∑ x(n)e − j2πnk/N k = 0,1, …. N-1
n=0
𝑁−1
j2πnk
ImX(k) = − ∑ x(n)sin ( ) k = 0,1, …. N-1
n=0 N
OUTPUT:
input sequence
1. 2. 3. 4.
DFT using formula,y
10.
- 2. + 2.i
- 2. - 9.797D-16i
- 2. - 2.i
magnitude response
10.
2.8284271
2.
2.8284271
phase response
0.
2.3561945
- 3.1415927
- 2.3561945
phase response in deg
0.
135.
- 180.
- 135.
DFT using builtin routine, y
10. - 2. + 2.i - 2. - 2.- 2.i
the obtained DFT is same as that of DFT using built in routine
Viva Questions:
OBJECTIVES: To implement circular convolution using DFT and IDFT in time domain
using SCILAB and to verify the result theoretically.
THEORY: Let x1(n) and x2(n) are finite duration sequences both of length N with DFT’s X1(k)
and X2(k). Convolution of two given sequences x1(n) and x2(n) is given by the equation,
x3(n) = IDFT[X3(k)] where X3(k) = X1(k) X2(k)
𝑁−1
𝑥3(𝑛) = ∑ 𝑥1(𝑚) 𝑥2((𝑛 − 𝑚)) 𝑁
𝑚=0
ALGORITHM:
1. Input the two sequences x and h
2. Circularly convolve both to get the output of y.
3. Plot the sequences.
PROGRAM LOGIC:
1.Read the first input sequence, x[n] and plot.
2.Read the second input sequence, h[n] and plot
3.Find the length of x[n] and y[n], l1 and l2 respectively
4. Check if l1=l2. Proceed only if equal.
5.If l1 not equal to l2, zero padding is done to make l1=l2.
6.Initialize a loop variable for the number of output points.
10. For each output sample access the samples of y[n] in cyclic order.
11. Find the sum of products of x[n] and cyclically folded and shifted h[n] to get
circularconvoluted output.
12. Display and plot the output.
PROGRAM
clc;
clear all;
L=4; // Length of the Sequence
N=4; // N −point DFT
x1 = [2, 1, 2,1];
x2 = [1, 2, 3, 4];
//Computing DFT
X1=fft (x1, -1);
X2=fft (x2, -1);
disp (X1,’DFT of x1[n] is X1(k)=’)
disp (X2,’DFT of x1[n] is X2(k)=’)
// Multiplication of 2 DFTs
X3=X1. * X2;
disp (X3,’DFT of x3[n] is X3(k)=’)
// Circular Convolution Result
x3=abs (fft (X3,1))
disp (x3,’Circular Convolution Result x3[n]=’)
//Result
//DFT of x1[n] is X1(k)=
//6 0 2 0
// DFT of x1[n] is X2(k)=
//10 −2+2i −2 −2−2i
// DFT of x3[n] is X3(k)=
// 60 0 −4 0
// Circular Convolution Result x3[n]=
//14 16 14 16
Mathematical Formula:
The linear convolution of two continuous time signals x(t) and h(t) is defined by
Where x(n) is the input signal and h(n) is the impulse response of the system.
ALGORITHM:
1.Input the two sequences x1 and x2
2.Use conv to get convoluted output.
3.Plot the sequences.
PROGRAM LOGIC:
The convolution Sum is given by
• The impulse response h[k] is time reversed (that is reflected about the origin) to obtain h[-k]
and then shifted by n to form h[n-k] = h[-(k-n)] which is a function of K with Parameter n.
• Two sequences x[k] and h[n-k] are multiplied together for all values of k with n fixed at some
value
• The product x[k]h[n-k] is summed over all k to produce a single output sample y[n]
• Steps 1 to 3 are repeated as n varies over -∞ to +∞ o produce the entire output y[n]
PROGRAM:
clc;
clear all;
h = [1, 2, 3]; // Impulse Response of LTI System
x = [1, 2, 2, 1]; // Input Response of LTI System
N1=length(x);
N2=length(h);
N=N1+N2-1
disp (N, ’Length of Output Response y(n)’)
//Padding zeros to Make Length of ‘h’and ‘x’
//Equal to length of output response ‘y’
h1= [h, zeros (1, N-N2)];
x1= [x, zeros (1, N-N1)];
//Computing FFT
H=fft (h1, -1);
X=fft (x1, -1);
//Multiplication of 2 DFTs
Y=X.*H
//Linear Convolution Result
y= abs(fft(Y,1))
disp (X, ‘DFT of i/p X(k)=’)
disp (H, ‘DFT of impulse sequence H(k)=’)
disp (Y, ’DFT of Linear Filter o/p Y(k)=’)
disp (y,’ Linear Convolution result y[n]=’)
//Result
//Length of Output Response y(n)
//6.
1. To solve the given difference equation (response of the filter) by varying the input
sequences as “Impulse input, Exponential input and Sinusoidal input” with and without
initial conditions using an inbuilt SCILAB FILTER function.
THEORY: A General Nth Order Difference equation looks likely [n] + a1y[n-1] + a2y[n-2] + …+
aNy[n-N) = b0x[n] + b1x[n-1] + …. + bMx[n-M]. Here y[n] is “Most advanced” output sample and
y[n-m] is “Least advanced” output sample. The difference between these two index values is the
order of the difference equation. Here we have: n-(n-N) = N
We can rewrite the above equation as,
y[n] + ∑aiy[n-i] = ∑bi x[n-i]
y[n] becomes,
y[n] = -∑aiy[n-i] + ∑bi x[n-i]
EXAMPLE:
y[n-2] – 1.5y[n-1] + y[n] = 2x[n-2]
In general, we start with the “Most advanced” output sample. Here it is y [n+2].
So, here we need to subtract 2 from each sample argument. Thus, we
gety[n] – 1.5y[n-1] + y[n-2] = 2x[n-2]
y[n] = 1.5y[n-1] - y[n-2] + 2x[n-2]
Let us assume our input x[n] = u[n] = 0 x<0
1 x≥0
In our example we have taken x[n] = u[n] = 0 x<0
1 0 ≤ x < 10
We need N past values to solve Nth order difference equation.
y [-2] = 1
y [-1] = 2
5. Find the response y[n] of the system defined by A and B coefficients to the input
excitation using filter command
6. Display and plot the impulse, step, exponential and steady state response y[n]
Step Response:
Enter the length of response = 10
Response of filter =
-1.0000 0.7500 0.8125 1.4844 1.6758 1.9756 2.1223 2.2714 2.3637 2.4427
OUTCOMES:
Acquire the knowledge of construction of different types of digital filters.
Viva Questions:
1. What is Infinite Impulse Response?
When length of h[n] is infinite it is called infinite impulse response. E.g. h[n] = (½)n u[n]
The transfer function of an LTI system is defined as the ratio of Z transform of output to Z
transform of input.
Signal is processed with the same speed it is captured. Signal is captured, sampled and
processed with the same speed. Signal is not stored before processing. Entire input signal never
available before processing. Processed signal can be stored. For example, in digital telephone system,
Signal is captured, Sampled, Processed, and Transmitted and made it available to the end user. Real
Time Processing is Online Processing.
OBJECTIVES:
After completing this lab, student will be able to Study the importance of DFT using Fast Fourier
Transform (FFT) method.
THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\displaystyle O\left(N^{2}\right)}{\displaystyle
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\displaystyle
O(N\log N)}O(N\log N), where {\displaystyle N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.
PROGRAM:
clc;
clear;
Let x(n) = {1, 2, 1, 2, 0, 2, 1, 2}
Let us begin with the programming for understanding, let us write the given data as
x (0) = 1; x (1) = 2, x (2) = 1, x (3) = 2, x (4) = 0, x (5) = 2, x (6) = 1, x (7) = 2
x0=1; //DIT−FFT, so arranging the input in bit−reversed order
x4=0; //DIT−FFT, so arranging the input in bit−reversed order
x2=1; //DIT−FFT, so arranging the input in bit−reversed order
EEE DEPT, S.G.B.I.T, BELAGAVI-10 47
DIGITAL SIGNAL PROCESSING LAB 18EEL67
x6=1; //DIT−FFT, so arranging the input in bit−reversed order
x1=2; //DIT−FFT, so arranging the input in bit−reversed order
x5=2; //DIT−FFT, so arranging the input in bit−reversed order
x3=2; //DIT−FFT, so arranging the input in bit−reversed order
x7=2; //DIT−FFT, so arranging the input in bit−reversed order
//Stage I computation
x0a=x4+x0; //Computing Stage−I output at line 1
disp (x0a, ’Stage−I output at line 1=’)
x4b = (x4 - x0) * (-1); //Computing Stage−I output at line 2
disp (x4b, ’Stage−I output at line 2=’)
x2c=x6+x2; //Computing Stage−I output at line 3
disp (x2c, ’Stage−I output at line 3=’)
x6d = (x6 - x2) * (-1); //Computing Stage−I output at line 4
disp (x6d, ’Stage−I output at line 4=’)
x1e=x5+x1; //Computing Stage−I output at line 5
disp (x1e, ’Stage−I output at line 5=’)
x5f = (x5 - x1) * (-1); // Computing Stage−I output at line 6
disp (x5f, ’Stage−I output at line 6=’)
x3g=x7+x3; //Computing Stage−I output at line 7
disp (x3g, ’Stage−I output at line 7’)
x7h = (x7 - x3) * (-1); //Computing Stage−I output at line 8
disp (x7h, ’Stage−I output at line 8=’)
Stage−I output at line 4 and line 8 is to be multiplied by twiddle factor having value (−j)
x6d1=(x6d) * (-sqrt (-1));
x7h1=(x7h) * (-sqrt (-1));
disp (x6d1, ’Stage−I output (i.e. input to stage −II) after multiplication by twiddle factor value of
(−j) at line 4=’)
disp (x7h1, ’Stage−I output (i.e. input to stage −II) after multiplication by twiddle factor value of
(−j) at line 8=’)
//Stage−II Computations
x0a_stageII_output=x2c+x0a; //Computing Stage−II output at line 1
disp (x0a_stageII_output, ’Stage−II output at line 1=’)
x4b_stageII_output=x6d1+x4b; //Computing Stage−II output at line 2
disp (x4b_stageII_output, ’Stage−II output at line 2=’)
x2c_stageII_output = (x2c - x0a) * (-1); // Computing Stage−II output at line 3
disp (x2c_stageII_output, ’Stage−II output at line 3=’)
x6d_stageII_output = (x6d1 - x4b) * (-1); // Computing Stage−II output at line 4
THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.
PROGRAM:
clc;
clear;
//Let X(k) = {11, 1, −1, 1, −5, 1, −1, 1}
//Let us begin with the programming for understanding, let us write the given data as
X (0) = 11; X (1) = 1, X (2) = −1, X (3) = 1, X (4) = −5, X (5) = 1, X (6) = −1, X (7) = 1
X0_conj =11; //IDIT−FFT, so arranging the input in bit−reversed order
X4_conj =-5; //IDIT−FFT, so arranging the input in bit−reversed order
X2_conj = -1; //IDIT−FFT, so arranging the input in bit−reversed order
X6_conj = -1; //IDIT−FFT, so arranging the input in bit−reversed order
X1_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X5_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X3_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
X7_conj =1; //IDIT−FFT, so arranging the input in bit−reversed order
THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.
PROBLEM:
Computing four-point DFT for x(n) = {1, 2, 3, 4} using Decimation in Frequency−Fast Fourier
transform (i. e. DIF−FFT) without using readymade in-built Sci-lab functions for DFT/FFT.
PROGRAM:
clc;
clear;
x0=1;
x1=2;
x2=3;
x3=4;
//Stage I computation
x0a = x2+x0; //Computing Stage−I output at position 1
disp(x0a, ’Stage−I output at position 1’)
THEORY: A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier
transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its
original domain (often time or space) to a representation in the frequency domain and vice versa.
The DFT is obtained by decomposing a sequence of values into components of different
frequencies. This operation is useful in many fields, but computing it directly from the definition is
often too slow to be practical. An FFT rapidly computes such transformations by factorizing the
DFT matrix into a product of sparse (mostly zero) factors. As a result, it manages to reduce the
complexity of computing the DFT from {\display style O\left(N^{2}\right)}{\display style
O\left(N^{2}\right)}, which arises if one simply applies the definition of DFT, to {\display style
O(N\log N)}O(N\log N), where {\display style N}N is the data size. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In the presence
of round-off error, many FFT algorithms are much more accurate than evaluating the DFT
definition directly or indirectly. There are many different FFT algorithms based on a wide range of
published theories, from simple complex-number arithmetic to group theory and number theory.
PROBLEM:
Computing four-point IDFT for X(k) = {10, −2+2j, −2, −2−2j} using Inverse Decimation in
Frequency−Fast Fourier transform (i. e. IDIF−FFT) without using readymade in- built Sci-lab
functions for IDFT/IFFT.
PROGRAM:
clc;
clear;
//Let us begin with the programming for understanding, let us write the given data as
//X (0) = 10; X (1) = −2+2j, X (2) =−2, X (3) = −2−2j
X0c = 10; //X0c means complex conjugate of XO
X1c = (-2) +((-1) *(2) *(sqrt (-1))); //X1c means complex conjugate of X1
X2c = -2; //X2c means complex conjugate of X2
X3c = (-2) -((-1) *(2) *(sqrt (-1))); //X3c means complex conjugate of X3
OBJECTIVES:
After completing this lab, student will be able to Study the importance of windows to design FIR filter
THEORY: The FIR filters are of non-recursive type, whereby the present output sample is
depending on the present input sample and previous input samples. The transfer function of a FIR
causal filter is given by,
𝑁−1
𝐻(𝑍) = ∑ 𝑛=0 h(n)z-n
In the design of FIR filters most commonly used approach is using windows. The desired frequency
response Hd(ejw) of a filter is periodic in frequency and can be expanded in Fourier series. The
resultant series is given by,
𝜋
hd(n) = (1/2𝜋) ∫ H(ejw)𝑒𝑗𝑤𝑛𝑑𝑤
−𝜋
This is known as Fourier series coefficients having infinite length. One possible way of obtaining
FIR filter is to truncate the infinite Fourier series at n = ± [(N-1)/2] Where N is the length of the
desired sequence.
The Fourier coefficients of the filter are modified by multiplying the infinite impulse response with
a finite weighing sequence w(n) called a window.
Where w(n) = w(-n) ≠ 0 for |n| ≤ [(N-1)/2]
=0 for |n| > [(N-1)/2]
After multiplying w(n)with hd(n), we get a finite duration sequence h(n) that satisfies the desired
magnitude response,
EXAMPLE:
Here we design a low pass filter using hamming window. Hamming window function is given by,
wH(n) = 0.54 + 0.46 cos ((2πn)/(N-1)) ;–(N-1)/2 ≤ n ≤ (N-1)/2
=0 ; otherwise
The frequency response of Hamming window is,
WH(ejw) = 0.54[(sin(wN/2))/(sin(w/2)) + 0.23[sin (wN/2 – πN/N – 1)/sin (w/2 – π/N -1)]+ 0.23[sin
(wN/2 + πN/N – 1)/sin (w/2 + π/N – 1)]
ALGORITHM:
1. Input the Pass and Stop band edge in radians.
2. Compute N=order of the filter.
3. Obtain cutoff frequency of the filter.
4. Obtain Impulse response of FIR filter
5. Plot the Response of the filter.
OUTPUT:
enter the Pass band edge in radians = 0.375*pi
enter the stop band edge in radians = 0.5*pi
Order of the FIR filter N = 65
OUTCOME:
This experiment enables the students to acquire the knowledge of advantage and disadvantages of filter
design using various windows techniques.
Viva Questions:
7. How to find output of FIR filter for real time input signal?
In real time application entire input is not available and input signal has to be processed
online. Length of input signal depends on application. It can be long sequence also. In FIR filter
length of h[n] is finite. Output of the filter is always Linear Convolution of impulse response with
the input of the signal. To find output of digital FIR filter, Overlap Add Method using FFT or
Overlap Save Method using FFT is used.
10. What is the role of window in the design of FIR filter? Name the few types of windows.
FIR filter is designed by truncating infinite samples of hd[n] by using window function.
Examples of window function include, Hamming window, Bartlet Window, Hanning window,
Blackman window etc.
11. Why rectangular window is not preferred for FIR filter design?
Rectangular window function has As = 21 db which is very small compared to other window
function. Larger value of as desired.
12. Explain how to find output of digital FIR filter in real time application.
In real time applications, output of FIR filter is obtained using overlap add method /
overlap save method.
15. Explain how to find output of digital FIR filter in real time application.
OBJECTIVES:
After completing this lab, student will be able to Study the importance of Butterworth filter and
Chebyshev filter approximation to design IIR filter.
∑|h(n)| < ∞
𝑛=0
ALGORITHM:
1. From the given specifications find the order of the filter N.
2. Round off it to the next higher integer.
3. Find the transfer function H(s) for Ωc = 1rad/sec for the value of N.
4. calculate the value of cutoff frequency Ωc
5. find the transfer function Ha(s) for the above value of Ωc by substituting
s→ (s/ Ωc) in H(s).
6. Plot the frequency response of the filter.
OUTPUT:
enter the Pass band edge frequency in Hz = 500
enter the stop band frequency in Hz = 750
enter the sampling frequency in Hz = 2000
enter the pass band ripple n db = 3.01
enter the stop band attenuation in db = 15
order of the filter N = 2
Normalised cutoff frequency = 2.052
num/den = 0.30053 z^2 + 0.60106 z + 0.30053
OUTPUT:
enter the Pass band edge frequency in Hz = 100
enter the stop band frequency in Hz = 500
enter the sampling frequency in Hz = 4000
enter the pass band ripple n db = 2
enter the stop band attenuation in db = 20
order of the filter N = 2
Normalized cutoff frequency = 0.1574
num/den =
0.0037904 z^2 + 0.0075808 z + 0.0037904
OUTCOME:
This experiment enables students to design and implement various IIR filters using less memory
and calculations.
Viva Questions:
1. What is Infinite Impulse Response (IIR) filter?
If the impulse response of the system is of infinite duration, the system is said to be IIR
filter system.
2. How to find output of IIR filter for real time input signal?
In real time application entire input is not available and input signal has to be processed
online. Length of input signal depends on application. It can be long sequence also. In IIR filter
length of h[n] is infinite. Output of the filter is always Linear Convolution of impulse response with
the input of the signal. To find output of digital IIR filter, Overlap Add Method using FFT or Overlap
Save Method using FFT cannot be used. Output of digital IIR filter is calculated using difference
equation recursively.
4. Explain how to find output of digital IIR filter in real time application.
In real time applications, output of IIR filter can be obtained by evaluating difference
equation.
6. Explain how to find output of digital IIR filter in real time application.
In real time applications, output of IIR filter can be obtained by evaluating difference
equation.
THEORY: Correlation: Correlation determines the degree of similarity between two signals. If
the signals are identical, then the correlation coefficient is 1; if they are totally different, the
correlation coefficient is 0, and if they are identical except that the phase is shifted by exactly
1800(i.e. mirrored), then the correlation coefficient is -1.
Autocorrelation: The Autocorrelation of a sequence is correlation of a sequence with itself. The
autocorrelation of a sequence x(n) is defined by,
Properties of Autocorrelation:
1. Periodicity: Rxx(k0) = Rxx(0) then Rxx(k) is periodic with period k0
2. Autocorrelation function is symmetric. i.e. Rxx(m) = Rxx(-m)
3. Mean square value: autocorrelation function at k=0, is equal to mean square value of the
process. Rxx(0) = E{|x(n)|2}≥0
ALGORITHM:
1. Input the sequence as x.
2. Use the ‘xcorr’ function to get auto correlated output r.
3. Plot the sequences.
PROGRAM LOGIC:
1. Read the input sequence x[n]
CALCULATION:
X(n) ={ 3, 4, 5, 6}
Rxx = [ 18 39 62 86 62 39 18]
Rxx_Right = Rxx(center_index:1:length(Rxx));
% take the right side values
Rxx_left = Rxx(center_index:-1:1);
% take the left side values
if Rxx_Right == Rxx_left
disp('Rxx is even');
% display the resultelse
disp('Rxx is not even'); % display the result
end
OUTPUT:
Enter the input signal x[n] [3 4 5 6]
Rxx = [ 18 39 62 86 62 39 18]
Rxx_0 = 30
Rxx(0) gives energy -- proved
Rxx is even