You are on page 1of 72

SHRI G.S.

INSTITUTE OF TECHNOLOGY & SCIENCE


INDORE 452003
(AN AUTONOMOUS INSTITUTE, ESTABLISHED IN 1952)

LABORATORY JOURNAL

EC35514: APPLIED DIGITAL SIGNAL PROCESSING


B.TECH. III YEAR

LAB - II
DEPARTMENT OF ELECTRONICS & TELECOMMUNICATION ENGINEERING
NAME- JINISHA NANDECHA
ROLL NO- 0801EC211031
CLASS- B.TECH 3rd YEAR
BRANCH- ELECTRONICS & TELECOMMUNICATION
SUBJECT- APPLIED DIGITAL SIGNAL PROCESSING
SEMESTER- 6th

Certificate

This is to certify that Ms./Mr._________________________________________


Roll No._______________________ studying in________________________
Year______________ of this institute has completed practical course based on the
syllabus and given a satisfactory account of it in the notebook containing a record
of the laboratory work.

Date: Signature
Grade: Professor in charge
SHRI G. S. INSTITUTE OF TECHNOLOGY & SCIENCE, INDORE
DEPARTMENT OF ELECTRONICS & TELECOMMUNICATION ENGINEERING
Bachelor of Engineering (Electronics & Telecommunication Engineering)

Vision and Mission of the Institute

VISION
A front line institute in science and technology making significant contributions to
human resource development envisaging dynamic needs of the society.

MISSION
To generate experts in science and technology relevant to society for its accelerated
socio economic growth in professional and challenging environment imparting
human values

Vision and Mission of the Department

VISION
To be a leading Electronics and Telecommunication engineering department
providing education at Graduate, Post-Graduate and research level fulfilling
changing academic and industrial needs to create human resources in the field of
modern Electronics and Telecommunication Engineering

MISSION
Our efforts are dedicated in educating the students in the field of Electronics and
Telecommunication Engineering to create competent professionals with high moral values,
social ethics and for pursuing higher education and research
SHRI G. S. INSTITUTE OF TECHNOLOGY & SCIENCE, INDORE
DEPARTMENT OF ELECTRONICS & TELECOMMUNICATION ENGINEERING
Bachelor of Engineering (Electronics & Telecommunication Engineering)

The Department of Electronics and Telecommunication Engineering was established in 1972 and
has been offering Bachelor of Engineering (B.E.) course since then. The department started M.
E. (Electronics and Telecommunication Engineering) course in 2003 with emphasis on
Telecommunication Technology in view of increased national tele-density, advances in the field
of mobile communications and expansion of communication and computer networks in the
country. The M.E. course of the department has been NBA accredited since January 2013 for 3
years. The department is a QIP Ph. D. center of MHRD, Govt. of India since 2012.

The department has well established laboratories in analog and digital electronics,
communication systems, telecommunication systems and networking, digital signal processing,
embedded systems, optical communications, microwave engineering and related fields. The
department also has computing facilities with intranet and internet connectivity. The department
participates in the distance education program of IIT Bombay as a remote center at the institute
level. The department has actively participated in IMPACT project supported by World Bank,
Swiss Development Corporation (SDC) and Department of Electronics (now known as Ministry
of communication and information technology), Government of India, which was aimed at
enhancing education facilities to create technical trained competent manpower. The department
has participated in TEQIP Phase I and is also participating in TEQIP Phase II program of the
institute. Faculty members and students are members of various professional societies and
participate in their activities. The department has close interaction with Raja Ramanna Center
for Advanced Technology (RRCAT), Indore in the field of joint conferences, seminars and
student’s projects, etc. In the year 2013, renowned companies like Texas Instruments, Bangalore
and BSNL have provided extensive on campus and off campus training to about 200 students of
the department.

The department carries research in the areas of wireless channel modeling, channel coding, cross
layer design issues, signal processing, routing protocols in computer networks, secure
communication, sensor networks, micro strip antenna design using soft computing techniques,
green wireless communication etc. Faculty members and research scholars regularly publish
their work in international and national journals. Many students and faculty members of the
department have received numerous awards and regularly participate in national and
international conferences for paper presentations, expert talks, session chairs in India and abroad.
Many alumni of the department have pursued M. Tech. and Ph. D. studies from various IITs,
IISc and abroad after securing high percentile in GATE and GRE
SHRI G. S. INSTITUTE OF TECHNOLOGY & SCIENCE, INDORE
DEPARTMENT OF ELECTRONICS & TELECOMMUNICATION ENGINEERING
B.Tech (Electronics & Telecommunication Engineering)

Program Educational Objectives (PEO):-


To create technically competent human resource capable of fulfilling dynamic socio-
economic needs in the field of Electronics and Telecommunication Engineering.

1. The graduates of Electronics & Telecommunication Engineering shall be competent


Electronics and Telecommunication Engineers, with hardware & software component
/subsystem selection capabilities, for system design, development, integration,
operation, commission, maintenance and up gradation of the systems.
2. The graduates shall have competency to become successful professionals for
accelerated socio-economic growth of the organization/ country.
3. The Electronics & Telecommunication Engineering graduates shall have high moral
values/ethics to build an efficient team with appropriate soft skill capabilities.

Program Outcomes (PO):-


Engineering Graduates will be able to:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex
engineering problems.

2. 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.

3. 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.

4. Conduct investigations of complex problems: Use research-based knowledge and


research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.

5. 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.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.

7. 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.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or


leader in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with


the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.

11. 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.

12. 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.
CONTENTS

S.No. Name of Program Page No. Signature


1. Introduction to MATLAB
2. Basic Operations on Matrices
3. Generation of different types of Sinusoidal Signals
4. Generation of different Discrete-time sequences
Decimation and interpolation for discrete time systems with frequency
5.
responses
6. z-Transform & Unit circle stability [pole-zero plot]
7. Methods of Inverse z-Transforms & concept of Residues and poles
8. Linear Convolution in time domain and z-domain
To calculate DTFT using different methods and plot its magnitude and
9.
phase response.
Properties of DTFT: Time-shifting, Frequency-shifting, Convolution,
10.
Modulation and Time-reversal.
11. N-point DFT and FFT of various sequences
Properties of DFT: Circular Time-shifting, Circular Frequency-shifting,
12.
Circular Time-reversal & Circular Convolution
13. Plot frequency response of Digital FIR and IIR LPF
14. Plot frequency response of Digital FIR and IIR HPF
15. Plot frequency response of Digital FIR and IIR BPF
16. Plot frequency response of Digital FIR and IIR BRF
17. Plot frequency response of Low-pass and High-pass COMB filter
18. Design an FIR LPF using a Rectangular window
19. Design an FIR Linear-Phase filter using a Hamming window
20. Design an FIR HPF filter using a Hanning window
21. To Calculate order and cut-off frequency of a digital Butterworth filter
22. Design an IIR LPF Butterworth filter using Bilinear Transformation
23. Design an IIR LPF Butterworth filter using Impulse Invariant method
24. Image Processing understanding using MATLAB
25. Exercise-I
26. Exercise-II
PROGRAM-1
OBJECTIVE: An Introduction to MATLAB.

ABOUT MATLAB: MATLAB, short for Matrix Laboratory, is a high-level programming


language and interactive environment developed by MathWorks. It is extensively used in
academia, research, and industry for tasks ranging from numerical computations to data analysis
and visualization. MATLAB's versatility and ease of use make it an invaluable tool for
engineers, scientists, and researchers worldwide.

DESCRIPTION: It offers an interactive environment that enables users to perform a wide range
of numerical computations, data analysis, and visualization tasks efficiently. This experiment
serves as an introduction to MATLAB, designed to provide participants with hands-on
experience in utilizing its key features for data analysis, visualization, and basic programming.
Through a series of hands-on exercises, participants will learn the essential tools and techniques
in MATLAB for analyzing, processing, and visualizing digital signals. The experiments cover
fundamental concepts such as signal generation, filtering, spectral analysis, and practical
implementation of DSP algorithms using MATLAB.

FEATURES:
1. High-level Language: MATLAB provides an intuitive high-level programming language that
allows users to express computational mathematics and algorithms in a natural and readable
manner. Its syntax is designed to be similar to traditional mathematical notation, making it
accessible to users with diverse backgrounds.

2. Matrix Operations: MATLAB is renowned for its excellent support for matrix and vector
operations. It treats matrices as fundamental entities, enabling users to perform a wide range of
linear algebra operations efficiently. This feature makes MATLAB particularly well-suited for
tasks involving numerical computations and data manipulation.

3. Interactive Environment: MATLAB offers an interactive environment where users can


execute commands, visualize data, and debug code in real-time. The Command Window
provides a convenient interface for executing individual commands, while the MATLAB Editor
allows users to write and edit scripts and functions.

4. Extensive Function Library: MATLAB comes with a vast library of built-in functions and
toolboxes covering various areas such as signal processing, image processing, optimization,
statistics, and more. These functions provide ready-made solutions for common computational
tasks, saving users time and effort in implementing algorithms from scratch.

5. Data Visualization: MATLAB offers powerful tools for data visualization, allowing users to
create high-quality plots, graphs, and charts to represent their data effectively. It supports a wide
range of plot types, including 2D and 3D plots, histograms, scatter plots, contour plots, and
surface plots.

6. Graphical User Interface (GUI) Development: MATLAB enables users to create interactive
graphical user interfaces (GUIs) for their applications using tools such as GUIDE (GUI
Development Environment) or App Designer. GUIs can streamline the user experience and make
complex functionalities more accessible to non-programmers.

7. Parallel Computing: MATLAB includes parallel computing capabilities that enable users to
distribute computational tasks across multiple processors or cores, significantly reducing the time
required for large-scale computations. Parallel computing in MATLAB can be achieved using
built-in functions, parallel computing toolboxes, or by leveraging GPU computing.

8. Integration with External Languages: MATLAB supports integration with external


programming languages such as C, C++, and Java, allowing users to call external functions or
libraries from within MATLAB code. This enables seamless interoperability between MATLAB
and other software systems.

9. Application Deployment: MATLAB allows users to deploy their MATLAB applications as


standalone executables, web applications, or software components, making it easy to share and
distribute their work with others who may not have MATLAB installed.

10. Community and Support: MATLAB boasts a large and active user community, with
abundant resources such as documentation, tutorials, online forums, and technical support
provided by MathWorks. This vibrant community fosters collaboration, knowledge-sharing, and
continuous learning among MATLAB users worldwide.
PROGRAM-2
OBJECTIVE: Basic Operations on Matrices.
clc; % clear the command window
clear all; % clear the workspace
close all; % clear the figure window

% creation of matrices
a = [1 2 3; 4 5 6; 7 8 9]
b = [1 1 0; 1 2 3; 1 5 3]

a=
1 2 3
4 5 6
7 8 9

b=
1 1 0
1 2 3
1 5 3

SYNTAX:
% matrix addition: c=a+b
% matrix subtraction: d=a-b
%matrix multiplication: e=a*b
%array multiplication (element by element): g=a.*b
% transpose: f=a'
% inverse matrix: h=inv(a)
%diagonal matrix: i=diag(a)
% extraction of sub matrix

CODE:
%%
clear ; clc;
%% intro
a=1+4; %a is 5

b=a+1;
A = [1 2 3; 4 5 6; 7 8 9];
B= zeros(2,3);
%%
%creation of matrices
a=[1 2 3; 4 5 6; 7 8 9];
b=[1 1 0;1 2 3;1 5 3];
%matrix addition
c=a+b
%%
%matrix subtraction
d=a-b
%%
%matrix multiplication
e=a*b
%%
%matrix transpose
f=a'
%%
%matrix array multiplication (element by element)
g=a.*b
%%
%inverse matrix
h=inv(a)
%%
%diagonal matrix
i=diag(a)
%%
% extraction of sub matrix
j1=a(1:2,2:3)
j2=a(2:3,1:2)
j3=a(2,1:3)
j4=a(1:3,2:end)
j5=a(:,:)
j6=a(1:3,:)
%%
j7=1:0.2:5
j8=1:5
j9=a(1:2:3)
j10=a(1:2:3,:)
j11=1:1:5

OUTPUT:
A = 3 3 3
6 3 6
1 2 3
4 5 6
7 8 9

B = e =

0 0 0 6 20 15
0 0 0 15 44 33
24 68 51

c =
f =
2 3 3
5 7 9 1 4 7
8 13 12 2 5 8
3 6 9

d =
g =
0 1 3
1 2 0
4 10 18
7 40 27 j6 =

h = 1 2 3
4 5 6
1.0e+16 * 7 8 9

-0.4504 0.9007 -0.4504


0.9007 -1.8014 0.9007 j7 =
-0.4504 0.9007 -0.4504
Columns 1 through 12

= 1.0000 1.2000 1.4000


1.6000 1.8000 2.0000 2.2000
1 2.4000 2.6000 2.8000 3.0000
5 3.2000
9
Columns 13 through 21

j1 = 3.4000 3.6000 3.8000


4.0000 4.2000 4.4000 4.6000
2 3 4.8000 5.0000
5 6

j8 =
j2 =
1 2 3 4 5
4 5
7 8
j9 =

j3 = 1 7

4 5 6
j10 =

j4 = 1 2 3
7 8 9
2 3
5 6
8 9 j11 =

1 2 3 4 5
j5 =

1 2 3
4 5 6
7 8 9
PROGRAM-3

OBJECTIVE: Generation of different types of Sinusoidal Signals.

% generation of different types of signals


clc; % clear the command window
clear all; % clear the workspace
close all; % clear the figure window

DESCRIPTION:
Sinusoidal signals are fundamental components in various fields, ranging from electrical
engineering to physics and beyond. This comprehensive course delves into the generation of
different types of sinusoidal signals, offering a thorough understanding of their characteristics,
applications, and generation techniques.

1. Basic sinusoidal waveforms: It shows the fundamental properties of sine and cosine waves,
including amplitude, frequency, phase, and periodicity.

2. Harmonic content and Fourier analysis: This module explores the concept of harmonics and
their significance in signal processing and Fourier analysis techniques to decompose complex
signals into their constituent sinusoidal components, paving the way for a deeper understanding
of signal synthesis and manipulation.

3. Modulated sinusoidal signals: Building upon the concepts of modulation, participants will
explore techniques such as amplitude modulation (AM), frequency modulation (FM), and phase
modulation (PM).

4. Digital synthesis of sinusoidal signals: In the digital domain, sinusoidal signals are generated
using algorithms and numerical techniques.

SYNTAX:
1. Sine waves: n=0:1:50;
y = amplitude * sin(2*pi*frequency*t );
2. Cosine waves: n=0:1:50;
y = amplitude * cos(2*pi*frequency*t + phase);
3. Exponential function: n=-10:0.0001:10;
y=exp(n);

CODE:
% generation of sine wave
%generation of discrete sinusoidal signal
n=0:0.5:20;
y=sin(0.1*pi*n);
subplot(2,1,1);
stem(n,y);grid;
title('discrete sinusoidal');
xlabel('time');
ylabel('Amplitude');
%%
%generation of continuous sinusoidal signal
n=0:0.5:20;
y=sin(0.1*pi*n);
subplot(2,1,2);
plot(n,y);grid;
title('conti sinusoidal');
xlabel('time');
ylabel('Amplitude');

% generation of cosine wave


%%
%generation of sum of sinusoidal signal
t=0:0.0001:3*pi;
x1=sin(5*t);
x2=sin(9*t);
x=x1+x2;
subplot(3,1,1);
plot(t,x1);
title('x1=sin(5t)');
subplot(3,1,2);
plot(t,x2);
title('x2=sin(9t)');
subplot(3,1,3);
plot(t,x);
grid;
title('sum of conti sinusoidal x=x1+x2');
xlabel('time');
ylabel('Amplitude');

% generation of cosine wave


%%
%generation of cosine wave
n=0:1:30;
y1=cos(0.2*pi*n);
plot(n,y1);
subplot(2,1,1);
xlabel('n');
ylabel('y1(n)');
title('cosine discrete');
hold on;
stem(y1);
subplot(2,1,2);
xlabel('n');
ylabel('y1(n)');
title('cosine continuous');

% generation of exponential wave


%%
%generation of exponential function
n=0:1:10;
y=exp(-0.3*n);
figure;
subplot(3,1,1);
plot(n,y);grid;
title(' exponential');
xlabel('time');
ylabel('Amplitude');
%%
%generation of discrete exponential function
n=-10:0.6:10;
y=exp(n);
subplot(3,1,2);
stem(n,y);grid;
title('discrete exponential');
xlabel('time');
ylabel('Amplitude');
%%
%generation of continuous exponential function
n=-10:0.0001:10;
y=exp(n);
subplot(3,1,3);
plot(n,y);grid;
title('continuous exponential');
xlabel('time');
ylabel('Amplitude');

OUTPUT:
PROGRAM-4

OBJECTIVE: Generation of different Discrete-time sequences.

clc; % clear the command window


clear all; % clear the workspace
close all; % clear the command window

DESCRIPTION:
1. Unit Impulse Function (or Dirac Delta Function):
- The unit impulse function, denoted as δ(t), is a theoretical construct in mathematics and
signal processing. It represents an infinitely narrow pulse of unit area centered at t = 0 and zero
elsewhere.
- Mathematically, it is defined as δ(t) = 0 for t ≠ 0, and the integral of δ(t) over any interval
containing 0 is 1: ∫δ(t)dt = 1.
- The unit impulse function is primarily used in the analysis and synthesis of signals and
systems, particularly in areas such as Fourier analysis, Laplace transforms, and convolution.

2. Unit Step Function:


- The unit step function, denoted as u(t), is a function that is zero for negative input values and
one for positive input values. It represents a sudden change from 0 to 1 at t = 0.
- Mathematically, it is defined as u(t) = 0 for t < 0, and u(t) = 1 for t ≥ 0.
- The unit step function is used to model phenomena like switching on or off a signal, and it is
also important in solving differential equations, particularly those that involve discontinuous
functions.

3. Ramp Function:
- The ramp function, denoted as r(t), is a linear function of time with a positive slope. It starts
at zero for negative values of t and increases linearly with time.
- Mathematically, it is defined as r(t) = 0 for t < 0, and r(t) = t for t ≥ 0.
- The ramp function is useful in representing signals that increase steadily over time, such as
the position of an object subjected to constant velocity.
- It finds applications in various engineering fields, including signal processing, control theory,
and circuit analysis.

SYNTAX:
1. Unit Impulse: n=-10:1:10;
y=2*(n==0);
2. Unit step: n=-10:1:10;
y=(n>=0);
3. Ramp function: n=-10:1:10;
y=(n);

CODE:
%%
%Generation of different signals
% generation of UNIT IMPULSE
n=-10:1:10;
y=(n==0);
subplot(2,1,1)
stem(n,y);grid;
title('unit impluse');
xlabel('time');
ylabel('Amplitude');

%%
% generation of DISCREATE UNIT STEP
n=-10:1:10;
y=(n>0);
subplot(2,2,3)
stem(n,y);grid;
title('discrete unit step');
xlabel('time');
ylabel('Amplitude');

%%
% generation of CONTINUOUS UNIT STEP
n=-10:1:10;
y=(n>0);
subplot(2,2,4)
plot(n,y);grid;
title('conti unit step');

%%
% generation of DISCREATE RAMP
n=-10:1:10;
y=(n);
subplot(2,1,1)
stem(n,y);grid;
title('discrete ramp');
xlabel('time');
ylabel('Amplitude');

%%
% generation of CONTINUOUS RAMP
n=-10:1:10;
y=(n);
subplot(2,1,2)
plot(n,y);grid;
title('conti ramp');
xlabel('time');
ylabel('Amplitude');
OUTPUTS:
PROGRAM-5

OBJECTIVE: Decimation and interpolation for Multi-rate discrete time systems.

DESCRIPTION:
Decimation:
• Decimation is the process of reducing the sampling rate of a signal. It involves discarding
samples from the original signal.
• In decimation by a factor of M, every Mth sample is retained while the rest are discarded.
This effectively reduces the sampling rate by a factor of M.

Upsampling :
• Upsampling, also known as expansion, is a specific form of interpolation where the
sampling rate of a signal is increased by inserting zeros between samples and then
applying a low-pass filter.
• It increases the sampling rate by an integer factor L. The zeros are inserted between each
sample, and then a low-pass filter is applied to remove the images introduced by the
upsampling process.

Downsampling (Compression):
• Downsampling, also known as compression, is the process of reducing the sampling rate
of a signal by keeping every Mth sample and discarding the rest.
• Downsampling is often used to reduce the data rate or to match the sampling rate of one
signal to that of another in multi-rate systems.

SYNTAX:
1. Downsample: x =[1 2 3 4 5 6 7 8 9 10]
y = downsample(x,3)
2. Upsample: x =[1 2 3 4 5 6 7 8 9 10]
y1 = upsample(x,3)

CODE:
%Decimation or Downsampling
%% down sampling
x =[1 2 3 4 5 6 7 8 9 10];
y = downsample(x,3);
stem(y)
subplot(211);
title('Down sample signal')

% Interpolation or Upsampling
%upsampling
x =[1 2 3 4 5 6 7 8 9 10]
y1 = upsample(x,3)
stem(y1)
subplot(212);
title('up sample signal')
OUTPUT:
PROGRAM-6

OBJECTIVE: z-Transform & Unit circle stability [pole-zero plot]

% z-Transform
DESCRIPTION:
The Z-transform is a pivotal mathematical tool in the realm of digital signal processing and
control theory, serving as the bridge between discrete-time sequences and their frequency-
domain representations. It operates by summing the sequence \( x[n] \) multiplied by powers of
the complex variable \( z \), defining the transformed signal \( X(z) \). Crucially, the Z-
transform's validity hinges on the Region of Convergence (ROC) in the complex \( z \)-plane,
determining where the transform converges and thereby affecting system properties like
causality and stability. This transform exhibits key properties such as linearity, shifting, time
reversal, and convolution, facilitating various analyses and manipulations of discrete-time
systems. Applications abound, ranging from system analysis, where it aids in understanding
frequency response and stability, to filter design in digital signal processing and the analysis and
optimization of discrete-time control systems. Additionally, the inverse Z-transform provides a
means to convert signals back to the time domain, enabling a comprehensive understanding of
system behavior. Overall, the Z-transform stands as an indispensable tool, empowering engineers
and researchers to navigate the complexities of discrete-time systems with precision and
efficacy.

SYNTAX:
For zTransform: y=ztrans(x)

CODE:
%% zT
syms w n
f = sin(w*n);
ztrans(f)

OUTPUT:
(z*sin(w))/(z^2 - 2*cos(w)*z + 1)

%% zT of exponential
CODE:
syms x
f=exp(x);
ztrans(f)

OUTPUT:
z/(z - exp(1))

% Roots and Polynomial [pole-zero plot]


DESCRIPTION:
Roots of a polynomial and pole-zero plots are intimately linked concepts crucial to the analysis
and design of systems in signal processing and control theory. The roots of a polynomial
equation represent the values of the variable for which the polynomial evaluates to zero. These
roots can be real or complex numbers, providing essential insights into system behavior. On the
other hand, a pole-zero plot graphically depicts the roots of the numerator and denominator
polynomials of a system's transfer function in the complex \( z \)-plane. Zeros correspond to the
roots of the numerator polynomial, while poles correspond to the roots of the denominator
polynomial. These plots visually represent critical system characteristics, including stability and
frequency response. Specifically, stable systems have poles located within the unit circle in the \(
z \)-plane. By examining the distribution of poles and zeros in a pole-zero plot, engineers can
gain valuable insights into a system's behavior and make informed decisions during analysis and
design processes. Thus, the relationship between the roots of a polynomial and pole-zero plots
forms the foundation for understanding and manipulating the dynamics of complex systems in
various engineering applications.

SYNTAX:
1. For roots: z=roots(b)
2.For polynomial: b = poly(z)
3.For unit circle: zplane(z,p)

CODE:
b = [1 2 0 3]
z=roots(b) %roots of z
b = poly(z) %polynomial of z from roots
polyval(b,3)/3^3 %polynomial at a given value z=3 & f^n divided by z^3 at z==3
polyval(b,3) %polynomial at a given value z=3
%to understand %% b=z^3 + 2* z^2 + 0 + 3* z^0
% polyval(b,3)/3^3 === b/z^3 = 1 + 2*z^-1 +3* z^-3
%%unit circle
z=[0.2;0.4];
p=[0.5;0.3];
zplane(z,p)

OUTPUT:
b=1 2 0 3

z =-2.4856 + 0.0000i
0.2428 + 1.0715i
0.2428 - 1.0715i

b = 1.0000 2.0000 0.0000 3.0000

ans = 1.7778

ans = 48.0000
PROGRAM-7

OBJECTIVE: Methods of Inverse z-Transforms & concept of Residues and poles.

% Inverse z-Transform
DESCRIPTION:
The inverse Z-transform is a mathematical operation that converts a function of the complex
variable Z back into the time-domain sequence. In other words, it allows us to recover a discrete-
time sequence from its Z-domain representation. The inverse Z-transform is crucial in digital
signal processing and control theory, where it is used to analyze and design discrete-time
systems.

The inverse Z-transform is denoted by x[n], where n represents discrete-time indices. Given a
function X(Z) in the Z-domain,

SYNTAX:
y=iztrans(x)

CODE:
%% inverse zT
syms z
f=(z/(z-1/2));
iztrans(f)

OUTPUT:
(1/2)^n

% Different methods to calculate Inverse z-Transform


DESCRIPTION:
1. When using partial fraction expansion to find the inverse Z-transform, the residues at each
pole are essential.
2. After decomposing the function into simpler fractions, the inverse Z-transform of each term
can be determined using known inverse Z-transform pairs or by computing the residue at each
pole.
3. The residue at a pole can be computed using techniques such as the residue theorem or by
algebraically manipulating the function to isolate the residue.
4. Once the residues are found, the inverse Z-transform is obtained by summing the
contributions of each term, which are determined by the residues and the poles.
5. In summary, residues and poles are fundamental concepts in the calculation of inverse Z-
transforms, particularly when using partial fraction expansion. They provide insights into the
behavior of functions in the Z-domain and facilitate the decomposition of functions into simpler
terms for analysis in the time domain.

SYNTAX:
CODE:
%% Partial Fraction
b=[2 1 0 0];
a=[1 0 1 1];
[r,p,k]=residuez(b,a)
[b,a]=residuez(r,p,k)
OUTPUT:
r =
0.9481 - 0.1825i
0.9481 + 0.1825i
0.1038 + 0.0000i

p =
0.3412 + 1.1615i
0.3412 - 1.1615i
-0.6823 + 0.0000i

k = 0

b = 2.0000 1.0000 0.0000 0

a = 1.0000 -0.0000 1.0000 1.0000


PROGRAM-8
OBJECTIVE: Linear Convolution in time domain and z-domain.

% Linear Convolution in time-domain


DESCRIPTION:
Linear convolution in the time domain is a core operation in signal processing, essential for
combining two discrete-time signals to produce a third signal. Mathematically, it involves
summing the products of corresponding elements of two input sequences, accounting for their
relative time shifts. The resulting output sequence reflects the combined influence of the input
signals over time. To compute linear convolution, methods such as the overlap-add or overlap-
save technique are commonly employed, facilitating efficient computation, especially for signals
of significant length. One fundamental aspect of linear convolution is its commutativity, where
the order of input signals does not affect the result. Additionally, it exhibits associativity and
distributivity properties, ensuring consistency and facilitating various signal processing
operations.

SYNTAX:
y=conv(a,b)

CODE:
x=[1 1 1 1];
h=[1 1 1];
y=conv(x,h);
%subplot(2,2,2);
stem(y);grid;
title(' linear convolution');
xlabel('time');
ylabel('Amplitude');

OUTPUT:

% Linear Convolution using z-Transform


DESCRIPTION:
Linear convolution using the z-transform is a powerful technique in signal processing and
control theory, offering a convenient way to compute convolutions in the frequency domain.
This method exploits the convolution theorem, which states that convolution in the time domain
corresponds to multiplication in the z-domain. To perform linear convolution using the z-
transform, one first finds the z-transforms of the input sequences (x[n]) and (h[n]), denoted as
(X(z)) and (H(z)) respectively. Then, by multiplying these z-transforms together, the z-transform
(Y(z)) of the output sequence (y[n]) is obtained. This approach simplifies convolution
calculations, especially for complex systems and signals. Furthermore, it provides insights into
system behavior in the frequency domain, aiding in the analysis and design of discrete-time
systems. Applications of linear convolution using the z-transform abound in various fields,
including digital signal processing, communications, and control systems, where it is
instrumental in analyzing system performance and designing efficient algorithms. Overall, linear
convolution using the z-transform serves as a versatile tool, facilitating advanced signal
processing techniques and enabling engineers to tackle diverse challenges in system analysis and
design.

SYNTAX:
CODE:
%%
syms n z;
y3=(.4)^n;
y4=(.5)^n;
xz1=ztrans(y3);
xz2=ztrans(y4);
xz3=xz1*xz2;
conv=iztrans(xz3);
disp('convolution of x1[n] and x2[n]')
simplify(conv)

OUTPUT:
convolution of x1[n] and x2[n]

ans = 5*(1/2)^n - 4*(2/5)^n


PROGRAM-9
OBJECTIVE: To calculate DTFT using different methods and plot its magnitude and phase
response.

%1. Determine the DTFT of 𝒙[𝒏] = (𝟎. 𝟕)𝒏 𝒖[𝒏]. Plot its magnitude, phase, real, and
imaginary parts.

%% Method 1: Using DTFT formula


DESCRIPTION:
The Discrete-Time Fourier Transform (DTFT) is a mathematical tool used to analyze the
frequency content of discrete-time signals. The DTFT of a sequence
x[n] is defined as:
X(ω)=∑x[n]⋅e ^−jωn
Where:
X(ω) is the DTFT of
x[n].

ω is the angular frequency variable.


−jωn is the complex exponential term.
To calculate the DTFT using different methods and plot its magnitude and phase response, we
can follow these steps:
1. Direct Calculation
2. By FFT
3. Frequency Sampling
4. Windowed DTFT

SYNTAX:
w=0:0.01:2*pi;
Xw=1+exp(-j*w)+exp(-j*w*2)+exp(-j*w*3); %%%DTFT
plot(w, abs(Xw));

CODE:
w= 0:0.01:pi;
n=0:100;
xn=0.7.^n;
Xw=exp(-j*w'*n)*xn.';%orignal signal
MagX=abs(Xw);%for magnitude
PhaseX=angle(Xw);%for phase
RealX=real(Xw);%for real part
ImagX=imag(Xw);%for imaginary part
subplot(221);
plot(w/pi,MagX); %to normalize the time access we use w/pi
xlabel('w');
ylabel('magnitude');
subplot(222);
plot(w/pi,PhaseX);
xlabel('w');
ylabel('Phase');
subplot(223);
plot(w/pi,RealX);
xlabel('w');
ylabel('Real');
subplot(224);
plot(w/pi,ImagX);
xlabel('w');
ylabel('Imaginary');

OUTPUT:

%% Method 2: Using the DTFT 𝑿[𝒆𝒋𝝎 ]

SYNTAX:

CODE:
%%
w= 0:0.01: pi;
Xw=1./(1-0.7.*exp(-j*w));
MagX=abs(Xw);
PhaseX=angle(Xw);
RealX=real(Xw);
ImagX=imag(Xw);
subplot(221);grid;
plot(w/pi,MagX);
xlabel('w');
ylabel('magnitude');
subplot(222); grid;
plot(w/pi,PhaseX);
xlabel('w');
ylabel('Phase');
subplot(223); grid;
plot(w/pi,RealX);
xlabel('w');
ylabel('Real');
subplot(224); grid;
plot(w/pi,ImagX);
xlabel('w');
ylabel('Imaginary');

OUTPUT:

%% Method 3: Using ‘freqz’ function


DESCRIPTION:
The freqz function in MATLAB is used to compute and plot the frequency response of a digital
filter. It can be used to visualize the magnitude and phase response of a filter in the frequency
domain.
The freqz function returns both the frequency response H and the frequency vector w. Typically,
we plot the magnitude and phase response using plot().

SYNTAX:

CODE:
%%
w= 0:0.01: pi;
num =[1];
den =[1 -0.5];
Xw=freqz(num,den,w);
MagX=abs(Xw);%for magnitude
PhaseX=angle(Xw);%for phase
RealX=real(Xw);%for real part
ImagX=imag(Xw);%for imaginary part
subplot(221); grid;
plot(w/pi,MagX);
xlabel('w');
ylabel('magnitude');
subplot(222); grid;
plot(w/pi,PhaseX); grid;
xlabel('w');
ylabel('Phase');
subplot(223);
plot(w/pi,RealX); grid;
xlabel('w');
ylabel('Real');
subplot(224); grid;
plot(w/pi,ImagX);
xlabel('w');
ylabel('Imaginary');

OUTPUT:
PROGRAM-11
OBJECTIVE: N-point DFT & FFT of various sequences

1; 0 ≤ n ≤ 3
% 1. Let 𝒙[𝒏]be a 4-point sequence given by 𝑥[𝑛] = { .
0; otherwise
a) Compute and plot the 4-point DFT of 𝑥[𝑛]
b) Compute and plot the 8-point DFT of 𝑥[𝑛]
c) Compute and plot the 16-point DFT of 𝑥[𝑛]

%DTFT
clear;clc;close all;
w=0:0.01:2*pi;
Xw=1+exp(-j*w)+ exp(-j*w*2)+ exp(-j*w*3); %%%DTFT
subplot(221);
plot(w,abs(Xw));
xlabel('Frequency');
ylabel('Magnitude');
%ylim([0 4]);
title('DTFT');

%% 4-point DFT
SYNTAX:
CODE:
%4-point DFT
xn=ones(1,4);
N=4;
n=0:N-1;
k=[0:N-1];
WN=exp(-j*2*pi/N*n'*k);
Xk=xn*WN;
subplot(222);
plot(w,abs(Xw));
hold on;
%w1=2*pi*k/n;
stem(2*pi*k/N,abs(Xk),'filled')
xlabel('2*pi*k/4');
ylabel('Magnitude');
title('4 point DFT');

%% 8-point DFT
SYNTAX:
CODE:
%8-point DFT
xn1=[ones(1,4) zeros(1,4)];
N1=8;
n1=0:N1-1;
k1=[0:N1-1];
WN1=exp(-j*2*pi/N1*n1'*k1);
Xk1=xn1*WN1;
subplot(223);
plot(w,abs(Xw));
hold on;
%w1=2*pi*k1/N1;
stem(2*pi*k1/N1,abs(Xk1),'filled', '*')
xlabel('2*pi*k/8');
ylabel('Magnitude');
title('8 point DFT');

%% 16-point DFT
SYNTAX:
CODE:
%16-point DFT
xn2=[ones(1,4) zeros(1,12)];
N2=16;
n2=0:N2-1;
k2=[0:N2-1];
WN2=exp(-j*2*pi/N2*n2'*k2);
Xk2=xn2*WN2;
subplot(224);
plot(w,abs(Xw));
hold on;
%w1=2*pi*k1/N1;
stem(2*pi*k2/N2,abs(Xk2),'filled')
xlabel('2*pi*k/16');
ylabel('Magnitude');
title('16 point DFT');

OUTPUTS:
PROGRAM-12
OBJECTIVE: Properties of DFT: Circular Time-shift, Circular Time reversal & Circular
Convolution of two sequences.

%Properties of DFT
%% Circular Time-shift of DFT

DESCRIPTION:
A circular time-shift of a Discrete Fourier Transform (DFT) involves rotating the frequency-
domain representation of a signal by a certain number of positions. Imagine the DFT as a
sequence of complex numbers, each representing the magnitude and phase of a specific
frequency component of the signal. Shifting this sequence circularly means that when a
component "shifts off" one end, it reappears at the other end, creating a circular arrangement.
In MATLAB, the circshift function can be utilized to implement this circular shift operation
efficiently. This operation can be beneficial in various signal processing applications, such as
filtering, convolution, and spectral analysis.

CODE:
clear;clc;close all;
N=9;
n=0:N-1;
x=[1 2 3 4 5 6 7 8 9];
subplot(131);
stem(n,x,'filled')
xlabel('n');
ylabel('x(n)');
title('9 point dft');
%X(n-3,mod 9)
n1=mod(n-3,N);
y1=x(n1+1);
subplot(132);
stem(n,y1,'filled','r')
xlabel('n');
ylabel('y1(n)');
title('x(n-3, mod 9)');
%X(n+3,mod 9
n2=mod(n+3,N);
y2=x(n2+1);
subplot(133);
stem(n,y2,'*')
xlabel('n');
ylabel('y2(n)');
title('x(n+3, mod 9)');
OUTPUT:

%% Circular Time reversal of DFT


DESCRIPTION:
Circular time reversal of a Discrete Fourier Transform (DFT) involves flipping the frequency-
domain representation of a signal across its midpoint. In other words, it reverses the order of the
frequency components while maintaining the periodic nature of the DFT. When applying circular
time reversal, the highest frequency component swaps places with the lowest frequency
component, and all other frequency components are similarly reversed around the midpoint of
the spectrum.

CODE:
N=9;
n=0:N-1;
x=[1 2 3 4 5 6 7 8 9];
subplot(221);
stem(n,x,'filled')
xlabel('n');
ylabel('x(n)');
title('9 point dft');
%DFT sequence
k=[0:N-1];
WN=exp(-j*2*pi/N*n'*k);
Xk = x*WN;
subplot(222);
stem(k,abs(Xk),'filled')
xlabel('k');
ylabel('magnitude');
title('dft');
%X(-N,mod 9)
n1=mod(-n,N);
y1=x(n1+1);
subplot(223);
stem(n,y1,'filled','r')
xlabel('n');
ylabel('y1(n)');
title('x(-n, mod 9)');

OUTPUT:
PROGRAM-13
OBJECTIVE: Plot frequency response of Digital FIR and IIR LPF.

% 1. Design a Low-pass FIR digital filter with impulse response given as:
𝟏
𝟏 ; 𝒏 = 𝟎, 𝟏
𝒉(𝒏) = 𝟐 [𝜹(𝒏) + 𝜹(𝒏 − 𝟏) = { 𝟐 . Plot its magnitude and phase response.
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆

CODE:
clc; clear all;
w=linspace(0,2*pi);
b=[0.5 0.5];
a=[1];
h=freqz(b,a,w);
subplot(2,2,1);
plot(w/pi, angle(h));
subplot(2,2,2);
plot(w/pi, abs(h));

OUTPUT:
% 2. Design a Low-pass IIR digital filter with system function given as:
𝟏 − 𝐚 𝟏 + 𝒛−𝟏
𝑯(𝒛) = [ ]
𝟐 𝟏 − 𝒂𝒛−𝟏
Plot its magnitude response for a=0.4, 0.7 and 0.9.
CODE:
v = 0:0.01:pi;
a = 0.4;
num = [(1+a)/2 (1+a)/2];
den = [1 -a];
a1 = 0.7;
num1 = [(1+a1)/2 (1+a1)/2];
den1 = [1 -a1];
a2 = 0.9;
num2 = [(1+a2)/2 (1+a2)/2];
den2 = [1 -a2];
Hw = freqz(num, den, v);
Hw1 = freqz(num1, den1, v);
Hw2 = freqz(num2, den2, v);
subplot(2, 1, 1);
plot(v/pi, abs(Hw), v/pi, abs(Hw1), v/pi, abs(Hw2));
subplot(2, 1, 2);
plot(v/pi, angle(Hw), v/pi, angle(Hw1), v/pi, abs(Hw2));

OUTPUT:
PROGRAM-14
OBJECTIVE: Plot frequency response of Digital FIR and IIR HPF.

% 1. Design a High-pass FIR digital filter with impulse response given as:
𝟏
;𝒏 = 𝟎
𝟐
𝟏
𝒉(𝒏) = 𝟐 [𝜹(𝒏) − 𝜹(𝒏 − 𝟏) = { − 𝟏 ; 𝒏 = 𝟏 . Plot its magnitude and phase response.
𝟐
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
SYNTAX:
CODE:
w=linspace(0,2*pi);
b=[0.5 -0.5];
a=[1];
h=freqz(b,a,w);
subplot(1,1,1);
plot(w/pi, abs(h));

OUTPUT:

% 2. Design a High-pass IIR digital filter with system function given as:
𝟏 + 𝐚 𝟏 − 𝒛−𝟏
𝑯(𝒛) = [ ]
𝟐 𝟏 − 𝒂𝒛−𝟏
Plot its magnitude response for a=0.4, 0.7 and 0.9.

CODE:
v = 0:0.01:pi;
a = 0.4;
num = [(1+a)/2 -(1+a)/2];
den = [1 -a];
a1 = 0.7;
num1 = [(1+a1)/2 -(1+a1)/2];
den1 = [1 -a1];
a2 = 0.9;
num2 = [(1+a2)/2 -(1+a2)/2];
den2 = [1 -a2];
Hw = freqz(num, den, v);
Hw1 = freqz(num1, den1, v);
Hw2 = freqz(num2, den2, v);
subplot(1, 1, 1);
plot(v/pi, abs(Hw), v/pi, abs(Hw1), v/pi, abs(Hw2));

OUTPUT:
PROGRAM-15
OBJECTIVE: Plot frequency response of Digital FIR and IIR BPF.
% 1. Design a Band-pass FIR digital filter with impulse response given as:
𝟏
;𝒏 = 𝟎
𝟐
𝟏
𝒉(𝒏) = 𝟐 [𝜹(𝒏) − 𝜹(𝒏 − 𝟐) = { − 𝟏 ; 𝒏 = 𝟐 . Plot its magnitude and phase response.
𝟐
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆

CODE:
w=linspace(0,2*pi);
b=[0.5 0 -0.5];
a=[1];
h=freqz(b,a,w);
subplot(1,1,1);
plot(w/pi, abs(h));

OUTPUT:

% 2. Design a Band-pass IIR digital filter with system function given as:
𝟏−𝐚 𝟏 − 𝒛−𝟐
𝑯(𝒛) = [ ]
𝟐 𝟏 − 𝒃(𝟏 + 𝒂)𝒛−𝟏 + 𝒂𝒛−𝟐
Plot its magnitude response for a) a=0.3, 0.6 and 0.9 with b=0.35.

CODE:
%%
bn=[1 0 -1];
w=0:0.01:pi;
a1=0.3;
b=0.35;
den1=[1 -b*(1+a1) a1];
b1=(1-a1)/2;
a2=0.6;
b=0.35;
den2=[1 -b*(1+a2) a2];
b2=(1-a2)/2;
a3=0.9;
b=0.35;
den3=[1 -b*(1+a3) a3];
b3=(1-a3)/2;
Hv1 = b1*freqz(bn, den1, w);
Hv2 = b2*freqz(bn, den2, w);
Hv3 = b3*freqz(bn, den3, w)
plot(w/pi, abs(Hv1), w/pi, abs(Hv2),w/pi, abs(Hv3));

OUTPUT:
PROGRAM-16
OBJECTIVE: Plot frequency response of Digital FIR and IIR BRF.

% 1. Design a Band-Reject FIR digital filter with impulse response given as:
𝟏
𝟏 ; 𝒏 = 𝟎, 𝟐
𝒉(𝒏) = 𝟐 [𝜹(𝒏) + 𝜹(𝒏 − 𝟐) = { 𝟐 . Plot its magnitude and phase response.
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
SYNTAX:
plot(w/pi, abs(h));

CODE:
%FIR
w=linspace(0,2*pi);
b=[0.5 0 0.5];
a=[1];
h=freqz(b,a,w);
subplot(1,1,1);
plot(w/pi, abs(h));

OUTPUT:

% 2. Design a Low-pass FIR digital filter with system function given as:
𝟏+𝐚 𝟏 − 𝟐𝒃𝒛−𝟏 + 𝒛−𝟐
𝑯(𝒛) = [ ]
𝟐 𝟏 − 𝒃(𝟏 + 𝒂)𝒛−𝟏 + 𝒂𝒛−𝟐
Plot its magnitude response for a) a=0.3, 0.6 and 0.9 with b=0.35
SYNTAX:
Phase response= abs(Hv1)
CODE:
%%
b=0.35;
b0=[1 -2*b 1];
w=0:0.01:pi;
a1=0.3;
den1=[1 -b*(1+a1) a1];
b1=(1+a1)/2;
a2=0.6;
b=0.35;
den2=[1 -b*(1+a2) a2];
b2=(1+a2)/2;
a3=0.9;
b=0.35;
den3=[1 -b*(1+a3) a3];
b3=(1+a3)/2;
Hv1 = b1*freqz(b0, den1, w);
Hv2 = b2*freqz(b0, den2, w);
Hv3 = b3*freqz(b0, den3, w);
plot(w/pi, abs(Hv1), w/pi, abs(Hv2),w/pi, abs(Hv3));

OUTPUT:
PROGRAM-17
OBJECTIVE: Plot frequency response of Low-pass and High-pass COMB filter.
% 1. Design a Low-pass FIR digital filter with system function given as:
𝟏
𝑯(𝒛) = [𝟏 + 𝒛−𝑳 ]
𝟐
Plot its magnitude response for L=7.
CODE:
num = [0.25 0 0 0 0 0.25];
den = [1 0 0 0 0 0 0];
v = -pi:0.001:pi;
subplot(3, 1, 1);
zplane(num, den);
Hw = freqz(num, den, v);
subplot(3, 1, 2);
plot(v/pi, abs(Hw));
xlabel('w');
ylabel('|Hw|');
title('Magnitude');
subplot(3, 1, 3);
plot(v/pi, angle(Hw));
xlabel('w');
title('Phase');

OUTPUT:

% 2. Design a High-pass FIR digital filter with system function given as:
𝟏
𝑯(𝒛) = [𝟏 − 𝒛−𝑳 ]
𝟐
Plot its magnitude response for L=7.
CODE:
num = [0.25 0 0 0 0 -0.25];
den = [1 0 0 0 0 0 0];
w = -pi:0.001:pi;
subplot(3, 1, 1);
zplane(num, den);
Hw = freqz(num, den, w);
subplot(3, 1, 2);
plot(w/pi, abs(Hw));
xlabel('w');
ylabel('|Hw|');
title('Magnitude');
subplot(3, 1, 3);
plot(w/pi, angle(Hw));
xlabel('w');
title('Phase');

OUTPUT:
PROGRAM-18
OBJECTIVE: Design an FIR LPF using a Rectangular window.

% Using a rectangular window, design a LPF with the pass-band gain of unity, cut-off
frequency is 1000 Hz, and working at sampling frequency of 5kHz. Take the length of
impulse response as M = 17.

CODE:
M=17;
tau=(M-1)/2;
n=0: M-1
Fc= 1000; Fs=5000;
wc=(2*pi*Fc)/Fs;
hd=(sin(wc*(n-tau)))./(pi*(n-tau));
hd(tau+1)=0.4;
wrect=rectwin(M)'
h=hd.*wrect;
w=0:0.01:pi;
Hw=freqz(h,1,w)
MagHw=abs(Hw)
Hwdb=20*log10(MagHw/max(MagHw));
subplot(2,2,1)
stem(n,hd,'filled')
axis([-1 M -0.15 0.5]);
xlabel ('n') ;
ylabel('hd(n)')
title('Ideal impulse response')
subplot (2,2,2)
stem (n, wrect, 'filled');
axis ([-1 M -0.1 1.2]);
xlabel('n' ) ;
ylabel('w(n)');
title('rectangular window')
subplot(2, 2, 3) ;
stem (n, h,'filled') ;
axis ([-1 M -0.15 0.5])
xlabel('n');
ylabel('h(n)');
title('Actual impulse response')
subplot (2,2, 4);
plot(w/pi,Hwdb);
%axis([- 1 -0.15 * 0.5])
xlabel('frequency in pi units');
ylabel('db')
title('Magnitude response')
OUTPUT:
PROGRAM-19
OBJECTIVE: Design an FIR Linear-phase filter using a Hamming window.

% The desired frequency response of a HPF is given by:


𝐞−𝐣𝛕𝛚 ; 𝛚𝐜 ≤ |𝛚| ≤ 𝛑
𝐇𝐝 (𝐞𝐣𝛚 ) = {
𝟎; |𝛚| ≤ 𝛚𝐜
Design a Linear-Phase FIR filter using Hamming window for M = 25 and 𝛚𝐜 = 2.

CODE:
M=17;
tau=(M-1)/2;
n=0: M-1
Fc= 1000; Fs=5000;
wc=(2*pi*Fc)/Fs;
hd=(sin(wc*(n-tau)))./(pi*(n-tau));
hd(tau+1)=0.4;
wrect=rectwin(M)'
h=hd.*wrect;
w=0:0.01:pi;
Hw=freqz(h,1,w)
MagHw=abs(Hw)
Hwdb=20*log10(MagHw/max(MagHw));
subplot(2,2,1)
stem(n,hd,'filled')
axis([-1 M -0.15 0.5]);
xlabel ('n') ;
ylabel('hd(n)')
title('Ideal impulse response')
subplot (2,2,2)
stem (n, wrect, 'filled');
axis ([-1 M -0.1 1.2]);
xlabel('n' ) ;
ylabel('w(n)');
title('rectangular window')
subplot(2, 2, 3) ;
stem (n, h,'filled') ;
axis ([-1 M -0.15 0.5])
xlabel('n');
ylabel('h(n)');
title('Actual impulse response')
subplot (2,2, 4);
plot(w/pi,Hwdb);
%axis([- 1 -0.15 * 0.5])
xlabel('frequency in pi units');
ylabel('db')
title('Magnitude response')
OUTPUT:
PROGRAM-20
OBJECTIVE: Design an FIR High-pass filter using a Hanning window.
% Write a MATLAB program to design an FIR HPF for the following specifications:
Pass band edge: 4kHz
Stop-band edge: 2kHz
Pass-band attenuation: 2dB
Stop-band attenuation: 40dB
Sampling frequency: 20kHz
Use Hanning window for M=17.

CODE:
Fp = 4000; Fs = 2000; Ft = 20*10^3;
wp = (2*pi*Fp)/Ft;
ws = (2*pi*Fs)/Ft;
trwidth = ws-wp;
M = 17;
tau = (M-1)/2;
wc = (wp+ws)/2;
n = 0:M-1;
hd = (sin(wc*(n-tau)))./(pi*(n-tau));
hd(tau+1) = 0.35;
whan = hann(M)';
h = hd.*whan;
w = 0:0.01:pi;
Hw = freqz(h,1,w);
MagHw = abs(Hw);
HwdB = 20*log10(MagHw/max(MagHw));
subplot(221); stem(n,hd,'filled');
axis([-1 M -0.15 0.5]);
xlabel('n'); ylabel('hd(n)');
title('Ideal impluse response')
subplot(222); stem(n,whan,'filled');
axis([-1 M -0.1 1.2]);
xlabel('n'); ylabel('w(n)');
title('Hann window')
subplot(223); stem(n,h,'filled');
axis([-1 M -0.15 0.5]);
xlabel('n'); ylabel('h(n)');
title('Actual impluse response')
subplot(224); plot(w/pi,HwdB)
axis([0 1 -100 10]);
xlabel('frequency in pi units'); ylabel('dB');
title('Magnitude response')
Ap = -min(HwdB(1:1:wp/0.01+1))
As = -round(max(HwdB(ws/0.01+1:315)))
OUTPUT:
Ap = 14.2123

As = 1
PROGRAM-22
OBJECTIVE: Design an IIR LPF Butterworth filter using Bilinear Transformation.

% Write a MATLAB program to design an IIR LPF Butterworth filter using Bilinear
Transformation for the following specifications:
𝟎. 𝟖 ≤ |𝑯(𝒆𝒋𝝎 )| ≤ 𝟏, |𝝎| ≤ 𝟎. 𝟐𝝅
|𝑯(𝒆𝒋𝝎 )| ≤ 𝟎. 𝟐, 𝟎. 𝟔𝝅 ≤ |𝝎| ≤ 𝝅 𝑨𝒔𝒔𝒖𝒎𝒆 𝑻 = 𝟏𝒔𝒆𝒄.
CODE:
Ap=.6;
As=.3;
PEF_D=0.2*pi;
SEF_D=.6*pi;
T=1;
alpha_P=-20*log10(Ap);
alpha_S=-20*log10(As);
PEF_A=(2/T)*tan(PEF_D/2);
SEF_A=(2/T)*tan(SEF_D/2);
[N,la]=buttord(PEF_A,SEF_A,alpha_P,alpha_S,'s');
[Bn,An]=butter(N,la,'s');
Hsn=tf(Bn,An);
[B,A]=butter(N,la,'s');
Hs=tf(B,A);
[num,den]=bilinear(B,A,1/T);
Hz=tf(num,den,T);
w=0:pi/16:pi;
Hw=freqz(num,den,w);
Hw_mag=abs(Hw);
plot(w/pi,Hw_mag,'k');
title('Magnitude response')

OUTPUT:
PROGRAM-24

OBJECTIVE: Image Processing understanding using MATLAB.

CODE:
% 1. Image read and show
clc; clear all; close all;
I = imread('tom and jerry.jpg'); imshow (I);
title('image');

% 2. Image complement
%% Image Complement
I = imread('tom and jerry.jpg');
a1 = imcomplement(I); %complement of the image
%obtained by subtracting each pixel from maximum value
imshow(a1);
title('tom and jerry comp')

% 3. Conversion on any image to gray images


%% Conversion of any image to gray image
I = imread('tom and jerry.jpg');
g = rgb2gray(I);
imshow(g);

% 4. Enhancement of image and various operations on an image


%% Enhancement of image and various operations on an image
I = imread('tom and jerry.jpg');
J = imresize(I, 2); %resizing
K = imcrop(J); %cropping, select the area to be cropped
subplot(211);
imshow(J);
title('image-1');
subplot(212);
imshow(K);
title('image - 2');

% 5. superimposition of image
%% superposition of image
I1 = imread('tom and jerry.jpg');
J1 = imread('tom and jerry.jpg');
K1 = imadd(I1,J1);
subplot(311);
imshow(I1);
title('image- 1');
subplot(312);
imshow(J1);
title('image - 2');
subplot(313);
imshow(K1);
title('addition of two images');

% 6. Color and Contrast Adjustment on images


%% color and contrast adjustment of image
g=rgb2gray(I);
b=histeq(g);
subplot(211),subimage(I),title('original image');
subplot(212),subimage(b),title('contrast image'),xlabel('contrast increased by histogram equi ')

OUTPUT:
PROGRAM- 25
EXERCISE 1
QUESTION- 1
OBJECTIVE: Write a MATLAB code to generate i) sawtooth wave ii) Sinc wave

SYNTAX: a = sawtooth(t)
b = sinc(t)
% Sawtooth Wave
CODE:
t = 0:0.01:10; % Time vector
f = 1; % Frequency in Hz
sawtoothWave = sawtooth(pi * f * t);
plot(t, sawtoothWave);
title('Sawtooth Wave');
xlabel('Time (s)');
ylabel('Amplitude');

OUTPUT:

% Sinc Wave
CODE:
t = -10:0.01:10; % Time vector
sincWave = sinc(t);
figure;
plot(t, sincWave);
title('Sinc Wave');
xlabel('Time (s)');
ylabel('Amplitude');
OUTPUT:
QUESTION – 2
OBJECTIVE: Write a MATLAB code to generate discrete-time sequences:
1) x(n) = cos(4 pi n/ 15) 2) x(n) = cos(n/8)
SYNTAX: y = cos(theta)

CODE:

n=0:1:30;
y=cos((4*pi*n)/15);
subplot(2,1,1)
stem(n,y);grid;
title('discrete cos 4*pi*n / 15 signal');
xlabel('time');
ylabel('Amplitude');

n=0:1:30;
y=cos(n/8);
subplot(2,1,2)
stem(n,y);grid;
title('discrete cos n / 8 signal');
xlabel('time');
ylabel('Amplitude');
OUTPUT:
QUESTION- 3
OBJECTIVE: Write a MATLAB code to generate even and odd parts of signal x(n)= (0.8)n
SYNTAX: a = flipr(x)
CODE:
n = -5:0.01:5;
x_n = (0.8).^n;

x_e = 0.5 * (x_n + fliplr(x_n));


x_o = 0.5 * (x_n - fliplr(x_n));

subplot(3,1,1);
plot(n, x_n);
title('Original Signal x(n)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(3,1,2);
plot(n, x_e);
title('Even Part x_e(t)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(3,1,3);
plot(n, x_o);
title('Odd Part x_o(t)');
xlabel('Time (s)');
ylabel('Amplitude');
OUTPUT:

QUESTION – 4
OBJECTIVE: Write a MATLAB program to perform amplitude scaling and time-shifting on
signal: x(n) = 1+ n , 0<n<2
SYNTAX: scaled_x_n = amplitude_scale * x_n;
shifted_n = n + time_shift;

CODE:
n = 0:2; % Time index vector
x_n = 1 + n; % Original signal x(n)
% Amplitude scaling factor and time shift value
amplitude_scale = 2;
time_shift = -1;

scaled_x_n = amplitude_scale * x_n;

shifted_n = n + time_shift;
shifted_x_n = amplitude_scale * [zeros(1, time_shift), x_n];

figure;
subplot(3,1,1);
stem(n, x_n, 'filled');
title('Original Signal x(n)');
xlabel('n');
ylabel('x(n)');
subplot(3,1,2);
stem(n, scaled_x_n, 'filled');
title('Amplitude Scaled Signal (2 * x(n))');
xlabel('n');
ylabel('Amplitude Scaled x(n)');
subplot(3,1,3);
stem(shifted_n, shifted_x_n, 'filled');
title('Time-Shifted Signal x(n + 1)');
xlabel('n');
ylabel('Amplitude Scaled and Time-Shifted x(n)');

OUTPUT:

QUESTION - 5
OBJECTIVE: Write a MATLAB code to perform linear convolution of the sequences:
X1(n)= 1, 1<n<10 and x2(n)= 1, 2<n<10
SYNTAX: y = cos(x1,x2)

CODE:
n=1:1:10;
x1 = n;
n = 2:1:10;
x2 = n;
y=conv(x1,x2);
subplot(3,1,1)
stem(x1);grid;
title('input 1');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,2)
stem(x2);grid;
title('input 2');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(y);grid;
title('convolution');
xlabel('time');
ylabel('Amplitude');
disp(x1)
disp(x2)
disp('the resultant signal is[')
disp(y)

OUTPUT:

QUESTION- 6
OBJECTIVE: Write a MATLAB code to find z–transform of x(n)= 1 + n(0.4)n-1. and sketch its
pole-zero plot.
SYNTAX: a = ztrans(b)

CODE:
syms n;
y2=1+n*(.25)^(n-1);
xz=ztrans(y2);
disp('y2=');
pretty(y2);
disp('xz=');
pretty(xz);
a=[16 -24 1 7];
b=[16 8 -15 0];
zplane(b,a);
OUTPUT:

QUESTION 7
OBJECTIVE: Write a MATLAB code to find roots of polynomial and sketch pole-zero plot of:
1) H(z) = (z2+ 0.8Zz +0.8) / (z2 + 0.49) 2) ( 3z2 + 2z +1) / ( z2 – 3z + 2)
SYNTAX: z= roots(b)
zplane(b,a)

CODE:
%% 1
w= linspace(0, pi);
b=[1 0.8 0.8];
a=[1 0 0.49]
z= roots(b)
zplane(b,a)

%% 2
w= linspace(0, pi);
b=[3 2 1];
a=[1 -3 2]
z= roots(b)
zplane(b,a)

OUTPUT:
a =
1.0000 0 0.4900
z =
-0.4000 + 0.8000i
-0.4000 - 0.8000i

a =
1 -3 2
z =
0.3333 + 0.4714i
-0.3333 - 0.4714i

QUESTION 8
OBJECTIVE: Write a MATLAB code to sketch impulse response of discrete-time sequence
governed by transfer function H(z) = 1 / ( 1 – 0.8 z-1 +0.16 z-2)
SYNTAX: [h,k]= impz(num, den, L)

CODE:
num= 1;
den= [1 -0.8 0.16];
L=5;
[h,k]= impz(num, den, L)
stem(k,h,'filled')

OUTPUT:
h =

1.0000
0.8000
0.4800
0.2560
0.1280

k =

0
1
2
3
4

PROGRAM-26
EXERCISE-II

QUESTION 1
OBJECTIVE: Write a MATLAB code to perform convolution of the signals x1(n) = (0.4)nu(n)
and x2(n)= (0.5)nu(n) using z-transform and then perform deconvolution using the result of
convolution to extract the signals x1(n) and x2(n).
CODE:
syms n z;
n>=0;
y3=(0.4).^n;
y4=(0.5).^n;
xz1=ztrans(y3);
xz2=ztrans(y4);
xz3=xz1*xz2;
conv=iztrans(xz3);
disp('convolution of x1[n] and x2[n]')
simplify(conv)
deconv1=xz3/xz2;
deconvn1=iztrans(deconv1);
disp('x1[n] is')
simplify(deconvn1)
deconv2=xz3/xz1;
deconvn2=iztrans(deconv2);
disp('x2[n] is')
simplify(deconvn2)

OUTPUT:
convolution of x1[n] and x2[n]

ans =
5*(1/2)^n - 4*(2/5)^n

x1[n] is

ans =
(2/5)^n

x2[n] is

ans =
1/2^n

QUESTION 2
OBJECTIVE: Design an FIR filter to meet the following specifications:
1. Pass-band edge: 2 kHz
2. Stop-band edge: 5 kHz
3. Pass-band attenuation: 2 dB
4. Stop-band attenuation: 42 dB
5. Sampling frequency: 20 kHz
Use Hanning window.

CODE:
clc; clear all; close all;
Fp=2000; Fs=5000; Ft=20*10^3;
wp=(2*pi*Fp)/Ft;
ws=(2*pi*Fs)/Ft;
trwidth=ws-wp;
M=ceil(6.2*pi/trwidth) +2;
tau= (M-1)/2;
wc=(wp+ws)/2;
n=0:M-1;
hd=(sin (wc* (n-tau)))./ (pi* (n-tau));
hd(tau+1)=0.35;
whan=hann (M)';
h=hd.*whan;
w=0:0.01:pi;
Hw=freqz (h,1,w);
MagHw=abs (Hw);
HwdB=20*log10 (MagHw/max (MagHw));
subplot (221); stem (n, hd);
axis ([-1 M -0.15 0.5]);
xlabel('n');ylabel('hd(n)');
title('Ideal impulse response')
subplot (222); stem (n, whan);
axis([-1 M -0.1 1.2]);
xlabel('n’);ylabel(‘w(n)');
title('Hann window')
subplot (223); stem (n, h);
axis([-1 M -0.15 0.5]);
xlabel('n'); ylabel('h(n)'); title('Actual impulse response')
subplot (224); plot (w/pi, HwdB)
axis ([0 1 -100 10]);
xlabel('frequency in pi units'); ylabel('dB');
title('Magnitude response')
Ap=-min (HwdB (1:1:wp/0.01+1));
As=-round (max (HwdB (ws/0.01+1:315)));

OUTPUT:
QUESTION 3
OBJECTIVE: Design a digital FIR LPF with the following specifications using Parks-
McClellan algorithm:
1. Pass-band edge frequency: 0.2 pi
2. Stop-band edge frequency: 0.3 pi
3. Pass-band attenuation: 0.25 dB
4. Stop-band attenuation: 50 dB

CODE:
wp = 0.2; % Passband edge frequency (normalized)
ws = 0.3; % Stopband edge frequency (normalized)
Ap = 10^(0.25/20); % Passband amplitude (magnitude)
As = 10^(-50/20); % Stopband amplitude (magnitude)

% Design filter using Parks-McClellan algorithm


N = 100; % Choose an initial filter order
b = remez(N, [0 wp ws 1], [1 1 0 0]);

% Plot frequency response


freqz(b);

[H, W] = freqz(b);
wp_index = round(wp * length(W));
ws_index = round(ws * length(W));
Ap_actual = -20*log10(abs(H(wp_index)));
As_actual = -20*log10(abs(H(ws_index)));
disp(['Actual passband attenuation: ', num2str(Ap_actual), ' dB']);
disp(['Actual stopband attenuation: ', num2str(As_actual), ' dB']);

OUTPUT:

Actual passband attenuation: -0.00046457 dB


Actual stopband attenuation: 74.8296 dB

QUESTION 4
OBJECTIVE: Design a HPF that has the following specifications using Parks-McClellan
algorithm:
1. Pass-band edge frequency: 0.75 pi
2. Stop-band edge frequency: 0.6 pi
3. Pass-band attenuation: 0.5 dB
4. Stop-band attenuation: 50 dB
CODE:
wp = 0.75; % Passband edge frequency (normalized)
ws = 0.6; % Stopband edge frequency (normalized)
Ap = 10^(0.5/20); % Passband amplitude (magnitude)
As = 10^(-50/20); % Stopband amplitude (magnitude)

% Design filter using Parks-McClellan algorithm


b = remez(50, [0 ws wp 1], [0 0 1 1]);

% Plot frequency response


freqz(b);

% Additional: Check the actual passband and stopband attenuations


[H, W] = freqz(b);
wp_index = round(wp * length(W));
ws_index = round(ws * length(W));
Ap_actual = -20*log10(abs(H(wp_index)));
As_actual = -20*log10(abs(H(ws_index)));
disp(['Actual passband attenuation: ', num2str(Ap_actual), ' dB']);
disp(['Actual stopband attenuation: ', num2str(As_actual), ' dB']);

OUTPUT:

Actual passband attenuation: 0.01059 dB


Actual stopband attenuation: 86.2968 dB

You might also like