0% found this document useful (0 votes)
10 views57 pages

DSPLAST

Calicut University MAT Lab /DSP Lab Manual

Uploaded by

yamktcr
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)
10 views57 pages

DSPLAST

Calicut University MAT Lab /DSP Lab Manual

Uploaded by

yamktcr
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/ 57

(2022-2025)

2022-2025
Digital Signal Processing Lab

FAMILIARIZATION OF MATLAB

Department of Electronics 1 CAS Nattika


Digital Signal Processing Lab

MATLAB BASICS

The MATLAB high-performance language for technical computing.It integrates


computation, visualization, and programming in an easy-to-use environment where problems and
solutions are expressed in familiar mathematical notation. Typical uses include

• Math and computation


• Algorithm development
• Data acquisition
• Modeling, simulation, and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. It allows you to solve many technical computing problems, especially
those with matrix and vector formulations, in a fraction of the time it would take to write a
program in a scalar noninteractive language such as C or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of
the art in software for matrix computation.

The MATLAB System

The MATLAB system consists of these main parts:

Desktop Tools and Development Environment


This part of MATLAB is the set of tools and facilities that help you use and become
more productive with MATLAB functions and files. Many of these tools are graphical user
interfaces. It includes the MATLAB desktop and Command Window, a command history, an
editor and debugger, a code analyzer, browsers for viewing help, the workspace, files, and other
tools.

Department of Electronics 2 CAS Nattika


Digital Signal Processing Lab

Mathematical Function Library


This library is a vast collection of computational algorithms ranging from elementary
functions like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like
matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.
The Language
The MATLAB language is a high-level matrix/array language with control flow
statements, functions, data structures, input/output and object-oriented programming features. It
allows both “programming in the small” to rapidly create quick programs you do not intend to
reuse. You can also do “programming in the large” to create complex application programs
intended for reuse.
Graphics
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as
well as annotating and printing these graphs. It includes high-level functions for two-dimensional
and three-dimensional data visualization, image processing, animation and presentation graphics.
It also includes low-level functions that allow you to fully customize the appearance of graphics
as well as to build complete graphical user interfaces on your MATLAB applications.
External Interfaces
The external interfaces library allows you to write C and Fortran programs that
interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic
linking), calling MATLAB as a computational engine and for reading and writing MAT-files.
Variables
Variable names must begin with an alphanumeric letter, followed by any number of
letters, digits, or underscores. MATLAB is case sensitive, it distinguishes between uppercase and
lowercase letters. A and a are different variables.Variable names may not start with a number,
contain a dash or contain reserved characters.
The % character is a special character and means a comment line. MATLAB will
ignore any text following the % symbol.

Department of Electronics 3 CAS Nattika


Digital Signal Processing Lab

Operators
Arithmatic operators perform numeric computations. The following table provides a
summary.
+ addition
- subtraction
* multiplication
/ division
^ power
.* element by element multiplication
./ element by element division
.^ element by element power

Department of Electronics 4 CAS Nattika


Digital Signal Processing Lab

HOW TO GET STARTED

Double click on the icon for MATLAB. Within about 30 seconds MATLAB will
open, a screen like the picture below appears.

This is the MATLAB screen. It has broken into 3 parts.

 Command Window: This is where you can type commands and usually the answers (or
error messages) appear here too. You will see the cursor flickering after the >> prompt.
This means that MATLAB is waiting for further instructions.
 Workspace: If you define new quantities (called variables) their names should be listed
here.
 Command History: This is the space where past commands are remembered. If you want
to re-run a previous command or to edit it, you can drag it from this window to the
command window.

Department of Electronics 5 CAS Nattika


Digital Signal Processing Lab

To begin MATLAB, click File>> New>> M-file. This opens a blank window as shown
below.

The M-file is executed using the run command under the Tools menu. The output
signal appears in Figure Window.

Department of Electronics 6 CAS Nattika


Digital Signal Processing Lab

The output data appears in command window.

Department of Electronics 7 CAS Nattika


Digital Signal Processing Lab

MATLAB FUNCTIONS

Department of Electronics 8 CAS Nattika


Digital Signal Processing Lab

A function is a group of statements that together perform a task. Functions are small
programs that accept inputs and return outputs. Functions provide more flexibility in
programming. Some of the frequently used buit-in functions in MATLAB are listed below.

subplot(m,n,p) Breaks the figure window in to an m-by-n matrix of small


subplots and select the pth subplot for the current graph.
axis([xmin xmax ymin ymax]) Sets the minimum and maximum values for x- and y-axes on
the current plot.
clc Clear the command window.
clear all Removes all variables, functions and MEX-files from
memory, leaving the workspace empty.
close all Closes all the open figure windows.
xlabel (‘text’) Adds text along the x-axis on the current plot.
ylabel (‘text’) Adds text along the y-axis on the current plot.
title (‘text’) Adds text at top of the current plot.
stem(x,y) Plots the data sequence y at the values specified in x.
plot(x,y) Plots vector y versus vector x.
user_entry = input(‘prompt’) Displays prompt as a prompt on the screen, waits for input
from the keyboard and returns the value entered in user_entry.
ones(N) Is an N-by-N matrix of ones.
zeros(N) Is an N-by-N matrix of zeros.
ones(M,N) Is an M-by-N matrix of ones.
zeros(M,N) Is an M-by-N matrix of zeros.
length(x) Returns the length of vector x.
size(x) Returns the dimensions of array x.
mod(a,m) Returns the remainder after division of a by m.
max(a,b) Returns an array with the largest elements taken from a or b.
conv(x,h) Computes the convolution of two sequences x and h.

Department of Electronics 9 CAS Nattika


Digital Signal Processing Lab

[h,t] = impz(b,a) Returns the impulse response of the filter with numerator
coefficients b and denominator coefficients a. impz chooses
the number of samples and returns the response in the column
vector h and the sample times in the column vector t.
filter(b,a,x) Filters the data in vector x with the filter described by
numerator coefficients b and denominator coefficients a.
fft(x,n) Returns the n-point DFT of the sequence x. If the length of x
is less than n, x is padded with trailing zeros to length n. If the
length of x is greater than n, x is truncated.
ifft(x,n) Returns the n-point inverse DFT of the sequence x.
abs(x) Returns the absolute value of the elements of vector x. If x is
complex, returns the magnitude.
angle(z) Returns the phase angles, in radians, for each element of
vector z. The angles lie between ± π.

Department of Electronics 10 CAS Nattika


Digital Signal Processing Lab

PROGRAMS

Department of Electronics 11 CAS Nattika


Digital Signal Processing Lab

Prog.No:01
18-01-2024

GENERATION OF DISCRETE TIME SIGNALS 1

AIM
Generate unit Impulse, step and ramp functions.

PROGRAM
clc
clear all
close all
n=-10:10

%GENERATION OF UNIT IMPULSE FUNCTION

y=[zeros(1,10) 1 zeros(1,10)]
subplot(3,1,1)
stem(n,y)
axis([-10,10,0,2])
xlabel('n')
ylabel('del(n)')
title('Unit Impulse')

%GENERATION OF UNIT STEP FUNCTION

y=[zeros(1,10) ones(1,11)]
subplot(3,1,2)
stem(n,y)
axis([-10,10,0,2])
xlabel('n')
ylabel('u(n)')
title('Unit Step')

%GENERATION OF UNIT RAMP FUNCTION

y=[zeros(1,11) (1:10)]
subplot(3,1,3)
stem(n,y)
axis([-10,10,0,10])
xlabel('n')
ylabel('r(n)')
title('Unit Ramp')

Department of Electronics 12 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Unit impulse, step and ramp functions are plotted.

Department of Electronics 13 CAS Nattika


Digital Signal Processing Lab

Prog.No:02
18-01-2024

GENERATION OF DISCRETE TIME SIGNALS 2

AIM
Generate shifted Impulse and step functions.

PROGRAM
clc
clear all
close all
n=-10:10

%GENERATION OF SHIFTED IMPULSE FUNCTION

y=[zeros(1,12) 1 zeros(1,8)]
subplot(3,1,1)
stem(n,y)
axis([-10,10,0,2])
xlabel('n')
ylabel('del(n-2)')
title('Shifted Impulse Function')

%GENERATION OF SHIFTED STEP FUNCTION 1

y=[zeros(1,12) ones(1,9)]
subplot(3,1,2)
stem(n,y)
axis([-10,10,0,2])
xlabel('n')
ylabel('u(n-2)')
title('Shifted Step Function 1')

%GENERATION OF SHIFTED STEP FUNCTION 2

y=[zeros(1,7) ones(1,14)]
subplot(3,1,3)
stem(n,y)
axis([-10,10,0,2])
xlabel('n')
ylabel('u(n+3)')
title('Shifted Step Function 2')

Department of Electronics 14 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Shifted impulse and step functions are plotted.

Department of Electronics 15 CAS Nattika


Digital Signal Processing Lab

Prog.No:03
25-01-2024

GENERATION OF DISCRETE TIME SIGNALS 3

AIM
Generate exponential functions.

PROGRAM
clc
clear all
close all
n=-10:10

%GENERATION OF GROWING EXPONENTIAL FUNCTION

a=1.1
y=a.^n
subplot(2,1,1)
stem(n,y)
axis([-10,10,0,3])
xlabel('n')
ylabel('x(n)')
title('Growing Exponential')

%GENERATION OF DECAYING EXPONENTIAL FUNCTION

a=0.9
y=a.^n
subplot(2,1,2)
stem(n,y)
axis([-10,10,0,3])
xlabel('n')
ylabel('x(n)')
title('Decaying Exponential')

Department of Electronics 16 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Exponential functions are plotted.

Department of Electronics 17 CAS Nattika


Digital Signal Processing Lab

Prog.No:04
25-01-2024

GENERATION OF DISCRETE TIME SIGNALS 4

AIM
Generate sinusoidal functions.

PROGRAM
clc
clear all
close all
n=-40:40

%GENERATION OF SINE WAVE

A=4
N=20
y=A*sin(2*pi*n/N)
subplot(2,1,1)
stem(n,y)
axis([-40,40,-5,5])
xlabel('n')
ylabel('x(n)')
title('Sine Wave')

%GENERATION OF COSINE WAVE

A=4
N=20
y=A*cos(2*pi*n/N)
subplot(2,1,2)
stem(n,y)
axis([-40,40,-5,5])
xlabel('n')
ylabel('x(n)')
title('Cosine Wave')

Department of Electronics 18 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Sinusoidal functions are plotted.

Department of Electronics 19 CAS Nattika


Digital Signal Processing Lab

Prog.No:05
01-02-2024

GENERATION OF DISCRETE TIME SIGNALS 5

AIM
Generate square and sawtooth waveforms.

PROGRAM
clc
clear all
close all
n=-20:20

%GENERATION OF SQUARE WAVE

A=5
N=10
y=A*square(2*pi*n/N)
subplot(2,1,1)
stem(n,y)
axis([-20,20,-7,7])
xlabel('n')
ylabel('x(n)')
title('Square Wave')

%GENERATION OF SAWTOOTH WAVE

A=5
N=10
y=A*sawtooth(2*pi*n/N)
subplot(2,1,2)
stem(n,y)
axis([-20,20,-7,7])
xlabel('n')
ylabel('x(n)')
title('Sawtooth Wave')

Department of Electronics 20 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Square and sawtooth waveforms are plotted.

Department of Electronics 21 CAS Nattika


Digital Signal Processing Lab

Prog.No:06
01-02-2024

GENERATION OF CONTINUOUS TIME SIGNALS 1

AIM
Generate unit step and ramp functions.

PROGRAM
clc
clear all
close all

%GENERATION OF UNIT STEP FUNCTION

t=-10:.5:10
y=[zeros(1,21) ones(1,20)]
subplot(2,1,1)
plot(t,y)
axis([-10,10,0,2])
xlabel('t')
ylabel('u(t)')
title('Unit Step Function')

%GENERATION OF UNIT RAMP FUNCTION

t=-10:10
y=[zeros(1,11) (1:10)]
subplot(2,1,2)
plot(t,y)
axis([-10,10,0,10])
xlabel('t')
ylabel('r(t)')
title('Unit Ramp Function')

Department of Electronics 22 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Unit step and ramp functions are plotted.

Department of Electronics 23 CAS Nattika


Digital Signal Processing Lab

Prog.No:07
08-02-2024

GENERATION OF CONTINUOUS TIME SIGNALS 2

AIM
Generate sinusoidal functions.

PROGRAM
clc
clear all
close all
t=-20:.01:20

%GENERATION OF SINE WAVE

A=2
T=10
y=A*sin(2*pi*t/T)
subplot(2,1,1)
plot(t,y)
axis([-20,20,-3,3])
xlabel('t')
ylabel('x(t)')
title('Sine Wave')

%GENERATION OF COSINE WAVE

A=2
T=10
y=A*cos(2*pi*t/T)
subplot(2,1,2)
plot(t,y)
axis([-20,20,-3,3])
xlabel('t')
ylabel('x(t)')
title('Cosine Wave')

Department of Electronics 24 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Sinusoidal functions are plotted.

Department of Electronics 25 CAS Nattika


Digital Signal Processing Lab

Prog.No:08
08-02-2024

GENERATION OF CONTINUOUS TIME SIGNALS 3

AIM
Generate square, sawtooth and triangular waveforms.

PROGRAM
clc
clear all
close all
t=-20:.01:20

%GENERATION OF SQUARE WAVE

A=2
T=5
y= A*square(2*pi*t/T)
subplot(3,1,1)
plot(t,y)
axis([-20,20,-3,3])
xlabel('t')
ylabel('x(t)')
title('Square Wave')

%GENERATION OF SAWTOOTH WAVE

A=2
T=5
y= A*sawtooth(2*pi*t/T)
subplot(3,1,2)
plot(t,y)
axis([-20,20,-3,3])
xlabel('t')
ylabel('x(t)')
title('Sawtooth Wave')

%GENERATION OF TRIANGULAR WAVE

A=2
T=5
dc=0.5
y= A*sawtooth(2*pi*t/T,dc)
subplot(3,1,3)
plot(t,y)
axis([-20,20,-3,3])
xlabel('t')
ylabel('x(t)')
title('Triangular Wave')

Department of Electronics 26 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Square, sawtooth and triangular waveforms are plotted.

Department of Electronics 27 CAS Nattika


Digital Signal Processing Lab

Prog.No:09
15-02-2024

AMPLITUDE MODULATION

AIM
Generate an amplitude modulating signal for a given carrier signal, modulating signal and
modulation index.

THEORY
In amplitude modulation, the instantaneous amplitude of the carrier signal is varied
in accordance with the amplitude of the modulating (or message) signal. If the carrier signal is
Vc sinωct and message signal is Vm sinωmt , then modulated signal is given by
VAM = (1+m sinωmt) Vc sinωct
where m is the modulation index which is equal to Vm / Vc

PROGRAM
clc
clear all
close all
t=0:0.1:500

%GENERATION OF CARRIER SIGNAL

T1=10
cs=4*sin(2*pi*t/T1)
subplot(5,1,1)
plot(t,cs)
xlabel('t')
ylabel('c(t)')
title('Carrier Signal')

%GENERATION OF MESSAGE SIGNAL

T2=100
ms=2*sin(2*pi*t/T2)
subplot(5,1,2)
plot(t,ms)
xlabel('t')
ylabel('m(t)')
title('Message Signal')

Department of Electronics 28 CAS Nattika


Digital Signal Processing Lab

%GENERATION OF AM WAVE WITH 0< m <1

m=0.5
am=(1+m*sin(2*pi*t/T2)).*cs
subplot(5,1,3)
plot(t,am)
xlabel('t')
ylabel('x(t)')
title('AM Wave with 0< m <1 ')

%GENERATION OF AM WAVE WITH m =1

m=1
am=(1+m*sin(2*pi*t/T2)).*cs
subplot(5,1,4)
plot(t,am)
xlabel('t')
ylabel('x(t)')
title('AM Wave with m =1')

%GENERATION OF AM WAVE WITH m >1

m=3
am=(1+m*sin(2*pi*t/T2)).*cs
subplot(5,1,5)
plot(t,am)
xlabel('t')
ylabel('x(t)')
title('AM Wave with m >1')

Department of Electronics 29 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
AM wave is generated and plotted.

Department of Electronics 30 CAS Nattika


Digital Signal Processing Lab

Prog.No:10
22-02-2024

LINEAR CONVOLUTION 1

AIM
Perform linear convolution of two given sequences starting from origin.

THEORY
Linear convolution is the operation to find out the output y(n) of an LTI system if its
input x(n) and impulse response h(n) are known.
y(n) = x(n) * h(n)

𝐲(𝐧) = ∑ 𝐱(𝐤) 𝐡(𝐧 − 𝐤)


𝒌=−∞
In MATLAB there is a built-in function conv to perform linear convolution.

PROGRAM
clc
clear all
close all
x=input('enter the first sequence')
x1=input('enter the starting of n value')
h=input('enter the second sequence:')
h1=input('enter the starting n value')
y=conv(x,h)

% INPUT SIGNAL

subplot(3,1,1)
n=x1:length(x)+x1-1
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('input signal')

% IMPULSE RESPONSE
subplot(3,1,2)
n=h1:length(h)+h1-1
stem(n,h)
xlabel('n')
ylabel('h(n)')
title('impulse responce')

Department of Electronics 31 CAS Nattika


Digital Signal Processing Lab

%PLOTTING OUTPUT SIGNAL

subplot(3,1,3)
n=x1+h1:length(y)+x1+h1-1
stem(n,y)
xlabel('n')
ylabel('y(n)')
title('output signal')

OBSERVATION 1:

enter the first sequence:[1 1 2]


enter the starting of n value 0
enter the second sequence:[1 2 1]
enter the starting of n value 0
y =

1 3 5 5 2

OBSERVATION 2:

enter the first sequence:[1 -2 3 1]


enter the starting of n value 0
enter the second sequence:[2 -3 -2]
enter the starting of n value 0
y =

2 -7 10 -3 -9 -2

Department of Electronics 32 CAS Nattika


Digital Signal Processing Lab

OUTPUT 1

Department of Electronics 33 CAS Nattika


Digital Signal Processing Lab

OUTPUT 2

RESULT
Linear convolution is performed and signals are plotted.

Department of Electronics 34 CAS Nattika


Digital Signal Processing Lab

Prog.No:11
01-03-2024

CIRCULAR CONVOLUTION

AIM
Perform circular convolution of two given sequences.

THEORY
A convolution operation that contains a circular shift is called circular convolution.
Circular convolution of two sequences x1(n) and x2(n) each having a length of N is given by

𝐱 𝟏 (𝐧) ⊛ 𝐱 𝟐 (𝐧) = ∑𝐍−𝟏


𝐤=𝟎 𝐱 𝟏 (𝐤) 𝐱 𝟐 ((𝐧 − 𝐤))𝐍

The result of circular convolution is also an N point sequence. If the length of the given sequences
is not equal, sufficient number of zeros must be padded to each.

PROGRAM
clc
clear all
close all

%INPUTTING DATA
x=input('enter the sequence x(n)=')
h=input('enter the sequence h(n)=')

%ZERO PADDING
xl=length(x)
hl=length(h)
yl=max(xl,hl)
x=[x,zeros(1,yl-xl)]
h=[h,zeros(1,yl-hl)]

c=cconv(x,h,yl)
n=0:yl-1
subplot(3,1,1)
stem(n,x)
title('first seq')

%GENERATION OF BY(n)
subplot(3,1,2)
stem(n,h)
title('seond seq')

Department of Electronics 35 CAS Nattika


Digital Signal Processing Lab

%GENERATION OF CIRCULAR CONVOLUTION

subplot(3,1,3)
stem(n,c)
title('circular convalution')

OBSERVATION 1:

enter the sequence x(n)=[1 2 2 1]

enter the sequence h(n)=[1 2 3 1]

y =

11 9 10 12

OBSERVATION 2:

enter the sequence x(n)=[1 -1 -2 3 -1]

enter the sequence h(n)=[1 2 3]

y = 11 9 10
8 -2 -1 -4 -1

Department of Electronics 36 CAS Nattika


Digital Signal Processing Lab

OUTPUT 1

Department of Electronics 37 CAS Nattika


Digital Signal Processing Lab

OUTPUT 2

RESULT
Circular convolution is performed and signals are plotted.

Department of Electronics 38 CAS Nattika


Digital Signal Processing Lab

Prog.No:12
08-03-2024

IMPULSE RESPONSE OF LTI SYSTEM

AIM
Obtain the impulse response of LTI systems described by the difference equations,
(a) y(n)+0.7y(n-1)-0.45y(n-2)-0.6y(n-3) = 0.8x(n)-0.44x(n-1)+0.36x(n-2)+0.02x(n-3)
(b) y(n)-0.5y(n-1)+0.25y(n-2) = x(n)+0.4x(n-1)

THEORY
The impulse response of an LTI system is its response to an impulse. In MATLAB,
the function filter (b, a, x) can be used to find the impulse response from transfer function.
b and a are the coefficients of x(n) and y(n) respectively. x is a unit impulse sequence.

PROGRAM
clc
clear all
close all

%GENERATION OF IMPULSE RESPONSE

b=input('enter the coefficients of x(n):')


a=input('enter the coefficients of y(n):')
N=input('enter the desired length of impulse response:')
x=[1 zeros(1,N-1)]
y=filter(b,a,x)
n=0:N-1
stem(n,y)
xlabel('n')
ylabel('h(n)')
title('Impulse Response of LTI System')

OBSERVATION 1:

enter the coefficients of x(n):[.8 -.44 .36 .02]

enter the coefficients of y(n):[1 .7 -.45 -.6]

enter the desired length of impulse response:60

Department of Electronics 39 CAS Nattika


Digital Signal Processing Lab

y =

0.8000 -1.0000 1.4200 -0.9440 0.6998 -0.0627

-0.2076 0.5370 -0.5069 0.4719 -0.2363 0.0736

0.1253 -0.1964 0.2380 -0.1798 0.1151 -0.0187

-0.0430 0.0908 -0.0941 0.0809 -0.0445 0.0111

0.0207 -0.0362 0.0414 -0.0328 0.0198 -0.0038

-0.0081 0.0158 -0.0170 0.0142 -0.0081 0.0018

0.0036 -0.0065 0.0073 -0.0059 0.0035 -0.0007

-0.0015 0.0028 -0.0030 0.0025 -0.0015 0.0003

0.0006 -0.0012 0.0013 -0.0011 0.0006 -0.0001

-0.0003 0.0005 -0.0005 0.0004 -0.0003 0.0001

OBSERVATION 2:

enter the coefficients of x(n):[1 .4]

enter the coefficients of y(n):[1 -.5 .25]

enter the desired length of impulse response:50

y =

1.0000 0.9000 0.2000 -0.1250 -0.1125 -0.0250

0.0156 0.0141 0.0031 -0.0020 -0.0018 -0.0004

0.0002 0.0002 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000

0.0000 0.0000

Department of Electronics 40 CAS Nattika


Digital Signal Processing Lab

OUTPUT 1

Department of Electronics 41 CAS Nattika


Digital Signal Processing Lab

OUTPUT 2

RESULT

Impulse responses are obtained for the given systems and plotted.

Department of Electronics 42 CAS Nattika


Digital Signal Processing Lab

Prog.No:13
08-03-2024

IMPULSE RESPONSE FROM TRANSFER FUNCTION

AIM
Obtain the impulse response of the following LTI system from transfer function and also
plot output of the system for step input.
y(n)-0.5y(n-1)+0.25y(n-2) = x(n)+0.4x(n-1)

THEORY
The impulse response of an LTI system is its response to an impulse. In MATLAB, the
function [h,t] = impz (b, a) can be used to find the impulse response from transfer function.
b and a are the coefficients of x(n) and y(n) respectively. Also output of the system for step input
can be obtained from convolution of input and impulse response.

Given y(n)-0.5y(n-1)+0.25y(n-2) = x(n)+0.4x(n-1)


Taking Z transform on both sides, we get

Y(Z)-0.5Z-1Y(Z)+0.25Z-2Y(Z) = X(Z)+0.4Z-1X(Z)
Y(Z) [1-0.5Z-1+0.25Z-2] = X(Z) [1+0.4Z-1]
Y(Z) / X(Z) = [1+0.4Z-1] / [ 1-0.5Z-1+0.25Z-2]

We know transfer function H(Z) =Y(Z) / X(Z)

ie, H(Z) = [1+0.4Z-1] / [ 1-0.5Z-1+0.25Z-2]

PROGRAM
clc
clear all
close all

%GENERATION OF IMPULSE RESPONSE

b=input('enter the coefficients of x(n):')


a=input('enter the coefficients of y(n):')
[h,t]=impz(b,a)
subplot(3,1,1)
stem(t,h)
xlabel('n')
ylabel('h(n)')
title('Impulse Response')

Department of Electronics 43 CAS Nattika


Digital Signal Processing Lab

%GENERATION OF STEP INPUT

x=ones(size(t))
subplot(3,1,2)
stem(t,x)
xlabel('n')
ylabel('x(n)')
title('Step Input')

%GENERATION OF OUTPUT THROUGH CONVOLUTION

y=conv(x,h)
n=0:length(y)-1
subplot(3,1,3)
stem(n,y)
xlabel('n')
ylabel('x(n)*h(n)')
title('Output of the System for Step Input')

OBSERVATION:

enter the coefficients of x(n): [1 .4]

enter the coefficients of y(n): [1 -.5 .25]

Department of Electronics 44 CAS Nattika


Digital Signal Processing Lab

h = y =

1.0000 1.0000

0.9000 1.9000

0.2000 2.1000

-0.1250 1.9750

-0.1125 1.8625

-0.0250 1.8375

0.0156 1.8531

0.0141 1.8672

0.0031 1.8703

-0.0020 1.8684

-0.0018 1.8666

-0.0004 1.8662

0.0002 1.8665

0.0002 1.8667

0.8667

-0.0333

-0.2333

-0.1083

0.0042

0.0292

0.0135

-0.0005

-0.0036

-0.0017

0.0001

0.0005

0.0002

Department of Electronics 45 CAS Nattika


Digital Signal Processing Lab

OUTPUT

RESULT
Impulse response and output of the system are obtained and plotted.

Department of Electronics 46 CAS Nattika


Digital Signal Processing Lab

Prog.No:14
15-03-2024

DFT AND IDFT

AIM
Compute the N point DFT for a given sequence x(n), plot the amplitude and phase spectrum and
obtain the IDFT.

THEORY
DFT stands for Discrete Fourier Transform. It has been developed to convert a continuous function
of ω into a discrete function of ω, so that frequency analysis of discrete time signals can be performed on a
digital system. Generally DFT is defined along with number of samples and is called N point DFT.
N point DFT of x(n) is defined as
𝑵−𝟏
X(k) = ∑𝒏=𝟎 𝐱(𝐧)e-j2πkn/N for k=0,1,2,------,N-1

The plot of |X(k)| versus k is called magnitude spectrum and plot of ∠X(k) versus k is called phase
spectrum.

Conversely x(n) is obtained by finding inverse DFT (IDFT) of X(k).


𝐍−𝟏
ie, x(n) = 𝟏/𝑵 ∑𝒌=𝟎 𝐗(𝐤)ej2πkn/N for n=0,1,2,------,N-1

In MATLAB functions fft (x,N) and ifft (X,N) are used for finding DFT and IDFT of a sequence x(n).
Magnitude and phase spectrum of the DFT sequence are obtained using functions abs and angle
respectively.

PROGRAM
clc
clear all
close all

%INPUT DATA
x=input('enter the sequence:')
N=input('enter the N point value:')
n=0:N-1
%GENERATION OF DFT
X=fft(x,N)

Department of Electronics 47 CAS Nattika


Digital Signal Processing Lab

%PLOTTING MAGNITUDE SPECTRUM & PHASE SPECTRUM

mag=abs(X)
subplot(3,1,1)
stem(n,mag)
xlabel('k')
ylabel('|X(k)|')
title('magnitude spectrum of X(k)')
pha=angle(X)
subplot (3,1,2)
stem(n,pha)
xlabel('k')
ylabel('<X(k)')
title('phase spectrum of X(k)')

%GENERATION OF IDFT
x1=ifft(X,N)

%PLOTTING OF INVERSEOF IDFT


subplot(3,1,3)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('inverse of x(k)')

OBSERVATION 1:

enter the sequence:[.33 .33 .33]

enter the N point value:4

X =
0.9900 0 - 0.3300i 0.3300 0 + 0.3300i

mag =
0.9900 0.3300 0.3300 0.3300

00 0.330.3300

Department of Electronics 48 CAS Nattika


Digital Signal Processing Lab

phase =

0 -1.5708 0 1.5708

x1 =

0.3300 0.3300 0.3300 -0.0000

OBSERVATION 2:

enter the sequence:[2 2 2 2 1 1 1 1]

enter the N point value:8

X =

12.0000 1.0000 - 2.4142i 0 1.0000 - 0.4142i 0

1.0000 + 0.4142i 0 1.0000 + 2.4142i

mag =

12.0000 2.6131 0 1.0824 0 1.0824 0

2.6131

phase =

0 -1.1781 0 -0.3927 0 0.3927 0

1.1781

x1 =

2 2 2 2 1 1 1 1

Department of Electronics 49 CAS Nattika


Digital Signal Processing Lab

OUTPUT 1

Department of Electronics 50 CAS Nattika


Digital Signal Processing Lab

OUTPUT 2

RESULT

DFT and IDFT of the given sequences are computed and plotted the graphs.

Department of Electronics 51 CAS Nattika


15-03-2024

You might also like