0% found this document useful (0 votes)
24 views28 pages

DSP Lab by Adarsh 252001107

The document is a lab manual containing details of experiments conducted using MATLAB for a Digital Signal Processing lab. It includes 9 experiments related to topics like introduction to MATLAB, plotting various waveforms, studying unit impulse, ramp and step functions, convolution, sampling, filters etc. Each experiment section provides the aim, theory, MATLAB code and results. The lab manual is submitted to the instructor for evaluation and grading.
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)
24 views28 pages

DSP Lab by Adarsh 252001107

The document is a lab manual containing details of experiments conducted using MATLAB for a Digital Signal Processing lab. It includes 9 experiments related to topics like introduction to MATLAB, plotting various waveforms, studying unit impulse, ramp and step functions, convolution, sampling, filters etc. Each experiment section provides the aim, theory, MATLAB code and results. The lab manual is submitted to the instructor for evaluation and grading.
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/ 28

UNIVERSITY INSTITUE OF ENGNIEERING

AND TECHNOLOGY
KURUKSHETRA UNIVERSITY,
KURUKSHETRA

DSP LAB PRACTICAL FILE

SUBMITTED TO : SUBMITTED BY :
Ekta mam Adarsh Kumar
Assistant professor ece ‘B’
Ece, uiet, kuk 252001107
INDEX
S.NO. EXPERIMENT DATE SIGNATURE

1. Introduction to MATLAB.
08.09.2022

2. Write a program to plot Sine,


Cosine, Tangent, Cotangent
22.09.2022
wave for Discrete and
Continuous function.
3. To study Unit Impulse, Unit Ramp,
Unit Step & Exponential function . 29.09.2022

4. To study Convolution and


Multiplication. 06.10.2022

5. To study Real, Imaginary phase and


magnitude of Exponential function. 03.11.2022

6. To study the Sampling of a


Sinusoidal discrete Signal. 10.11.2022

7. Write a program to plot the Circular


Convolution of two signals. 24.11.2022

8. To study toolbox of various FIR


(Finite Impulse Response) filter. 12.12.2022

9. To study toolbox of various IIR


(Infinite Impulse Response) filter. 12.12.2022
EXPERIMENT : 1
AIM : Introduction to MATLAB

THEORY :

What is MATLAB?

MATLAB is widely used in all areas of applied mathematics, in education and research at
universities, and in the industry. MATLAB stands for MATrix LABoratory and the
software is built up around vectors and matrices. This makes the software particularly
useful for linear algebra but MATLAB is also a great tool for solving algebraic and
differential equations and for numerical integration. MATLAB has powerful graphic tools
and can produce nice pictures in both 2D and 3D. It is also a programming language, and
is one of the easiest programming languages for writing mathematical programs.
MATLAB also has some tool boxes useful for signal processing, image processing,
optimization, etc.

How to start MATLAB :

Mac: Double-click on the icon for MATLAB.


PC: Choose the submenu "Programs" from the "Start" menu. From the "Programs" menu,
open the "MATLAB" submenu. From the "MATLAB" submenu, choose "MATLAB".
Unix: At the prompt, type matlab.

You can quit MATLAB by typing exit in the command window.

The MATLAB environment :

Note: From now on an instruction to press a certain key will be denoted by < >, e.g.,
pressing the enter key will be denoted as <enter>. Commands that should be typed at the
prompt, will be written in courier font.

The MATLAB environment (on most computer systems) consists of menus, buttons and a
writing area similar to an ordinary word processor. There are plenty of help functions that
you are encouraged to use. The writing area that you will see when you start MATLAB,
is called the command window. In this window you give the commands to MATLAB. For
example, when you want to run a program you have written for MATLAB you start the
program in the command window by typing its name at the prompt. The command window
is also useful if you just want to use MATLAB as a scientific calculator or as a graphing
tool. If you write longer programs, you will find it more convenient to write the program
code in a separate window, and then run it in the command window .
In the command window you will see a prompt that looks like >> . You type your
commands immediately after this prompt. Once you have typed the command you wish
MATLAB to perform, press <enter>. If you want to interupt a command that MATLAB is
running, type <ctrl> + <c>.

The commands you type in the command window are stored by MATLAB and can be
viewed in the Command History window. To repeat a command you have already used,
you can simply double-click on the command in the history window, or use the <up arrow>
at the command prompt to iterate through the commands you have used until you reach the
command you desire to repeat.

Useful functions and operations in MATLAB :

Using MATLAB as a calculator is easy.

Example: Compute 5 sin(2.53-pi)+1/75. In MATLAB this is done by simply


typing 5*sin(2.5^(3-pi))+1/75
at the prompt. Be careful with parantheses and don't forget to type * whenever you
multiply!
Note that MATLAB is case sensitive. This means that MATLAB knows a difference
between letters written as lower and upper case letters. For example, MATLAB will
understand sin(2) but will not understand Sin(2).
EXPERIMENT : 2
AIM : Write a program to plot Sine, Cosine, tangent, Cotangent wave for Discrete and
Continuous function.

TOOL USED : MATLAB R2021a

THEORY : The sine function starts from 0. Maximum value of sine function is 1.
Range of cosine is -1 to 1. Range of tangent is from -∞ to ∞.
Range of secant is -1 to 1.

PROGRAM:
t = 0:25;
a = sin(t);
subplot(4,2,1)
plot(a)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Sine wave for continuous function ');

subplot(4,2,2)
stem(a)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Sine wave for discrete function ');

b = cos(t);
subplot(4,2,3)
plot(b)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cosine wave for continuous function ');

subplot(4,2,4)
stem(b)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cosine wave for discrete function ');
c = tan(t);
subplot(4,2,5)
plot(c)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Tangent wave for continuous function ');

subplot(4,2,6)
stem(c)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Tangent wave for discrete function ');

d = cot(t);
subplot(4,2,7)
plot(d)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cotangent wave for continuous function ');

subplot(4,2,8)
stem(d)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Cotangent wave for discrete function ');

RESULT :
EXPERIMENT : 3
AIM : To study Unit Impulse, Unit Ramp, Unit step & Exponential function.

TOOL USED : MATLAB R2021a

THEORY : A unit step has 1 for t ≥ 0 and 0 for t ˂ 0. A unit ramp has t for t ≥ 0 and
0 for t ˂ 0.
PROGRAM:
t = -7:1:7;
x = [zeros(1,7) ones(1,7)];
subplot(2,2,1)
stem(x)
xlabel('time');
ylabel('amplitude');
title('Unit Step Signal');

y = [zeros(1,7) ones(1,1) zeros(1,7)];


subplot(2,2,2)
stem(y)
xlabel('time');
ylabel('amplitude');
title('Unit Impulse Signal');

a = 0:7;
z = [zeros(1,7) a];
subplot(2,2,3)
stem(z)
xlabel('time');
ylabel('amplitude');
title('Unit Ramp Signal');

e = exp(t);
subplot(2,2,4)
stem(e)
xlabel ('time' ) ;
ylabel ('amplitude') ;
title ('Exponential Function ');
RESULT :
EXPERIMENT : 4
AIM : To study Convolution and Multiplication.

TOOL USED : MATLAB R2021a

THEORY : In mathematics, the convolution theorem states that under suitable


conditions the fourier transform of a convolution is the pointwise product of fourier
transforms. In other words, convolution in one domain (e.g. time domain) equals
point wise multiplication in other domain (e.g frequency domain). Convolution
syntax is denoted by conv(x,y). Multiplication syntax is denoted by x.*y .
PROGRAM:
x = [1,1,0,7] ;
y = [2,3,5,0] ;
z = x.*y ;
subplot(2,2,1)
plot(z)
xlabel('time');
ylabel('amplitude');
title('Multiplication');

subplot(2,2,2)
stem(z)
xlabel('time');
ylabel('amplitude');
title('Multiplication');

p = conv(x,y) ;
subplot(2,2,3)
plot(p)
xlabel('time');
ylabel('amplitude');
title('Convolution');

subplot(2,2,4)
stem(p)
xlabel('time');
ylabel('amplitude');
title('Convolution');
RESULT :
EXPERIMENT : 5
AIM : To study Real, Imaginary phase and magnitude of Exponential function.

TOOL USED : MATLAB R2021a

THEORY : Exponential function is a form of function in which the input variable


x occurs as an exponent .A function f(x)=b^x is considered as an exponential
function .When the real part is 0 ,it is considered as a imaginary and when img. part
is 0 it is considered as real part.
PROGRAM:
t = 0:0.4:7;
m = 18+1i*100;

a = exp(m.*t);
subplot(2,2,1);
plot(t,a);
xlabel('time');
ylabel('amplitude');
title('Exponential');

b = real(a);
subplot(2,2,2);
plot(t,b);
xlabel('time');
ylabel('amplitude');
title('Real phase of exponential function');

c = imag(a);
subplot(2,2,3);
plot(t,c);
xlabel('time');
ylabel('amplitude');
title('Imaginary phase of exponential function');

d = abs(a);
subplot(2,2,4);
plot(t,d);
xlabel('time');
ylabel('amplitude');
title('Absolute of exponential function');
RESULT :
EXPERIMENT : 6
AIM : To study the Sampling of a Sinusoidal Discrete Signal.

TOOL USED : MATLAB R2021a

THEORY : A continuous time signal can be represented in its samples and can be
recovered back when sampling frequency fs is greater than or equal to the twice the
highest frequency component of the message signal. i.e. fs ≥ 2fm
PROGRAM:
clc;
clear all ;
close all ;

n = 0:0.7:70 ;
x = sin(0.5 * pi * n);
subplot(4,1,1)
stem(x)
xlabel('time');
ylabel('amplitude');
title('Original')

y = resample(x,2,1) ;
subplot(4,1,2)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs=2fm')

y = resample(x,5,1);
subplot(4,1,3)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs>2fm') ;

y = resample(x,1,2);
subplot(4,1,4)
stem(y)
xlabel('time');
ylabel('amplitude');
title('fs<2fm') ;
RESULT :
EXPERIMENT : 7
AIM : Write a program to plot the Circular Convolution of two signals.

TOOL USED : MATLAB R2021a

THEORY : The circular convolution also known as cyclic convolution , of two


aperiodic functions occurs when one of them is convolved in normal way with a
periodic summation of other function.
PROGRAM:
a = [1 1 0 7] ;
b = [2 3 5 0] ;

y = cconv(a,b,4) ;
subplot(2,1,1)
plot(y)
xlabel('time');
ylabel('amplitude');
title('Circular-Convolution');
subplot(2,1,2)
stem(y)
xlabel('time');
ylabel('amplitude');
title('Circular-Convolution');

RESULT :
EXPERIMENT : 8
AIM : To study toolbox of various FIR (Finite Impulse Response) filter.

TOOL USED : MATLAB R2021a

THEORY :
The term FIR abbreviation is “Finite Impulse Response” and it is one of two main
types of digital filters used in DSP applications. Filters are single conditioners and
function of each filter is, it allows an AC components and blocks DC components.
The best example of the filter is a phone line, which acts as a filter. Because, it limits
frequencies to a rage significantly smaller than the range of human beings can hear
frequencies.
There are various kinds of filters, namely LPF, HPF, BPF, BSF. A LPF allows only
low frequency signals through tom its o/p, so this filter is used to eliminate high
frequencies. A LPF is convenient for controlling the highest range of frequencies in
an audio signal. An HPF is quite opposite to LPF. Because, it rejects only frequency
components below some threshold. The best example of the HPF is, cutting out the
60Hz audible AC power.
The design methods of FIR filter based on approximation of ideal filter. The ensuing
filter approaches the perfect characteristic because the order of the filter will
increase, so creating the filter and its implementation additional complicated.
The design process starts with necessities and specifications the FIR filter. The
method used in the design process of the filter depends upon the implementation and
specifications. There are many advantages and disadvantages of the design methods.
Thus, it is very significant to elect the right method for FIR filter design. Due to
efficiency and simplicity of the FIR filter, most commonly window method is used.
The other method sampling frequency method is also very simple to use, but there
is a small attenuation in the stopband.
The three most popular design methods are (in order):
1. Parks-McClellan: The Parks-McClellan method (inaccurately called “Remez”
by Matlab) is probably the most widely used FIR filter design method. It is an
iteration algorithm that accepts filter specifications in terms of passband and
stopband frequencies, passband ripple, and stopband attenuation. The fact that
you can directly specify all the important filter parameters is what makes this
method so popular. The PM method can design not only FIR “filters” but also
FIR “differentiators” and FIR “Hilbert transformers”.
2. Windowing:. In the windowing method, an initial impulse response is derived
by taking the Inverse Discrete Fourier Transform (IDFT) of the desired
frequency response. Then, the impulse response is refined by applying a data
window to it.
There are six types of Window methods:
i. Rectangular
ii. Bartlett
iii. Hanning
iv. Hamming
v. Blackman
vi. Kaiser
3. Direct Calculation: The impulse responses of certain types of FIR filters (e.g.
Raised Cosine and Windowed Sinc) can be calculated directly from formulas.

FILTER DESIGNING :

1. Low-Pass Filter(LPF) :

i. Through Hamming Window :


ii. Through Bartlett Window :

iii. Through Blackman Window :


2. High Pass Filter (HPF) :

i. Through Hamming Window :

ii. Through Bartlett Window :


iii. Through Blackman Window :

3. Band Pass Filter (BPF) :

i. Through Hamming Window :


ii. Through Bartlett Window :

iii. Through Blackman Window :


EXPERIMENT : 9
AIM : To study toolbox of various IIR (Infinite Impulse Response) filter.

TOOL USED : MATLAB R2021a

THEORY :
The infinite impulse response is a type of digital filter that is used in Digital Signal
Processing applications. A filter’s job is to allow certain types of signals to pass and
block the rest. The infinite impulse response filter is unique because it uses a
feedback mechanism. It requires current as well as past output data. Though they are
harder to design, IIR filters are computationally efficient and generally cheaper.

Methods to design an Infinite Impulse Response filter :


1. Direct method – Designing analog filters and then converting them to digital.
2. Approximation of derivatives method – Approximating a differential equation
(continuous-time (d/dt)) by an equivalent difference equation.
3. Impulse invariance method – simple s-plane to z-plane mapping.
4. Bilinear Transformation method (BLT) – An improvement over the impulse
invariance method.
5. Approximation of standard analog filters – Butterworth, Chebyshev, and
Elliptic analog filter designs can be approximated as IIR filters. These analog
filters have an infinite response too.
6. Spectral transformation – We can create different types of digital IIR filters
using a digital IIR low pass filter via the spectral transformation method.
Conditions to design a stable Infinite Impulse Response (IIR) filter :
To design a stable and causal IIR filter, the following requirements are necessary:
1. The transfer function (H(z)) should be a rational function of z, and the
coefficients of z should be real.
2. The poles (values, where the denominator turns 0 / output is infinite) should lie
inside the unit circle of the z-plane.
3. The number of zeros should be less than or equal to the number of poles.
4. For the effective conversion from an analog filter to a digital one, the imaginary
axis of the s-plane should map into the unit circle of the z-plane. This establishes
a direct relationship between the analog frequency and digital frequency in two
domains.
5. The left half of the s-plane should map into the inside of the unit circle of the z-
plane.
Advantages of an IIR filter :
i. IIR filters are more versatile.
ii. They are computationally easier to implement.
iii. They are cheaper too.
iv. The infinite response of the IIR filter is a cool feature when you are looking for
amplification of signals. Not so much when you wish to attenuate them, though.

Disadvantages of an IIR filter


i. Practically realizable digital IIR filters do not have a linear phase response. The
linear phase is a property where the phase response of a filter is a linear function
of the frequency.
ii. IIR filters cannot implement integer math, which is an easy to use mathematical
representation because it’s cheap, fast, and easy to implement.
iii. IIR filters have a higher chance of being unstable.
iv. Additionally, they also have a higher chance of being affected by quantization
operations like truncation and rounding. This is due to the feedback mechanism
that introduces poles in the transfer function. On the contrary, FIR filter transfer
functions do not have poles.
FILTER DESIGNING :

1. Low Pass Filter (LPF) :


i. Through Butterworth method :

ii. Through Chebyshev I method :


iii. Through Chebyshev II method :

2. High Pass Filter (HPF) :


i. Through Butterworth method :
ii. Through Chebyshev I method :

iii. Through Chebyshev II method :


3. Band Pass Filter (BPF) :
i. Through Butterworth method :

ii. Through Chebyshev I method :


iii. Through Chebyshev II method :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy