You are on page 1of 153

DIGITAL SIGNAL PROCESSING

Digital Signal
Processing Lab

FAMILIARIZATION OF MATLAB

Department of Electronics 2
CAS,calicut
Digital Signal
Processing Lab

MATLAB BASICS

MATLAB is an interactive program for doing matrix calculations and has now
grown to a high level mathematical language that can solve integrals and differential
equations numerically and plot a wide variety of two and three dimensional graphs.

A) Definition of Variables

Variables are assigned numerical values by typing the expression directly. The
answer will not be displayed when a semicolon is put at the end of an expression.

MATLAB utilizes the following arithmetic operators:


+ - Addition
- - Subtraction
* - Multiplication
/ - Division
^ - Power operator
' - Transpose

A variable can be assigned using a formula that utilizes these operators and
either numbers or previously defined variables. To determine the value of a previously
defined quantity, type the quantity by itself. If your expression does not fit on one line,
use an ellipsis (three or more periods at the end of the line) and continue on the next
line. There are several predefined variables which can be used at any time, in the same
manner as user defined variables:
i - sqrt(-1)
j - sqrt(-1)
pi - 3.1416...
There are also a number of predefined functions that can be used when defining
a variable. Some common functions that are used in this text are:
abs - magnitude of a number (absolute value for real numbers)
angle - angle of a complex number, in radians
cos - cosine function, assumes argument is in radians
sin - sine function, assumes argument is in radians
exp - exponential function(can be used on complex numbers).

B) Definition of Matrices

MATLAB is based on matrix and vector algebra; even scalars are treated as 1x1
matrices. Therefore, vector and matrix operations are as simple as common calculator
operations.

Department of Electronics 3
CAS,calicut
Digital Signal
Processing Lab
Vectors can be defined in two ways. The first method is used for arbitrary
elements.
v = [1 3 5 7];

creates a 1x4 vector with elements 1, 3, 5 and 7. Note that commas could have been
used in place of spaces to separate the elements. Additional elements can be added to
the vector,
v(5) = 8;
yields the vector v = [1 3 5 7 8]. Previously defined vectors can be used to define a new
vector.

The second method is used for creating vectors with equally spaced elements.
t = 0:0.1:10;
creates a 1x11 vector with the elements 0, .1, .2, .3,..., 10. Note that the middle number
defines the increment. If only two numbers are given, then the increment is set to a
default of 1.
k = 0:10;
creates a 1x11 vector with the elements 0, 1, 2, ..., 10.Matrices are defined by entering
the elements row by row.
M = [1 2 4; 3 6 8];
creates the matrix
M = [1 2 4]
[3 6 8]

There are a number of special matrices that can be defined as follows.


Null matrix: M = [ ];
nxm matrix of zeros: M = zeros(n,m);
nxm matrix of ones: M = ones(n,m);
nxn identity matrix: M = eye(n);

A particular element of a matrix can be assigned as,


M (1, 2) = 5;
places the number 5 in the first row, second column. Operations and functions that were
defined for scalars in the previous section can also be used on vectors and matrices.

Functions are applied element by element. For example,


t = 0:10;
x = cos(2*t);
creates a vector x with elements equal to cos(2t) for t = 0, 1, 2, ..., 10.

Operations that need to be performed element-by-element can be accomplished


by preceding the operation by a ".". For example, to obtain a vector x that contains the
elements of x(t) = tcos(t) at specific points in time, you cannot simply multiply the
vector t with the vector cos(t). Instead you multiply their elements together:
t = 0:10;
x = t.*cos(t);
Department of Electronics 4
CAS,calicut
Digital Signal
Processing Lab

C) General Information

MATLAB is case sensitive so "a" and "A" are two different names. Comment
statements are preceded by a "%". On-line help for MATLAB can be reached by typing
help for the full menu or typing help followed by a particular function name or M-file
name. For example, help cos gives help on the cosine function.

The number of digits displayed is not related to the accuracy. To change the
format of the display, type format short e for scientific notation with 5 decimal places,
format long e for scientific notation with 15 significant decimal places and format bank
for placing two significant digits to the right of the decimal.

The commands who and whos give the names of the variables that have been
defined in the workspace. The command length(x) returns the length of a vector x and
size(x) returns the dimension of the matrix x.

D) M-files

M-files are macros of MATLAB commands that are stored as ordinary text files
with the extension "m", that is filename.m. An M-file can be either a function with
input and output variables or a list of commands.

The following describes the use of M-files on a PC version of MATLAB.


MATLAB requires that the M-file must be stored either in the working directory or in a
directory that is specified in the MATLAB path list. For example, consider using
MATLAB on a PC with a user-defined M-file stored in a directory called
"\MATLAB\MFILES". Then to access that M-file, either changes the working directory
by typing cd\matlab\mfiles from within the MATLAB command window or by adding
the directory to the path. Permanent addition to the path is accomplished by editing
the \MATLAB\matlabrc.m file, while temporary modification to the path is
accomplished by typing addpath c:\matlab\mfiles from within MATLAB.

MATLAB M-files are most efficient when written in a way that utilizes matrix
or vector operations. Loops and if statements are available, but should be used
sparingly since they are computationally inefficient. An if statement can be used to
define conditional statements.

The allowable comparisons between expressions are >=, <=, <, >, ==, and ~=.
Suppose that you want to run an M-file with different values of a variable T. The
following command line within the M-file defines the value.
T = input ('Input the value of T: ')
Whatever comment is between the quotation marks are displayed to the screen
when the M-file is running, and the user must enter an appropriate value.

Department of Electronics 5
CAS,calicut
Digital Signal
Processing Lab

HOW TO GET STARTED

Double click on icon for MATLAB 6.5. 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) there names should
be listed here.
Department of Electronics 6
CAS,calicut
Digital Signal
Processing Lab
• Command History – This is 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 to re-run it.

To begin to use MATLAB, click New:M-file from the File menu. 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 7
CAS,calicut
Digital Signal
Processing Lab

The out put data appears in Command Window.

Department of Electronics 8
CAS,calicut
Digital Signal
Processing Lab

Department of Electronics 9
CAS,calicut
Digital Signal
Processing Lab

DISCRETE TIME SIGNALS

DISCRETE TIME SIGNALS


Department of Electronics 10
CAS,calicut
Digital Signal
Processing Lab

A discrete time signal, x(n),is a function of an independent variable where the


independent variable is an integer. A discrete time signal is not defined at instants
between two successive samples. Also, x(n) is not equal to zero if n is not an integer.
Simply the signal x(n) is not defined for non-integer values of n. A discrete time signal
is defined for every integer value of n in the range – ∞ < n < ∞. Since a discrete time
signal is represented by a set of numbers it is also called a sequence.

Some elementary discrete-time signals

1. Digital impulse signal or unit sample sequence

The unit sample sequence is denoted as ∂(n) and is defined as

∂(n) =1 for n = 0
0 for n ≠ 0

In words, unit sample sequence is a signal that is zero everywhere, except at


n=0 where its value is unity. This signal is sometimes referred to as a unit impulse.

Delayed impulse ∂1(n) = ∂(n-d) = 1 for n = d


0 for n ≠ d

2. Unit step signal

The unit step signal is denoted as u(n) and is defined as

u(n) =1 for n ≥ 0
0 for n < 0

Department of Electronics 11
CAS,calicut
Digital Signal
Processing Lab

3. Ramp signal

The unit ramp signal is denoted as ur(n) and is denoted as

ur(n)=n for n ≥ 0
0 for n < 0

4. Exponential signal

The exponential signal is a sequence of the form

x(n) = an for all n

If the parameter a is real, then x(n) is a real signal. We can express x(n) for
various values of the parameter a.
If the parameter a is complex valued, it can be expressed as

a = rejθ

where r and θ are now the parameters.

Department of Electronics 12
CAS,calicut
Digital Signal
Processing Lab

5. Sine signal

A discrete time sine signal may be expressed as

x(n) = A sin (ω n + θ) , - ∞ < n < ∞ …….. (1)

where n is an integer variable(called the sample number),


A is the amplitude of the signal,
ω is the frequency in radians per sample, and
θ is the phase in radians.
If instead of ω we use the frequency variable f defined by

ω ≡ 2π f

The relation (1) becomes

x(n) = A sin (2π f n + θ ) , - ∞ < n < ∞

The frequency f has dimensions of cycles per sample.

6. Cosine signal

A discrete time cosine signal may be expressed as

x(n) = A cos (ω n + θ) , - ∞ < n < ∞ …….. (2)

where n is an integer variable(called the sample number),


A is the amplitude of the signal,
ω is the frequency in radians per sample, and
θ is the phase in radians.
If instead of ω we use the frequency variable f defined by

ω ≡ 2π f

The relation (2) becomes

x(n) = A cos (2π f n + θ ) , - ∞ < n < ∞

The frequency f has dimensions of cycles per sample.

Department of Electronics 13
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 1 DISCRETE TIME SIGNALS-I


28-7-09

Aim

To write a program that plot unit step signal, unit impulse, ramp signals.

Program

clf;
%UNIT STEP SIGNAL
subplot(3,1,1);
x=[-10:10];
y=[zeros(1,10) 1 ones(1,10)];
stem(x,y);
xlabel(‘samples’);
ylable(‘amplitude’);
axis([-10,10,0,2]);
title(‘UNIT STEP’);

%
subplot(2,1,1)
x=[zeros(1,10) 1 zeros(1,10)];
n=[-10:10];
stem(n,x);
axis([-10,10,0,2]);
subplot(2,1,2)
x=[zeros(1,15) 1 zeros(1,5)];
n=[-10:10];
stem(n,x);
axis([-10,10,0,2]);

Department of Electronics 14
CAS,calicut
Digital Signal
Processing Lab

Output

Unit step
2

1.5
amplitude

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
samples
unit step shifted by 5 unit
2

1.5
amplitude

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
samples

Result

The unit step signal and delaying unit step signal are plotted.

Department of Electronics 15
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 2 UNIT IMPULSE SIGNAL


28-10-08

Aim

To write a program that plot unit impulse signal and delayed unit impulse signal

Program

clf;

Department of Electronics 16
CAS,calicut
Digital Signal
Processing Lab

Output

Unit impulse
2

1.5
amplitude

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
samples
Unit impulse shifted by 5 unit
2

1.5
Amplitude

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
Samples

Result

The unit impulse signal and delayed unit impulse signal are plotted.

Department of Electronics 17
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 3 RAMP SIGNAL AND TRIANGLE WAVE


28-10-08

Aim

To plot a) ramp signal


b) triangular wave
c) modified triangular wave.

Program

clf;
subplot(3,1,1);
n=[0:60];
stem(n,n);
axis([0,60,0,60]);
subplot(3,1,2);
y=[0:1:20 19:-1:0 -1:-1:-20 -19:1:0];
n=[0:80]
stem(n,y);
axis([0,80,-20,20]);
subplot(3,1,3);
y=[zeros(1,10) 1:1:10 9:-1:0 zeros(1,10) -1:-1:-10 -9:1:0 zeros(1,11)];
n=[0:70];
stem(n,y);
axis([0,70,-15,15]);

Department of Electronics 18
CAS,calicut
Digital Signal
Processing Lab

Output

Ramp signal
60
Amplitude

40

20

0
0 10 20 30 40 50 Samples60
Triangular wave
20
Amplitude

-20
0 10 20 30 40 50 60 70 80
Modified triangular wave Samples
10
Amplitude

-10

0 10 20 30 40 50 60 70
Samples

Result

The ramp signal, triangular wave and modified triangular wave are plotted.

Department of Electronics 19
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 4 SINE AND COSINE WAVES


31-10-08

Aim

To plot a) sine wave


b) cosine wave

Program

clf;
subplot(2,1,1);
a=10;
f=0.02;
n=[0:80];
y=a*sin(2*3.14*f*n);
stem(n,y);
axis([0,80,-20,20]);
subplot(2,1,2);
a=10;
f=0.02;
n=[0:80];
y=a*cos(2*3.14*f*n);
stem(n,y);
axis([0,80,-20,20]);

Department of Electronics 20
CAS,calicut
Digital Signal
Processing Lab

Output

Sine wave
20

10
Amplitude

-10

-20
0 10 20 30 40 50 60 70 80
Samples
Cosine wave
20

10
Amplitude

-10

-20
0 10 20 30 40 50 60 70 80
Samples

Result

The sine wave and cosine wave are plotted.

Department of Electronics 21
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 5 EXPONENTIAL SIGNAL


31-10-08

Aim

To plot a)exponential signal,a=0.8


b)exponential signal,a=1.1

Program

clf;
subplot(2,1,1);
a=0.8;
n=[0:15];
y=a.^n;
stem(n,y);
axis([0,15,0,1]);
subplot(2,1,2);
a=1.1;
n=[0:50];
y=a.^n;
stem(n,y);
axis([0,42,0,50]);

Department of Electronics 22
CAS,calicut
Digital Signal
Processing Lab

Output

Exponential signal with a=0.8


1

0.8
Amplitude

0.6

0.4

0.2

0
0 5 10 Samples 15
Exponential signal with a=1.1
50

40
amplitude

30

20

10

0
0 5 10 15 20 25 30 35 40
Samples

Result

The exponential signals are plotted.

Department of Electronics 23
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 3 AMPLITUDE MODULATION


31-7-09

Aim

To plot a)message wave


b)carrier wave
c)modulated wave for m=1,m<1 and m>1.
Program

clf;
subplot(5,1,1);
a=10;
f=0.1;
n=[0:500];
ya=a*cos(2*3.14*f*n);
plot(n,ya);
axis([0,500,-20,20]);
subplot(5,1,2);
a=10;
f=0.01;
n=[0:500];
yb=a*cos(2*3.14*f*n);
plot(n,yb);
axis([0,500,-20,20])
subplot(5,1,3);
m=1;
am=10;
n=[0:500];
y=(1+(m/am).*yb).*ya;
plot(n,y);
axis([0,500,-20,20])
subplot(5,1,4);
m=2;
am=10;
n=[0:500];
y=(1+(m/am).*yb).*ya;
plot(n,y);
axis([0,500,-20,20])
subplot(5,1,5);
m=.5;
am=10;
n=[0:500];
y=(1+(m/am).*yb).*ya;
plot(n,y);
axis([0,500,-20,20])

Department of Electronics 24
CAS,calicut
Digital Signal
Processing Lab

Output

Carrier siginal
20
Amplitude

-20
Message siginal 0 50 100 150 200 250 300 350 400 450 500
20 Time
Amplitude

-20
AM wave m=1 0 50 100 150 200 250 300 350 400 450 500
20 Time
Amplitude

-20
AM wave m>1 0 50 100 150 200 250 300 350 400 450 500
20 Time
Amplitude

-20
0 50 100 150 200 250 300 350 400 450 500
AM wave m<1 20
Time
Amplitude

-20
0 50 100 150 200 250 300 350 400 450 500
Time

Result

The a)message wave


b)carrier wave
c)modulated wave for m=1,m<1 and m>1 are plotted.

Department of Electronics 25
CAS,calicut
Digital Signal
Processing Lab

DISCRETE TIME SYSTEMS

Department of Electronics 26
CAS,calicut
Digital Signal
Processing Lab

DISCRETE TIME SYSTEMS

A discrete time system is a device or algorithm that operates on a discrete time


signal, called the input or excitation, to produce another discrete time signal called the
output or the response of the system. The input signal x(n) is transformed by the system
into a signal y(n) , and expressed as

y(n) = H[x(n)]
where H denotes the transformation (also called an operator) .

The input-output description of a discrete time system consists of mathematical


expression or a rule, which explicitly defines the relation between the input and output
signals. The input-output relationship of an LTI system can be expressed by Nth order
constant coefficient difference equation.

N M
y(n) = - ∑ ak y(n-k) + ∑ bk x(n-k) …… (1)
k =1 k =0

The integer N is called the order of the system. Here y(n-k) are past outputs,
x(n-k) are past inputs, x(n) is present input and ak and bk are constant coefficients .
The transfer function of the LTI system is defined as the ratio of z-transform of output
to z-transform of input. On taking z-transform of equation (1) we get

M −k
∑ bk z
Y (z) k =0
= ….. (2)
X (z) N
1+ ∑ ak z − k
k =1

The equation (2) is the transfer function of the LTI system. The numerator and
the denominator of the transfer function are polynomials of z. The roots of the
numerator polynomial are zeros of the LTI system and the roots of the denominator
polynomial are poles of the LTI system.

Classification of discrete time systems

The discrete time systems are classified based on their characteristics. Some of
the classifications of discrete time systems are,

1. Linear and Nonlinear systems.


2. Causal And Noncausal systems.
3. Time variant and time invariant systems.

Department of Electronics 27
CAS,calicut
Digital Signal
Processing Lab
4. Stable and unstable systems.
5. Static and dynamic systems.
6. FIR and IIR systems.
7. Recursive and non recursive systems

1. Linear and non linear systems

A linear system is one that satisfies the superposition principle. The principle of
superposition requires that the response of the system to a weighted sum of the signals
is equal to the corresponding weighted sum of the responses of the system to each of
the individual input signals.

Let y1(n) = H[x1(n)] and y2(n) = H[x2(n)]


Suppose we have a signal
x3(n) = a1x1(n) + a2x2(n)
and let y3(n) = H[x3(n)] = H[a1x1(n) + a2x2(n)]
The principle of superposition requires that
y3(n) = a1y1(n) + a2y2(n) = a1H[x1(n)] + a2H[x2(n)].

Definition:

A relaxed system H is linear if

H[a1x1(n) + a2x2(n)] = a1H[x1(n)] + a2H[x2(n)]

for any arbitrary input sequences x1(n) and x2(n) and for any arbitrary constants a1 and
a2. If a relaxed system does not satisfy the superposition principle as given by the above
definition, the system is non linear.

2. Causal and non causal systems

Definition:

A system is said to be causal if the output of the system at any time n depends
only on the present input, past inputs and past outputs but does not depend on future
inputs and outputs.

If the system output at any time n depends on future inputs or outputs then the
system is called non causal system.

The causality refers to a system that is realizable in real time. It can be shown
that a LTI is causal if and only if the impulse response is zero for n<0, (i.e., h(n)=0 for
n<0).
Let x(n)=present input and y(n)=present output

∴ x(n-1),x(n-2),…are past inputs

y(n-1),y(n-2),…are past outputs

Department of Electronics 28
CAS,calicut
Digital Signal
Processing Lab
In mathematical terms the output of a causal system satisfies the equation of the form

y(n)=F[x(n), x(n-1), x(n-2),…, y(n-1), y(n-2),…],

where F[.] is some arbitrary function.

3. Time invariant and time variant systems

A system is said to be time invariant if its input-output characteristics do not


change with time.

Definition:

A relaxed system H is time invariant if and only if


x (n) → y(n) implies that , x(n-k) → y(n-k)

For every input signal x(n) and every time shift k.


(i.e., in time invariant systems, if y(n) = H[x(n)] then y(n-k) = H[x (n-k)].)

Alternative definition for time invariance

A system H is time invariant if the response to a shifted version of the input is


identical to a shifted version of the response based on the unshifted input. i.e., in a time
invariant system, H[x (n-k)] = z-k H[x (n)] for all values of k. The operator z-k represents
a signal delay of k samples.

Testing for time invariance

Let, H[x (n-k)] = y(n-k); H[x(n)] = y(n); z-k H[x(n)] = y`(n-k)

where, y(n-k) =response of the system for the shifted input


y(n) = response of the system for the unshifted input
y`(n-k)=shifted version of the response based on unshifted input.

A system can be tested for time invariance using the following procedure:

1. Delay the input signal by k units of time and determine the response of the
system for this delayed input signal. Let this response be y(n-k).

2. Delay the response of the system for unshifted input by k units of time. Let
this delayed response be y`(n-k).

3. Check whether y(n-k) = y`(n-k).If they are equal then the system is time
invariant. Otherwise the system is time variant.

4. Stable and unstable systems

Definition:

Department of Electronics 29
CAS,calicut
Digital Signal
Processing Lab
An arbitrary relaxed system is said to be Bounded Input-Bounded Output
(BIBO) stable if and only if every bounded input produces a bounded output.

If x(n) is bounded, there exists a constant Mx such that │x(n)│≤ Mx< ∞; for all
n. Similarly, if the output is bounded, there exists a constant My such that │y (n) │≤ My
< ∞; for all n.


By convolution sum formula, y(n)= ∑
k =−∞
h(k) x(n-k) ….. (1)

Taking absolute values on both sides of equation (1) we get,


∞ ∞
│y(n)│= │ ∑
k =−∞
h(k) x(n-k) │ = ∑
k =−∞
│h(k)││x(n-k)│ ….. (2)

If the input is bounded then │x(n-k)│ = Mx. Hence equation (2) can be written
as,
∞ ∞
│y(n)│ = ∑
k =−∞
│h(k)│ Mx = Mx ∑
k =−∞
│h(k)│ ….. (3)

Form equation (3) we can say that the output is bounded if the impulse response
of the system satisfies the condition


k =−∞
│h(k)│ < ∞

i.e., an LTI system is stable if the impulse response is absolutely summable.

5. Static and dynamic systems

A discrete time system is static or memory less if its output at any instant n
depends at most on the input sample at the same time but not on past or future samples
of the input. In any other case the system is said to be dynamic or to have memory.

6. FIR and IIR systems

In FIR (Finite duration Impulse Response) systems, the impulse response


consists of finite number of samples. The convolution formula for FIR system is given
by,
N −1
y (n)= ∑ h (k) x(n-k)
k =0

where h (n) = 0;n < 0 and n ≥ N ….. (1)

From equation (1) it can be concluded that the impulse response selects only N
samples of the input signal.

Department of Electronics 30
CAS,calicut
Digital Signal
Processing Lab
In effect, the system acts as a window that views only the most recent N input
signal samples in forming the output. It neglects or simply forgets all prior input
samples. Thus a FIR system has a finite memory of length N samples.

In general, a FIR system is described by the difference equation,

N −1
y(n)= ∑ bk x(n-k)
k =0

In IIR (Infinite duration Impulse Response) systems the impulse response has
finite number of samples. The convolution formula for IIR systems is given by,


y(n)= ∑ h(k) x(n-k)
k =0

Since this weighted sum involves the present and all the past input samples, the
system has an infinite memory.

In general, an IIR system is described by the difference equation,

N M
y(n)= - ∑ ak y(n-k) + ∑ bk x(n-k)
k =1 k =1

7. Recursive and non-recursive systems

A system whose output y (n) at time n depends on any number of past output
values is called a recursive system. The past outputs are y(n-1), y(n-2), y(n-3), …
Hence for recursive system, the output, y(n) is given by,

y(n)=F[y(n-1), y(n-2), …, y(n-N), x(n), x(n-1), …, x(n-M)]

A system whose output depends only on the present and past input is called a
non-recursive system. Hence for non recursive system, the output, y(n) is given by

y(n)=F[x(n), x(n-1), …, x(n-M)]

In recursive system, in order to compute y(n0), we need to compute all the


values y(0), y(1), …, y(n0-1) before calculating y(n0-1). Hence the output of a recursive
system has to be computed in order [i.e., y(0), y(1), y(2), …].

In non-recursive system, y(n0) can be computed immediately without having


y(n0-1), y(n0-2) … . Hence the output of non-recursive system can be computed in any
order [i.e., y(50), y(5), y(2), y(100), …].

Department of Electronics 31
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 4 REALIZATION OF A DISCRETE TIME SYSTEM


5-8-09
Aim

To write a program to realize a discrete time system

Program

clf;
subplot(4,1,1);
a=10;
f=0.02;
n=[0:80];
y1=a*sin(2*3.14*f*n);
plot(n,y1);
axis([0,80,-20,20]);
subplot(4,1,2);
a=10;
y2=a*rand(1,81);
plot(n,y2);
axis([0,80,-12,12]);
subplot(4,1,3);
y3=y1+y2;
plot(n,y3);
axis([0,80,-25,25]);
subplot(4,1,4);
xco=ones(1,15);
yco=1;
y4=filter(xco,yco,y3)/10
plot(n,y4);
axis([0,80,-30,30]);

Department of Electronics 32
CAS,calicut
Digital Signal
Processing Lab

Output

Input siginal Y1(n)


20
Amplitude

-20
0 10 20 30 40 50 60 70 Time 80
Input siginal Y2(n)
10
Amplitude

-10
0 10 20 30 40 50 60 70 Time 80
Y3(n)=Y1(n)+Y2(n)
20
Amplitude

-20
0 10 20 30 40 50 60 70 Time 80
Filtered siginal
20
Amplitude

-20
0 10 20 30 40 50 60 70 Time 80

Result

The discrete time system is realized.

Department of Electronics 33
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 5 REALIZATION OF A NON – CAUSAL SYSTEM


5-8-09

Aim
To write a program to realize the system described by the equation,
y(n)= x2(n) + x(n-1) ∗ x(n+1)
Program
clf;
n=[0:4];
x=[1 2 3 4 5];
subplot(5,1,1);
a=10;
f=0.02;
n=[0:6];
x1=[0 x 0];
stem(n,x1);
axis([-2,7,0,8]);
subplot(5,1,2);
a=10;
f=0.02;
n=[0:6];
x2=[0 0 x];
stem(n,x2)
axis([-2,7,0,8]);
subplot(5,1,3);
a=10;
f=0.02;
n=[0:6];
x3=[x 0 0];
stem(n,x3)
axis([-2,7,0,8]);
subplot(5,1,4);
a=10;
f=0.02;
n=[0:6];
x4=(x1).^2;
Department of Electronics 34
CAS,calicut
Digital Signal
Processing Lab
stem(n,x4)
axis([-2,7,0,25]);
subplot(5,1,5);
a=10;
f=0.02;
n=[0:6];
x5=x4+(x2.*x3);
stem(n,x5)
axis([-2,7,0,40]);

Output

X(n)
5
Amplitude

0
-2 -1 0 1 2 X(n-1) 3 4 5 6 7
Time
Amplitude

0
-2 -1 0 1 2 X(n+1) 3 4 5 6 7
Time
Amplitude

0
-2 -1 0 1 2 X2(n) 3 4 5 6 7
20
Amplitude

10

0
-2 -1 0 1 Y(n)=X2(n)+X(n-1)*X(n+1)
2 3 4 5 6 7
40
Amplitude

20

0
-2 -1 0 1 2 3 4 5 6 7
Time

Result

The given non causal system is realized.

Department of Electronics 35
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 6 CHECKING FOR LINEARITY-I


7-08-09

Aim

To write a program to check the system described by the equation,


y(n) = x(n) - 0.4x(n-1) + 0.2x(n-2) - 0.6x(n-3) + 0.1y(n-1) - 0.5y(n-2)
is a linear system. Inputs are a random signal and a sine wave.

Program

clf;
a=10;
f=0.02;
n=[0:80];
y1=a*sin(2*3.14*f*n);
xco=[1 -0.4 0.2 0.6];
yco=[1 -0.1 0.5];
y2=filter(xco,yco,y1)/5;
subplot(5,2,1);
a1=2;
y3=a1.*y2;
plot(n,y3);
axis([0,80,-20,20]);
subplot(5,2,2);
a=10;
y4=a*rand(1,81);
y5=filter(xco,yco,y4)/5;
a2=3;
y6=a2.*y5;
plot(n,y6);
axis([0,80,-20,20]);
subplot(5,1,3);
y7=y6+y3;
Department of Electronics 36
CAS,calicut
Digital Signal
Processing Lab
plot(n,y7);
axis([0,80,-20,20]);
subplot(5,2,4);
y8=[a1.*y1+a2.*y4];
plot(n,y8);
subplot(5,1,5);
y9=filter(xco,yco,y8)/5;
plot(n,y9);
axis([0,80,-20,20]);

Output

a1H[x1(n)] a2H[x2(n)]
20 20
Amplitude

Amplitude

0 0

-20 -20
0 20 40 60 Time80 0 20 40 60 80
Time
[a1x1(n)+a2x2(n)]
20
Amplitude

-20
0 20 40 60 80
Time a1H[x1(n)]+a2H[x2(n)]=LHS
50
Amplitude

-50
0 10 20 30 40 50 60 70 Time 80
H[a1x1(n)+a2x2(n)]=RHS
20
Amplitude

-20
0 10 20 30 40 50 60 70 80
Time

Result

The given system is realized. The system is linear.

Department of Electronics 37
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 7 CHECKING FOR LINEARITY-II


12-08-09

Aim

To write a program to check the system described by the equation y(n)= x2(n) is
a linear system.

Program

clf;
subplot(4,1,1);
a=2;
f=0.02;
n=[0:80];
y1=a*sin(2*3.14*f*n);
a1=2;
y2=a1.*y1;
plot(n,y2);
axis([0,80,-20,20]);

subplot(4,1,2);
a=2;
y3=a*rand(1,81);
a2=3;
y4=a2.*y3;
plot(n,y4);
axis([0,80,-20,20]);

subplot(4,1,3);
y5=y2+y4;
y6=(y5).^2;
plot(n,y6);
Department of Electronics 38
CAS,calicut
Digital Signal
Processing Lab
axis([0,80,0,40]);

subplot(4,1,4);
y7=y1.^2;
y8=a1.*y7;
y9=y3.^2;
y10=a2.*y9;
y11=y8+y10;
plot(n,y11);
axis([0,80,0,40]);

Output

a1x1(n)
20
Amplitude

-20
0 10 20 30 40 50 60 70 Time 80
a2x2(n)
20
Amplitude

-20
0 10 20 30 40 50 60 70 Time 80
[a1x1(n)+a2x2(n)]2
40
Amplitude

20

0
0 10 20 30 40 50 60 70 Time 80
[a1x12(n)+a2x22(n)]
40
Amplitude

20

0
0 10 20 30 40 50 60 70 Time 80

Result

The given system is realized. The system is non-linear.

Department of Electronics 39
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 8 CHECKING FOR TIME INVARIANCE – I


12-08-09

Aim

To write a program to check a given system is whether time invariant or not.


y(n)= x(n) - 0.46y(n-1) + 0.21y(n-2) + 0.635y(n-3) + x(n-1) - 0.5x(n-2)
be the differential equation of the system and the input be
x(n)= 0.5sin(2∗ π∗ 0.1∗n) - 0.3cos(2∗ π∗ 0.1∗n).

Program

clf;
subplot(5,2,1);
a=15;
f=0.1;
n=[0:80];
y1=[0.5*sin(2*3.14*0.1*n)]-[0.3*cos(2*3.14*0.1*n)];
plot(n,y1);
axis([0,80,-1,1]);

subplot(5,2,2);
xco=[1 1 -0.5];
yco=[1 0.41 -0.21 -0.635];
y2=filter(xco,yco,y1);
plot(n,y2);
axis([0,80,-1,1]);

subplot(5,2,3);
d=20;
n1=[0:80+d]
Department of Electronics 40
CAS,calicut
Digital Signal
Processing Lab
y3=[zeros(1,d) y2];
plot(n1,y3);
axis([0,80,-1,1]);

subplot(5,2,4);
y4=[zeros(1,d) y1];
plot(n1,y4);
axis([0,80,-1,1]);

subplot(5,2,5);
y5=filter(xco,yco,y4);
plot(n1,y5);
axis([0,80,-1,1]);

Output

X(n) Y(n)
1 1
Amplitude
Amplitude

0 0

-1 -1
0 20 40 60 80 0 20 40 60Time 80
Time

Y(n-d) X(n-d)
1 1
Amplitude

Amplitude

0 0
-1 -1
0 20 40 60 80 0 20 40 60 Time 80
Time

Filtered siginal X(n-d)


1
Amplitude

-1
0 20 40 60 80
Time

Result

Department of Electronics 41
CAS,calicut
Digital Signal
Processing Lab
The given system is realized. The system is time invariant.

Prog. No: 9 CHECKING FOR TIME INVARIANCE - II


14-08-09

Aim

To write a program to check the system is whether time invariant or not.


Let y(n) = n∗x(n) + x(n-1)
be the differential equation of the system and the input of the system be
x(n) = 0.5∗sin(2∗ π∗ 0.01∗n).
Program

clf;
subplot(3,2,1);
n=[0:80];
x=[0.5*sin(2*3.14*0.01*n)];
plot(n,x);
axis([0,80,0,1]);
subplot(3,2,2);
n1=[0:82];
x1=[0 x 0];
x2=[0 0 x]
y1=(n1.*x1)+x2;
plot(n1,y1);
axis([0,80,0,20]);
subplot(3,2,3);
d=20;
n2=[0:82+d];
y2=[zeros(1,d) y1];
plot(n2,y2);
Department of Electronics 42
CAS,calicut
Digital Signal
Processing Lab
axis([0,80,0,20]);
subplot(3,2,4);
d=20;
n3=[0:82+d]
y3=[zeros(1,d) y1];
plot(n3,y3);
axis([0,80,0,20]);
subplot(3,2,5);
n=[0:80+d];
x3=[zeros(1,d) x];
n1=[0:82+d];
x1=[0 x3 0];
x2=[0 0 x3]
y4=(n1.*x1)+x2;
plot(n1,y4);
axis([0,80,0,25]);

Output

X(n) Y(n)
1 20
Amplitude

Amplitude

0.5 10

0 0
0 20 40 60 Time80 0 20 40 60 Time80
Y(n-d) X(n-d)
20 20
Amplitude

Amplitude

10 10

0 0
0 20 40 60 Time 80 0 20 40 60 80
Y(n,d) Time
20
Amplitude

10

0
80 60 40 20 0
Time

Result
Department of Electronics 43
CAS,calicut
Digital Signal
Processing Lab

The given system is realized. The system is time variant.

Prog. No: 10 CHECKING FOR STABILITY - I


18-08-09

Aim

To write a program to check the following LTI system described by the


difference equation y(n) = x(n) + 0.8x(n-1) - y(n-1) - 1.5y(n-2) - 0.9y(n-3) is stable.

Program

clf;
n=[0:500];
xco=[1 0.8];
yco=[1 1 1.5 0.9];
h=impz(xco,yco,n);
stem(n,abs(h));
s=0;
for i=1:500
s=s+abs(h(i));
if abs(h(i))<10^(-6)
break
end
end
display(s);

Department of Electronics 44
CAS,calicut
Digital Signal
Processing Lab

Output

27 Impulse Response of Unstable system


x 10
3.5

2.5

2
amplitude

1.5

0.5

0
0 50 100 150 200 250 300 350 400 450 500
samples

Department of Electronics 45
CAS,calicut
Digital Signal
Processing Lab

Result

The impulse response of the given system is plotted. Since ∑ h(n) ≈ ∞, the
system is unstable.

Prog. No: 11 CHECKING FOR STABILITY - II


18-08-09

Aim
To write a program that check the following LTI system described by the
difference equation y(n) = x(n) - 0.8x(n-1) - y(n-1) - 0.9y(n-2) is stable.

Program

clf;
n=[0:500];
xco=[1 0.8];
yco=[1 1 0.9];
h=impz(xco,yco,n);
stem(n,abs(h));
s=0;
for i=1:500
s=s+abs(h(i));
if abs(h(i))<10^(-6)
break
end
end
display(s);

Department of Electronics 46
CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 47
CAS,calicut
Digital Signal
Processing Lab
Impulse Response of a Stable System
1

0.9

0.8

0.7

0.6
amplitude

0.5

0.4

0.3

0.2

0.1

0
0 50 100 150 200 250 300 350 400 450 500
samples

Result

The impulse response of the given system is plotted. Since ∑ h(n)< ∞, the
system is stable.

Department of Electronics 48
CAS,calicut
Digital Signal
Processing Lab

DISCRETE TIME FOURIER TRANSFORM

DISCRETE TIME FOURIER TRANSFORM


Department of Electronics 49
CAS,calicut
Digital Signal
Processing Lab

The Fourier Transform (FT) of discrete-time signals is called Discrete-Time


Fourier Transform (i.e., DTFT).

Let x(n) = Discrete-time signal


ω
X(ω ) or X(ej ) = Fourier Transform of x(n)

The Fourier Transform of a finite energy discrete time signal, x(n) is defined as

ω
X(ω ) = ∑ x(n) e-j n
n =−∞

The Fourier Transform of a signal is said to exist if it can be expressed in valid


functional form. Since the computation of Fourier Transform involves summing infinite
number of terms, the Fourier Transform exists only for the signals that are absolutely
summable, i.e., given a signal x(n), the X(ω ) exists only when


∑ | x(n) | < ∞
n =−∞

The Fourier Transform X(ω ) of a signal x(n) represents the frequency of x(n).
By taking Fourier Transform, the signal x(n) is decomposed into its frequency
components. Hence X(ω ) is also called Signal spectrum.

The difference between the Fourier Transform of a discrete time signal and
analog signal are given below.

1. The Fourier Transform of analog signals consists of a spectrum with a


frequency range - ∞ to + ∞ . But the Fourier Transform of discrete time
signal is unique in the frequency range -π to +π (or equivalently 0 to 2π ).
Also Fourier Transform of discrete time signals is periodic with period 2π .
Hence the frequency range for any discrete time signal is limited to -π to
+π (or 0 to 2π ) and any frequency outside this interval has an equivalent
frequency within this interval.

2. Since the analog signals are continuous the Fourier Transform of analog
signals involves integration but the Fourier Transform of discrete time
signals involves summation because the signals are discrete.

Inverse Fourier Transform

Let x(n) = Discrete time signal


X(ω ) = Fourier Transform of x(n)

Department of Electronics 50
CAS,calicut
Digital Signal
Processing Lab
The inverse Fourier Transform of X(ω ) is defined as,

Π
F {x(ω )} = x(n) =  π ∫
-1 ωn
X(ω ) ej dω
−Π

We also refer to x(n) and X(ω ) as a Fourier Transform pair and this relation is
expressed as
x(n)  F
→ X(ω )

A more useful method of determining the values of x(n) follows directly from
the definition of the Fourier Transform.
ωn ω ω ω ω
X(ω ) = Σ x(n) e-j = . . .+ x(-2) ej2 + x(-1) ej + x(0) e0 +x(1) e-j + x(2) e-j2 + . . .
….. (1)

From the defining equation of X(ω ) we can say that, if X(ω ) can be expressed
as a series of complex exponentials, as shown in equation (1) then x(n) is simply the
ω
coefficient of e-j n.

Properties:

1. Time-shifting property

If F{x(n)} = X(ω )
ω
then F{x(n-k)} = e-j k X(ω )
Also
ωk
F{x(n+k)} = ej X(ω )

This relation means that if a signal is shifted in time domain by k


samples, its magnitude spectrum remains unchanged. However, the phase
spectrum is changed by an amount –ω k. This result can be explained from the
fact that the frequency content of a signal depends only on its shape.
Mathematically, we can say that shifting by k units in time domain is equivalent
ω
to multiplying the spectrum by e-j k in the frequency spectrum.

2. Time-reversal property

If F{x(n)} = X(ω )
then F{x(-n)} = X(-ω )

If x(n) is real or imaginary then,


∠ ω ∠ ω
If F{x(-n}} = X(-ω ) = | X(-ω )| ej X(- ) = | X(ω )| e-j X( )

This means that if a signal is folded about the origin in time, its
magnitude spectrum remains unchanged and the phase spectrum undergoes a
change in sign (phase reversal).
Department of Electronics 51
CAS,calicut
Digital Signal
Processing Lab

3. Convolution theorem

If F{x(n)} = X(ω )
and F{h(n)} = H(ω )
then F{x(n)*h(n)} = X(ω ) H(ω )

The Fourier Transform convolution of x(n) and h(n) is equal to product


of X(ω ) and H(ω ). It means that if we convolve two signals in time domain, it
is equivalent to multiplying their spectra in frequency domain.

4. Frequency shifting

If F{x(n)} = X(ω )
ω
then F{ej 0n x(n)} = X(ω -ω 0)
ω 0n
According to this property the multiplication of a sequence x(n) by ej
is equivalent to a frequency translation of the spectrum X(ω ) by ω 0.

Department of Electronics 52
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 12 EVALUATION OF DTFT - I


19-08-09

Aim

To write a program that plot real, imaginary, magnitude and phase spectrum of
DTFT of input signal with numerator coefficient [2, 1] & denominator coefficient
[1 -0.6].

Program

clf;
yco=[1 -0.6];
xco=[2 1];
w=[-pi*4:pi/512:pi*4];
y=freqz(xco,yco,w);
subplot(4,1,1);
plot(w,real(y));
subplot(4,1,2);
plot(w,imag(y));
subplot(4,1,3);
plot(w,abs(y));
subplot(4,1,4);
plot(w,angle(y));

Department of Electronics 53
CAS,calicut
Digital Signal
Processing Lab

Output

Real Part of X(ejw )


10
amplitude

0
-15 -10 -5
Imaginary Part0 of X(ejw ) 5 10 frequency15
5
amplitude

-5
-15 -10 -5 0 5 10 frequency15
Magnitude Spectrum of X(e jw )
10
amplitude

0
-15 -10 -5 0 5 10 15
frequency
Phase Spectrum of X(ejw )
2
phase

-2
-15 -10 -5 0 5 10 frequency 15

Result

The DTFT of the given signal is found and its real part, imaginary part,
magnitude spectrum and phase spectrum are plotted.

Department of Electronics 54
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 13 EVALUATION OF DTFT - II


19-08-09

Aim

To write a program that plot the magnitude and phase spectrum of DTFT of the
following sequence,
a= [1 3 5 7 9 11 13 15 17].

Program

clf;
yco=1;
xco=[1 3 5 7 9 11 13 15 17];
w=[-pi*4:pi/512:pi*4];
y=freqz(xco,yco,w);
subplot(2,1,1);
plot(w,abs(y));
subplot(2,1,2);
plot(w,angle(y));

Department of Electronics 55
CAS,calicut
Digital Signal
Processing Lab

Output

Magnitude Spectrum of X(ejw )


100

80
amplitude

60

40

20

0
-15 -10 -5 0 5 10 15
frequency
Phase Spectrum of X(ejw )
4

2
phase

-2

-4
-15 -10 -5 0 5 10 15
frequency

Result

The DTFT of the given signal is found and it’s magnitude spectrum and phase
spectrum are plotted.

Department of Electronics 56
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 14 TIME SHIFTING PROPERTY OF DTFT


21-08-09

Aim

To write a program that verifies the time shifting property of DTFT. Input be
x (n) = [1 2 3 4 5 6 7 8 9].
y(n) =[1] .Delay = 10 units
Program

clf;
yco=1;
xco=[1 2 3 4 5 6 7 8 9];
w=[-pi*4:pi/512:pi*4];
y=freqz(xco,yco,w);
subplot(4,1,1);
plot(w,abs(y));
subplot(4,1,2);
plot(w,angle(y));
d=10;
x1=[zeros(1,d) xco];
w=[-pi*4:pi/512:pi*4];
y1=freqz(x1,yco,w);
subplot(4,1,3);
plot(w,abs(y1));
subplot(4,1,4);
plot(w,angle(y1));

Department of Electronics 57
CAS,calicut
Digital Signal
Processing Lab

Output

Phase Spectrum Of x1(n)*x2(n)


100
Amplitude

50

0
-15 -10 -5 0 5 10 Frequency15
Phase Spectrum of x1(n)*x2(n)
5
Phase

-5
-15 -10 -5 0 5 10frequency 15
Magnitude Spectrum of e -jw noY(ejw )
100
amplitude

50

0
-15 -10 -5 0 5 10 frequency 15
Phase Spectrum of e-jw n0Y(ejw )
5
phase

-5
-15 -10 -5 0 5 10frequency 15

Result

The time shifting property of DTFT is verified.


ω
F{x(n-10)} = ej 10 X(ω ).

Department of Electronics 58
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 15 CONVOLUTION PROPERTY OF DTFT


21-08-09

Aim

To write a program that verifies the convolution property of DTFT.


Given x1(n) = [1 2 3] and x2(n) = [2 3 4].

Program

clf;
a=[1 2 3];
b=[2 3 4];
c=conv(a,b);
yco=1;
w=[-pi*4:pi/512:pi*4];
y=freqz(c,yco,w);
subplot(4,1,1);
plot(w,abs(y));
subplot(4,1,2);
plot(w,angle(y));
y1=freqz(a,yco,w);
y2=freqz(b,yco,w);
y3=y1.*y2;
subplot(4,1,3);
plot(w,abs(y3));
subplot(4,1,4);
plot(w,angle(y3));

Department of Electronics 59
CAS,calicut
Digital Signal
Processing Lab

Output

Magnitude Spectrum Of x1(n)*x2(n)


100
Amplitude

50

0
-15 -10 -5 0 5 10 15
Phase Spectrum Of x1(n)x2(n) Frequency
5
Phase

-5
-15 -10 -5 0 5 10Frequency 15
Magnitude Spectrum Of X1(W)X2(W)
100
Amplitude

50

0
-15 -10 -5 0 5 10Frequency 15
Phase Spectrum Of X1(W)X2(W)
5
Phase

-5
15 10 5 0 -5 -10Frequency-15

Result

The convolution property of DTFT is verified.


F{x1(n) ∗ x2(n)} ↔ X1(ω ) X2(ω ).

Department of Electronics 60
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 16 FREQUENCY SHIFTING PROPERTY


28-08-09

Aim

To write a program that verifies the frequency shifting property of DTFT.


Let Xco = [1 2 3] and Yco = 1.

Program

clf;
n=[0:2]
a=[1 2 3];
yco=1;
w=[-pi*4:pi/512:pi*4];
y=freqz(a,yco,w);
subplot(4,1,1);
plot(w,abs(y));
subplot(4,1,2);
plot(w,angle(y));
f=0.5;
w1=2*3.14*f;
y1=exp(j*w1*n);
y2=a.*y1;
w=[-pi*4:pi/512:pi*4];
y3=freqz(y2,yco,w);
subplot(4,1,3);
plot(w,abs(y3));
subplot(4,1,4);
plot(w,angle(y3));

Department of Electronics 61
CAS,calicut
Digital Signal
Processing Lab

Output

Magnitude Spectrum Of X(e jw )


10
Amplitude

0
-15 -10 -5 0 5 10 Frequency15
5 Phase Spectrum Of X(ejw )
Phase

-5
-15 -10 -5 0 5 10 15
Magnitude Spectrum Of X(e j -w 0))
- (w Frequency
10
amplitude

0
-15 -10 -5 0 5 10 frequncy 15
Phase spectrum of X(e-j(w -w 0))
5
phase

-5
-15 -10 -5 0 5 10frequency 15

Result

The frequency shifting property of DTFT is verified.


ω
F{ej 0n x(n)} = X(ω -ω 0).

Department of Electronics 62
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 17 MODULATION PROPERTY


02-09-09

Aim

To write a program that verifies the modulation property of DTFT.


Let X1(n) = sin(2∗ π∗ 0.1∗n) and X2(n) = sin(2∗ π∗ 1∗n).

Program

clf;
a=[1 2 3];
b=[2 3 4];
yco=1;
w=[-pi*4:pi/512:pi*4];
y=freqz(a,yco,w);
y1=freqz(b,yco,w);
subplot(4,1,1);
plot(w,abs(y));
subplot(4,1,2);
plot(w,abs(y1));
y2=a.*b;
y3=freqz(y2,yco,w);
subplot(4,1,3);
plot(w,abs(y3));

Department of Electronics 63
CAS,calicut
Digital Signal
Processing Lab

Output

Magnitude Spectrum Of X1(e jw )


10
Amplitude

0
-15 -10 -5 0 5 10 15
Frequency

Magnitude Spectrum Of X2(W)


10
Amplitude

0
-15 -10 -5 0 5 10 15
Frequency
Magnitude Spectrum Of DTFT Of x1(n)x2(n)
20
Amplitude

10

0
-15 -10 -5 0 5 10 15
Frequency

Result

The modulation property of DTFT is verified.

Department of Electronics 64
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 18 TIME REVERSAL PROPERTY


9-09-09
Aim

To write a program that verifies the time reversal property of DTFT.


Given x(n) = [1 2 3 4 5 6 7 8 9].

Program

clf;
yco=1;
xco=[1 2 3 4 5 6 7 8 9];
w=[-pi*4:pi/512:pi*4];
y=freqz(xco,yco,w);
subplot(4,1,1);
plot(w,abs(y));
subplot(4,1,2);
plot(w,angle(y));
y1=fliplr(xco)
y2=freqz(y1,yco,w);
subplot(4,1,3);
plot(w,abs(y2));
subplot(4,1,4);
plot(w,angle(y2));

Department of Electronics 65
CAS,calicut
Digital Signal
Processing Lab

Output

Result

The time reversal property of DTFT is verified.


F{x(-n)} = X(-ω ).

Department of Electronics 66
CAS,calicut
Digital Signal
Processing Lab

DISCRETE FOURIER TRANSFORM

Department of Electronics 67
CAS,calicut
Digital Signal
Processing Lab

DISCRETE FOURIER TRANSFORM

The discrete Fourier Transform (DFT) of a discrete time signal x(n) is a finite
duration discrete frequency sequence. The DFT sequence is denoted by X(k). The DFT
is obtained by sampling one period of the Fourier Transform X(ω ) of the signal x(n) at
a finite number of frequency points. This sampling is conventionally performed at N
equally spaced points in the period 0 ≤ ω ≤ 2π or at ω k =2π k/N; 0 ≤ k ≤ N-1.

The Fourier Transform of a discrete time signal is continuous function of w and


so cannot be processed by digital system. The discrete Fourier Transform (DFT)
converts the continuous function of ‘ω ’ to a discrete function of ‘ω ’. Thus DFT allows
us to perform frequency analysis on a digital computer.

The DFT is important for two reasons.

1. It allows us to determine the frequency content of a signal, i.e., to perform


spectral analysis.
2. Perform filtering operations in the frequency domain.

Let x(n) be a discrete time sequence with Fourier Transform X(ω ), then the
DFT of x(n) denoted by X(k) is defined as,

X(k) = X(ω )| ω =2π k/N ; for k=0,1,2,. . . (N-1)

The DFT of x(n) is a sequence consisting of N samples of X(ω ). The DFT


sequence starts at k=0, corresponding to ω =0 but does not include k=N, corresponding
to ω =2π ( since the sample at ω =0 is same as the sample at ω =2π ).

Department of Electronics 68
CAS,calicut
Digital Signal
Processing Lab
Generally the DFT is defined along with number of samples and is called N-
point DFT. The number of samples N for a finite duration sequence x(n) of length L
should be such that, N ≥ L .

Definition of DFT

The N-point DFT of a finite duration sequence x(n) of length L, where N ≥ L,


is defined as
N −1 π
DFT{x(n)} = X(k) = ∑ x(n) e-(j2 kn) / N ; for k=0,1,2, . . . (N-1)
n=0
Definition of IDFT

The Inverse Discrete Fourier Transform (IDFT) of the sequence X(k) of length
N is defined as
N −1 π
IDFT{X(k)} = x(n) = 1/N ∑ X(k) e(j2 kn)/N ; for n= 0,1,. . . (N-1)
n=0

Properties:

1. Linearity

If DFT{x1(n)} = X1(k)
and DFT{x2(n)} = X2(k)

Then for any real-value or complex value constant a1 and a2,


DFT{a1x1(n) + a2x2(n)} = a1X1(k) + a2X2(k)

2. DFT of delayed sequence

Let x(n) be the discrete sequence and x`(n) be a shifted sequence of x(n) by n0
units of time.
Let DFT{x(n)} = X(k)
π
Now, DFT{x`(n)} = DFT{x(n-n0)} = X(k) e-(j2 kn0)/N

3. DFT of time reversed sequence

If DFT{x(n)} = X(k)
then DFT{x(N-n)} = X(N-k)

Hence reversing the N-point sequence in time is equivalent to reversing the DFT
values.

4. Circular time shift of a sequence

If DFT{x(n)} = X(k)

Department of Electronics 69
CAS,calicut
Digital Signal
Processing Lab
π
then DFT{x(n-l , (mod N)) } = X(k) e-(j2 kl)/N

5. Circular frequency shift

If DFT{x(n)} = X(k)
π
then DFT{x(n) e(j2 ln)/N } = X(k-l, (mod N)) .

Hence the multiplication of the sequence x(n)with the complex exponential


π
sequence e(j2 ln)/N is equivalent to the circular shift of the DFT by l units in
frequency. This is the dual to the circular time shifting property.

6. Circular Convolution

If DFT{x1(n)} = X1(k)
and DFT{x2(n)} = X2(k)
then DFT{x1(n) x2(n) }= X1(k) X2(k)

7. Multiplication of two sequences

DFT{x1(n) * x2(n)} = 1/N X1(k) X2(k)

Prog. No: 19 EVALUATION OF N-point DFT


16-09-09

Aim

To write a program that evaluate the DTFT & 4-point DFT of a causal 3
sampled sequence given by,
x(n) =  ; 0<=n<=2
0 ; otherwise.

Program

clf;
xco=[1/3 1/3 1/3];
yco=1;
w=[-4*pi:pi/512:4*pi];
n=[0:15];
y1=freqz(xco,yco,w);
m1=abs(y1);
p1=angle(y1);
y2=fft(xco,16);
m2=abs(y2);
p2=angle(y2);
subplot(4,1,1);
plot(w,m1);
axis([0,6,0,2]);
Department of Electronics 70
CAS,calicut
Digital Signal
Processing Lab
grid
subplot(4,1,2);
plot(w,p1);
axis([0,6,-2.5,2.5]);
grid
subplot(4,1,3);
stem(n,m2);
grid
subplot(4,1,4);
stem(n,p2);
grid

Output

Department of Electronics 71
CAS,calicut
Digital Signal
Processing Lab

Result

The 4-point DFT of the given sequence is found.

Prog. No: 20 CIRCULAR SHIFTING


16-09-09
Department of Electronics 72
CAS,calicut
Digital Signal
Processing Lab

Aim

To write a program that performs the circular shifting property of DFT.

Program

function y=circularshift(x,m)
ln=length(x);
if m<0
m=m*-1;
end
if m>ln
m=rem(m,ln);
end
y=[x((m+1):ln) x(1:m)];

clf;
x=[0:9];
m=4;
subplot(2,1,1);
stem(x,x);
subplot(2,1,2);
y=circularshift(x,m);
stem(x,y);

Output
Department of Electronics 73
CAS,calicut
Digital Signal
Processing Lab

Result

The given sequence is circular shifted by 4 units.

Department of Electronics 74
CAS,calicut
Digital Signal
Processing Lab
Prog. No: 21 CIRCULAR CONVOLUTION
23-09-09

Aim

Write a program to study the circular convolution property of DFT.

Program

function y=circularsh(x,m)
ln=length(x);
if m<0
m=m*-1;
end
if m>ln
m=rem(m,ln);
end
y=[x((m+1):ln) x(1:m)];

function s=circularconvo(x1,x2)
l1=length(x1);
l2=length(x2);
if l1~=l2
display('Unequal signals');
end
s=zeros(1:l1);
x2f=[x2(1) x2(l2:-1:2)];
k1=x1.*x2f;
s(1)=sum(k1);
for m=1:l1-1
y=circularsh(x2f,m);
k=x1.*y;
s(m+1)=sum(k);
end
s=s(1:l1);

clf;
x1=input('Enter first signal:');
s=circularconvo(x1,x2);
display (s);

Department of Electronics 75
CAS,calicut
Digital Signal
Processing Lab

Input

Enter first signal:[2 1 2 1]


Enter second signal:[1 2 3 4]

Output

s=

14 16 14 16

Result

The circular convolution of two sequences is obtained.

Department of Electronics 76
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 22 INVERSE DISCRETE FOURIER TRANSFORM


03-10-09

Aim

To write a program that finds the inverse discrete Fourier transform of


y(k) = [1 0 1 0].

Program

clf;
x=[1 0 1 0];
y=ifft(x);
display(y);

Department of Electronics 77
CAS,calicut
Digital Signal
Processing Lab

Output

y=

0.5000 0 0.5000 0

Result

IDFT of the sequence is found.

Department of Electronics 78
CAS,calicut
Digital Signal
Processing Lab

SAMPLING

Department of Electronics 79
CAS,calicut
Digital Signal
Processing Lab

SAMPLING

Sampling is the conversion of a continuous-time signal into discrete-time signal


obtained by taking “samples” of the continuous-time signal at discrete-time instants.
Thus, if xa(t) is the input to the samples, the output is
xa(nT) = x(n),
where T is called sampling interval.
If the highest frequency obtained in an analog signal x a(t) is fmax. The sampling
rate fs = fmax is called the Nyquist rate.

If the sampling rate is higher than the Nyquist rate, it is called Over-sampling.
On the other hand, if the sampling rate is lower than the Nyquist rate, it is called under-
sampling. Finally, if the sampling rate is exactly equal to the Nyquist rate, it is called
critical sampling.

Sampling theorem

“A continuous-time signal may be completely represented in its samples and


recovered back if the sampling if the sampling frequency is fs ≥ 2 fmax. Here fs is the
sampling frequency and fmax is the maximum frequency present in the signal.”

Department of Electronics 80
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 23 SAMPLING


05-10-09

Aim

To write a program that performs sampling at following rates.


a) < Nyquist Rate (under sampling)
b) = Nyquist Rate (critical sampling)
c) > Nyquist Rate (upper sampling).

Program

clf;
f=0.6;
t=[0:100];
w=pi/180;
ts=1/(2*f);
x1=cos(2*pi*f*t*w);
subplot(4,1,1);
plot(t,x1);
k=([length(t)-1])/ts;
n=[0:k];
x2=cos(2*pi*f*n*ts*w);
subplot(4,1,2);
stem(n,x2);
n=[0:k/10];
x3=cos(2*pi*f*(n*ts*10)*w);
subplot(4,1,3);
stem(n,x3);
n=[0:k*10];
x4=cos(2*pi*f*(n*ts/10)*w);
subplot(4,1,4);
stem(n,x4);

Department of Electronics 81
CAS,calicut
Digital Signal
Processing Lab

Output

Result

The sampling of the given signal is done at rates,

Department of Electronics 82
CAS,calicut
Digital Signal
Processing Lab
a) < Nyquist Rate
b) = Nyquist Rate
c) > Nyquist Rate.

ANALOG-TO-DIGITAL CONVERSION

Department of Electronics 83
CAS,calicut
Digital Signal
Processing Lab

ANALOG-TO-DIGITAL CONVERSION

Most signals of practical interest such as speech, biological signals, seismic


signals, radar signals, sonar signals, and various communication signals such as audio
and video signals are analog .To process analog signals by digital means it is first
necessary to convert them into digital form. That is, to convert them to a sequence of
numbers having finite precision. This procedure is called analog to digital conversion.
The corresponding devices are called A/D converters.

Conceptually A/D conversion can be treated as a three step process:

1. Sampling: This is a conversion of a continuous time signal into a discrete time


signal obtained by taking samples of the continuous time signal at discrete time
instants.
2. Quantization: This is the conversion of discrete time continuous valued signal
into a discrete time, discrete valued signal. The value of each sample is
represented by a value selected from a finite set of possible values. The
difference between the unquantized sample x (n) and the quantized output xq (n)
is called the quantization error.
3. Coding: In the coding process, each discrete value xq (n) is represented by a b-
bit binary sequence.

Although we model the A/D converter as a sampler followed by a


quantizer and coder, in practice the A/D conversion is performed by a single device that
takes xa(t) and produces a binary coded number. The operations of sampling and
quantization can be performed in either order but in practice sampling is always
performed before quantization.

Department of Electronics 84
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 24 ANALOG TO DIGITAL CONVERSION


14-10-09
Aim

To write a program that converts an analog input to digital output.

Program

clf;
i=input('Enter the number:');
if i<0
f(1)=1;
else
f(1)=0;
ni=abs(i);
m=fix(ni);
x=ni-m;
for i=5:-1:2
f(i)=rem(m,2);
m=fix(m/2);
end
for i=6:1:10
x=x*2;
f(i)=fix(x);
x=x-fix(x);
end
display(f);

Department of Electronics 85
CAS,calicut
Digital Signal
Processing Lab

Input

Enter the number:14.6

Output

f=

0 1 1 1 0 1 0 0 1 1

Result

The analog input is converted to digital output.

Department of Electronics 86
CAS,calicut
Digital Signal
Processing Lab

DIGITAL-TO-ANALOG CONVERSION

Department of Electronics 87
CAS,calicut
Digital Signal
Processing Lab

DIGITAL-TO-ANALOG CONVERSION

In many cases of practical interest, (Eg: speech processing) it is desirable to


convert the processed digital signal into analog form. The process of converting digital
signal to analog signal is called digital to analog conversion. All D/A converters
connect the dots in the digital signal by performing some kind of interpolation whose
accuracy depends upon the quality of D/A conversion process. A simple form of D/A is
called a zero hold or a staircase approximation. Other approximations are possible such
as linearly connecting a pair of successive samples and so on.

Department of Electronics 88
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 25 DIGITAL TO ANALOG CONVERSION


16-10-09

Aim

To write a program that convert digital input to analog output.

Program

clf;
x=input('Enter binary value');
if x(1)==1
s=-1;
else
s=1;
end
sum=0;
for i=6:10
sum=sum+(x(i))/(2^(i-5));
end
j=0;
for i=5:-1:2
sum=sum+(x(i))*(2^j);
j=j+1;
end
y=sum*s;
display(y);

Department of Electronics 89
CAS,calicut
Digital Signal
Processing Lab

Input

Enter binary value:[0 1 1 1 0 1 0 0 1 1]

Output

y=

14.5938

Result

The digital input is converted to analog output.

Department of Electronics 90
CAS,calicut
Digital Signal
Processing Lab

FIR FILTER DESIGN

Department of Electronics 91
CAS,calicut
Digital Signal
Processing Lab

FIR FILTER DESIGN

The filters designed by using finite number of samples of impulse response are
called FIR filters. These finite number of samples are obtained from the infinite
duration desired impulse response hd (n) .Here hd(n) is the inverse Fourier Transform of
Hd(ω), where Hd(ω) is the ideal(desired) frequency response. The various methods of
designing FIR filters differs only in the method of determining the samples of h(n) from
the samples of hd(n).

Various steps in designing FIR filters

1. Choose an ideal (desired) frequency response, Hd(ω).


2. Take inverse Fourier Transform of Hd(ω) to get hd(n) or sample Hd(ω) at finite
number of points (N-point) to get H(k).
3. If hd(n) is determined then convert the infinite duration hd(n) to a finite
duration h(n),(usually h(n) is an N-point sequence) or if H(k) is determined
then take N-point inverse DFT to get h(n).
4. Take Z-transform of h(n) to get H(z), where H(z) is the transfer function of the
digital filter.
5. Choose a suitable structure and realize the filter.
6. Verify the design by simulation.

Advantages of FIR filters

1. FIR filters with exactly linear phase can be easily designed.


2. Efficient realization of FIR filter exist as both recursive and non-recursive
structures.
3. FIR filters realized non-recursively i.e., by direct convolution are always stable.

Department of Electronics 92
CAS,calicut
Digital Signal
Processing Lab
4. Round off noise, which is inherent in realizations with finite precision
arithmetic can easily be made small for non-recursive realization of FIR filters.

Disadvantages of FIR filters

1. The duration of the impulse response should be large (i.e., N should be large) to
adequately approximate sharp cut-off filter. Hence a large amount of processing
is required to realize such filters when realized via slow convolution.
2. The delay of linear phase FIR filters need not always be an integer number of
samples. This non-integral delay can lead to problems in some signal processing
applications.

Prog. No: 26 LOW PASS FILTER


16-10-09
Aim

To design an FIR LPF for a cut off frequency of 1.5 KHz .Let the order of the
filter is 50.Use window method .Assume the sampling frequency be 8000 samples/sec.

Program

clf;
N=50;
Wn=[1500/4000];
B=fir1(N,Wn);
[p,w]=freqz(B,1,512,8000);
subplot(3,1,1);
plot(w,abs(p)) ;
subplot(3,1,2);
plot(w,angle(p));
subplot(3,1,3);
zplane(B,N);

Department of Electronics 93
CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 94
CAS,calicut
Digital Signal
Processing Lab

Result

The FIR LPF with given specifications is designed.

Prog. No: 27 HIGH PASS FILTER


Department of Electronics 95
CAS,calicut
Digital Signal
Processing Lab
18-10-09
Aim

To design an FIR HPF for a cut off frequency of 1.5 KHz .Let the order of the
filter be 50.Use window method .Assume the sampling frequency be 8000 samples/sec.

Program

clf;
N=50;
Wn=[1500/4000];
B=fir1(N,Wn,'high');
[p,w]=freqz(B,1,512,8000);
subplot(3,1,1);
plot(w,abs(p));
subplot(3,1,2);
plot(w,angle(p));
subplot(3,1,3);
zplane(B,N);

Department of Electronics 96
CAS,calicut
Digital Signal
Processing Lab
Output

Result

The FIR HPF with given specifications is designed.

Department of Electronics 97
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 28 BAND PASS FILTER


18-10-09
Aim

To design a FIR band pass filter. Let the order of the filter be 50.Use window
method .Assume the sampling frequency be 8000 samples/sec. Let the cut off
frequencies be 1500 and 3000 respectively.

Program

clf;
N=50;
Wn=[1500/4000,3000/4000];
B=fir1(N,Wn,'band');
[p,w]=freqz(B,1,512,8000);
subplot(3,1,1);
plot(w,abs(p));
subplot(3,1,2);
plot(w,angle(p));
subplot(3,1,3);
zplane(B,N);

Department of Electronics 98
CAS,calicut
Digital Signal
Processing Lab

Output

Result

The FIR BPF with given specifications is designed.

Department of Electronics 99
CAS,calicut
Digital Signal
Processing Lab

Prog. No: 29 BAND STOP FILTER


23-10-09

Aim

To design a FIR stop band filter. Let the order of the filter be 50.Use window
method. Assume the sampling frequency be 8000 samples/sec. Let the cut off
frequencies be 1500 and 3000 respectively.

Program

clf;
N=50;
Wn=[1500/4000,3000/4000];
B=fir1(N,Wn,'stop'); % FIR stop band filter design using window
method
[p,w]=freqz(B,1,512,8000); % compute an N-point complex frequency
response
subplot(3,1,1);
plot(w,abs(p)); % magnitude spectrum
subplot(3,1,2);
plot(w,angle(p)); % phase spectrum
subplot(3,1,3);
zplane(B,N); % z-transform in the form of rational function

Department of Electronics 100


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The FIR BSF with given specifications is designed.

Department of Electronics 101


CAS,calicut
Digital Signal
Processing Lab

IIR FILTER DESIGN

Department of Electronics 102


CAS,calicut
Digital Signal
Processing Lab

IIR FILTER DESIGN

The filters designed by considering all the infinite samples of impulse response
are called IIR filters. The impulse response is obtained by taking inverse Fourier
Transform of ideal frequency response. The popular methods for such filter design use
the technique of transforming the analog filter to an equivalent digital filter. We know
that the analog filter with transfer function Ha(s) is stable if all its poles lie in the left
half of the s-plane. Consequently, if the conversion technique is to be effective, it
should posses the following desirable properties.

1. The imaginary axis in the s-plane should map into the unit circle in the z-
plane .Thus there will be a direct relationship between the two frequency
variables in the two domains.
2. The left half of the s-plane should map into the interior of the unit circle in the
z-plane. Thus a suitable analog filter will be converted to a stable digital filter.

The IIR filter is a discrete time system that is designed to pass the spectral
content of the input signal in a specified band of frequencies. Based on the frequency
response the filters are classified into four types. They are Low pass, High pass, Band
pass, and Band stop filters.

A number of solutions to the approximation problem of analog filter design are


well developed. The popular among them are Butterworth and Chebyshev
approximation. For designing a digital IIR filter, first an equivalent analog filter is
designed using any one of the approximation technique and the given specifications.
The result of the analog filter design will be an analog filter transfer function Ha(s) .The
analog transfer function is converted to digital transfer function H(z) using either
Bilinear or Impulse invariant transformation . The digital transfer function H(z) can be
realized in a software that runs on a digital hardware (or it can be implemented in
firmware) .

Important features of IIR filters

1. The physically realizable IIR filters does not have linear phase.
2. The IIR filter specifications include the desired characteristics for the magnitude
response only.

Department of Electronics 103


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 30 LOW PASS IIR FILTER


25-10-09
Aim

To write a program to study the characteristics of a Butterworth IIR low pass


filter. The following specifications are given.
1) Sampling frequency = 8000
2) Passband frequency = 1000
3) Stop band frequency = 2000
4) Pass band ripple = 0.2
5) Stop band ripple = 16.

Program

clf;
Wp=1000/4000;
Ws=2000/4000;
rp=0.2;
rs=16;
[N,Wn]=buttord(Wp,Ws,rp,rs);
[B,A]=butter(N,Wn,'low');
[p,w]=freqz(B,A,512,8000);
subplot(2,1,1);
plot(w,abs(p));
grid
subplot(2,1,2);
zplane(B,N);
grid

Department of Electronics 104


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The IIR LPF with given specifications is designed.

Department of Electronics 105


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 31 HIGH PASS IIR FILTER


1-11-09

Aim

To write a program to study the characteristics of a Butterworth IIR high pass


filter. The following specifications are given.
1) Sampling frequency = 8000
2) Passband frequency = 1000
3) Stop band frequency = 2000
4) Pass band ripple = 0.002
5) Stop band ripple = 20.

Program

clf;
Wp=1000/4000;
Ws=2000/4000;
rp=0.002;
rs=20;
[N,Wn]=buttord(Wp,Ws,rp,rs);
[B,A]=butter(N,Wn,'high');
[p,w]=freqz(B,A,512,8000);
subplot(2,1,1);
plot(w,abs(p));
grid
subplot(2,1,2);
zplane(B,N);
grid

Department of Electronics 106


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The IIR HPF is designed using given specifications.

Department of Electronics 107


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 32 BAND PASS IIR FILTER


1-11-09
Aim

To write a program to study the characteristics of a Butterworth IIR band pass


filter. The following specifications are given.
1) Sampling frequency = 8000
2) Passband frequency = 300, 1000
3) Stop band frequency = 200, 2000
4) Pass band ripple = 1
5) Stop band ripple = 20.

Program

clf;
Wp=[300/4000,1000/4000];
Ws=[200/4000,2000/4000];
rp=1;
rs=20;
[N,Wn]=buttord(Wp,Ws,rp,rs);
[B,A]=butter(N,Wn,'bandpass');
[p,w]=freqz(B,A,512,8000);
subplot(2,1,1);
plot(w,abs(p));
grid
subplot(2,1,2);
zplane(B,N);
grid

Department of Electronics 108


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The IIR BPF is designed using given specifications.

Department of Electronics 109


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 33 BAND STOP IIR FILTER


1-11-09
Aim

To write a program to study the characteristics of a Butterworth IIR band stop


filter. The following specifications are given.
1) Sampling frequency = 8000
2) Passband frequency = 200, 1000
3) Stop band frequency = 100, 2000
4) Pass band ripple = 0.1
5) Stop band ripple = 10.

Program

clf;
Wp=[200/4000,1000/4000];
Ws=[100/4000,2000/4000];
rp=.1;
rs=10;
[N,Wn]=buttord(Wp,Ws,rp,rs);
[B,A]=butter(N,Wn,'stop');
[p,w]=freqz(B,A,256,8000);
subplot(2,1,1);
plot(w,abs(p));
grid
subplot(2,1,2);
zplane(B,A);
grid

Department of Electronics 110


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The IIR BSF with given specifications is designed.

Department of Electronics 111


CAS,calicut
Digital Signal
Processing Lab

LTI SYSTEM CONVOLUTION

Department of Electronics 112


CAS,calicut
Digital Signal
Processing Lab

LTI SYSTEM CONVOLUTION

In an LTI system the response y(n) of the system for an arbitrary input x(n) is
given by convolution of input x(n) with impulse response h(n) of the system. It is
expressed as

y(n) = x(n) ∗ h(n)

where the symbol ‘∗’ represents convolution operation.

Properties of convolution:

Commutative property: x(n) * h(n) = h(n) * x(n)

Associative property : [x(n) * h1(n)] * h2(n) = x(n) * [h1(n) * h2(n)]

Distributive property : x(n) * [h1(n)+h2(n)] = [x(n) * h1(n)] + [x(n) * h2(n)]

Department of Electronics 113


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 34 IMPULSE RESPONSE


8-11-09
Aim

To evaluate impulse response of the system described by the differential


equation, y(n) +0.71y(n-1) - 0.46y(n-2) - 0.62y(n-3) = 0.9x(n) - 0.45x(n-1) + 0.35x(n-1)
+ 0.002x(n-3).

Program

clf;
xco=[.9 -.45 .35 .002];
yco=[1 .71 -.46 -.62];
n=[0:50];
subplot(2,1,1);
ir=impz(xco,yco,n);
stem(n,ir);
subplot(2,1,2);
imp=[1 zeros(1,50)];
y=filter(xco,yco,imp);
stem(n,y);

Department of Electronics 114


CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 115


CAS,calicut
Digital Signal
Processing Lab
Result

The impulse response of the given system is evaluated.

Prog. No: 35 CONVOLUTION - I


8-11-09

im

To sketch the Impulse response of an LTI system characterized by the


differential equation y(n) = 0.4 x(n) + x(n-1) + 0.6 x(n- 2) + x(n-3) + 0.4x(n-4). And
also to find the output of the system when the signal x(n) = cos(π ∗ n) is given as the
input of the system.

Program

clf;
subplot(3,1,1);
n=[0:50];
xco=[0.4 1 0.6 1 0.4];
yco=1;
y=impz(xco,yco,n);
stem(n,y);
subplot(3,1,2);
x=cos(pi.*n);
stem(n,x);
subplot(3,1,3);
yc=conv(x,y);
n1=[0:length(yc)-1];
stem(n1,yc);

Department of Electronics 116


CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 117


CAS,calicut
Digital Signal
Processing Lab

Result

The impulse response of the given system is evaluated and plotted.

Prog. No: 36 CONVOLUTION - II


Department of Electronics 118
CAS,calicut
Digital Signal
Processing Lab
10-11-09

Aim

To write a program to obtain the output y(n) for an LTI causal system whose
impulse response is h(n) = [3 2 1 -2 1 0 -4 0 3] for an input x(n) = [1 -2 3 -4 3 2
1].

Program

clf;
x=[1 -2 3 -4 3 2 1];
h=[3 2 1 -2 1 0 -4 0 3];
n=[0:2*length(x)];
y=conv(x,h);
subplot(2,1,1);
stem(n,y);
yco=1;
ip=[3 2 1 -2 1 0 -4 0 3 0 0 0 0 0 0];
y1=filter(x,yco,ip);
subplot(2,1,2);
stem(n,y1);

Department of Electronics 119


CAS,calicut
Digital Signal
Processing Lab
Output

Result

The impulse response of the given system is evaluated.

Department of Electronics 120


CAS,calicut
Digital Signal
Processing Lab

CORRELATION

Department of Electronics 121


CAS,calicut
Digital Signal
Processing Lab

CORRELATION

A mathematical operation that closely resembles convolution is correlation.


Two signal sequences are involved in correlation. The objective ion computing the
correlation between the two signals is to measure the degree to which the two signals
are similar and thus to extract some information that depends to a large extent on the
application. Correlation of signals is often encountered in radar, sonar, digital
communications, geology, and other areas in science and engineering.

Crosscorrelation and Autocorrelation sequences

Suppose that we have two real signal sequences x(n) and y(n) each of which has
finite energy. The crosscorrelation of x(n) and y(n) is a sequence rxy(l), which is defined
as

rxy(l) = ∑ x(n) y(n-l) l=0, 1, 2, … ….. (1)
n =−∞

or, equivalently, as


rxy(l)= ∑ x(n+l) y(n) l=0, 1, 2, … ….. (2)
n =−∞

The index l is the (time) shift(or lag) parameter and the subscripts xy on the
crosscorrelation sequence rxy(l) indicate the sequences being correlated. The order of
the subscripts, with x preceding y , indicates the direction in which one sequence is
shifted, relative to the other. In (1), the sequence x(n) is left unshifted and y(n) is
shifted by l units in time, to the right for l positive and to the left for l negative.
Equivalently, in (2), the sequence y(n) is left unshifted and x(n) is shifted by l units in
time , to the left for l positive and to the right for l negative. But shifting x(n) to the left
by l units relative to y(n) is equivalent to shifting y(n) to the right by l units relative to
x(n). hence the computations (1) and (2) yield identical crosscorrelation sequences.

If we reverse the roles of x(n) and y(n) in (1) and (2) and therefore reverse the
order of the indices xy, we obtain the crosscorrelation sequence


ryx(l)= ∑ y(n) x(n-l) ….. (3)
n =−∞

or, equivalently,


ryx(l)= ∑ y(n+l) x(n) ….. (4)
n =−∞
Department of Electronics 122
CAS,calicut
Digital Signal
Processing Lab

By comparing (1) with (4) or (2) with (3), we conclude that

rxy(l)=ryx(-l)

Therefore, ryx(l) is simply rhe folded version of rxy(l), where the folding is done
with respect to l=0. Hence, ryx(l) provides exactly the same information as rxy(l), with
respect to the similarity of x(n) to y(n).

In the special case where y(n)= x(n), we have the autocorrelation of x(n), which
is defined as the sequence


rxx(l)= ∑ x(n) x(n-l)
n =−∞

or, equivalently, as


rxx(l)= ∑ x(n+l) x(n)
n =−∞

In dealing with finite-duration sequences, it is customary to express the autocorrelation


and crosscorrelation in terms of the finite limits on the summation. In particular if x(n)
and y(n) are causal sequences of length N [i.e.,x(n)= y(n)= 0 for n<0 and n≥ N], the
crosscorrelation and autocorrelation sequences may be expressed as

N − k −1
rxy(l)= ∑ x(n) y(n-l)
n =i

and

N − k −1
rxx(l)= ∑ x(n) x(n-l)
n =i

where i=l , k=0 for l≥ 0, and i=0, k=l for l<0.

Properties:

1. Symmetry
The autocorrelation sequence of a WSS random process is a conjugate
symmetric function of k,
rxx(k)=rxx∗(-k)
For a real process, the autocorrelation sequence is symmetric
rxx(k)=rxx(-k)
Department of Electronics 123
CAS,calicut
Digital Signal
Processing Lab

2. Mean-square value
The autocorrelation sequence of a WSS process at lag k=0 is equal to the mean-
square value of the process
rxx(0)= E{| x(n) | 2} ≥ 0

3. Maximum value
The magnitude of the autocorrelation sequence of a WSS random process at lag
k is upper bounded by its value at lag k=0,
rxx(0) ≥ | rxx(k) |

4. Periodicity
If the autocorrelation sequence of a WSS random process is such that
rxx(k0) = rxx(0)
For some k0, then rx(k) is periodic with period k0. Further more,
E{| x(n) - x(n-k0) | 2}=0
And x(n) is said to be mean-square periodic.

Department of Electronics 124


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 37 AUTO-CORRELATION


14-11-09

Aim

To write a program that performs auto-correlation.

Program

clf;
n=[0:100];
x=sin(2*pi*0.1*n);
subplot(2,1,1);
stem(n,x);
y=xcorr(x);
subplot(2,1,2);
n1=length(x);
n2=[0:(2*n1)-2];
stem(n2,y);

Department of Electronics 125


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The auto-correlation of the signal is done.

Department of Electronics 126


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 38 CROSS-CORRELATION


20-11-09

Aim

To write a program that performs cross-correlation.

Program

clf;
n=[0:50];
x1=sin(2*pi*0.1*n);
subplot(3,1,1);
stem(n,x1);
x2=rand(1,51);
subplot(3,1,2);
stem(n,x2);
y=xcorr(x1,x2);
n1=length(x1);
m=[0:(2*n1)-2];
subplot(3,1,3);
stem(m,y);

Department of Electronics 127


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The cross-correlation of the signal is done

Department of Electronics 128


CAS,calicut
Digital Signal
Processing Lab

Z-TRANSFORM

Department of Electronics 129


CAS,calicut
Digital Signal
Processing Lab

Z-TRANSFORM

Transform techniques are an important tool in the analysis of signals and linear
time invariant systems. z-transform plays an important role in analysis and
representation of linear discrete time systems. The z-transform provides a method for
the analysis of discrete time systems in the frequency domain which is generally more
efficient than its time domain analysis.

Definition:

Let, x (n) = Discrete time signal or sequence


X (z) =Z{x (n)} = z-transform of x (n)

The z-transform of a discrete time signal or sequence is defined as the power series


X (z) = ∑xnz
n=


() −n
..... (1)
where z is a complex variable.

The sequence of equation (1) is considered to be two sided and the transform is called
two sided z-transform, since the time index n is defined for both positive and negative
values. If the sequence x (n) is one sided sequence, then the z-transform is called one
sided z-transform.

The one sided z-transform of x (n) is defined as,


X (z) = ∑x (n)z
n =0
−n

Region of convergence

The z-transform is an infinite power series; it exists only for those values of z for
which the series converges. The region of convergence (ROC), of X (z) is the set of all
values of z, for which X (z) attains finite value. The ROC of a finite-duration signal is
the entire z-plane, except possibly the point z = 0 and/or z = ∞.

Department of Electronics 130


CAS,calicut
Digital Signal
Processing Lab
These points are excluded, because z n (when n>0) becomes unbounded for
z=∞ and z −n (when n>0) becomes unbounded for z=0. The properties of the
sequence x (n) determine the region of convergence of X (z).

Poles and zeros

The roots of the numerator polynomial are those values of z for which X (z) = 0
and are referred to as the zeros of X (z). Values of z for which X (z) is infinite are
referred to as the poles of X (z).

Prog. No: 39 Z-TRANSFORM ON THE UNIT CIRCLE


20-11-09

Aim

To write a program to evaluate the following z-transform on the unit circle,


g(z) = (2 + 5 z-1 + 9 z-2 + 5 z-3 + 3 z-4)/(5 + 45 z-1 + 2 z-2 + z-3 + z-4).

Program

clf;
num=[2 5 9 5 3];
den=[5 45 2 1 1];
w=[-4*pi:pi/512:4*pi];
d=freqz(num,den,w);
subplot(4,1,1);
plot(w/pi,abs(d));
subplot(4,1,2);
plot(w/pi,angle(d));
subplot(4,1,3);
zplane(num,den);
subplot(4,1,4);
[z,po,k]=tf2zp(num,den);
zplane(z,po);

Department of Electronics 131


CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 132


CAS,calicut
Digital Signal
Processing Lab

Result

The z-transform of the transfer function of the system is evaluated.

Prog. No: 40 POLE-ZERO PLOT


25-11-09

Aim

To write a program which generates the pole-zero plot for a given function that
has poles & zeros at the following points.
Zero’s 0, 1+2i, -3.2, 5.7
Poles 0.6, 7+3i, -2.7.

Program

clf;
z=[ 0
1+2i
-3.2
5.7];
p=[0.6
7+3i
-2.7];
zplane(z,p);

Department of Electronics 133


CAS,calicut
Digital Signal
Processing Lab

Output

Result

The pole-zero plot for the function given its poles & zeros is generated.

Department of Electronics 134


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 41 GENERATING NUMERATOR AND


25-11-09 DENOMINATOR
Aim

To write a program that generates numerator & denominator values of the


rational function. The given function has zeros (z), poles (p), k at the following points.
z= -1 + 1.4142i - 1 - 1.4142i - 0.25 + 0.6614i - 0.25 - 0.6614i;
p= -0.89576 - 0.2718 0.1147+0.2627i 0.1147-0.2627i;
k= 0.4.

Program

clf;
z=[-1.0000+1.4142i
-1.0000-1.4142i
-0.2500+0.6614i
-0.2500-0.6614i];
p=[-8.9576
-0.2718
0.1147+0.2627i
0.1147-0.2627i];
k=0.4000;
[num,den]=zp2tf(z,p,k);
display(num);
display(den);

Department of Electronics 135


CAS,calicut
Digital Signal
Processing Lab

Output

num =

0.4000 1.0000 1.8000 1.0000 0.5999

den =

1.0000 9.0000 0.3996 0.1998 0.2001

Result

The numerator & denominator values of the rational function given its zeros (z),
poles (p) and k is generated.

Department of Electronics 136


CAS,calicut
Digital Signal
Processing Lab

INVERSE Z-TRANSFORM

Department of Electronics 137


CAS,calicut
Digital Signal
Processing Lab

INVERSE Z-TRANSFORM

The procedure for transforming from the z-domain to the time domain is called
the inverse z-transform.

The inverse Z-transform is

Where ‘C’ is a counterclockwise closed path encircling the origin and entirely in
the region of convergence (ROC). The contour or path, C, must encircle all of the poles
of X(z).

Department of Electronics 138


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 42 INVERSE Z-TRANSFORM OF RATIONAL


2-12-09 FUNCTIONS

Aim

To write a program to find the inverse z-transform of the equation,


x(z)=( z-1 - 1.2 z-2 + z-3)/(1 - 1.3 z-1 + 1.04 z-2 - 0.222 z-3).

Program

clf;
num=[0 1 -1.2 1];
den=[1 -1.3 1.04 -0.222];
[g,t]=impz(num,den);
subplot(2,1,1);
stem(t,g);
subplot(2,1,2);
[g1,t1]=impz(num,den,10,2);
stem(t1,g1);

Department of Electronics 139


CAS,calicut
Digital Signal
Processing Lab

Output

Department of Electronics 140


CAS,calicut
Digital Signal
Processing Lab

Result

The inverse z-transform of the equation is found and plotted.

Prog. No: 43 INVERSE Z-TRANSFORM OF IRRATIONAL


2-12-09 FUNCTIONS
Department of Electronics 141
CAS,calicut
Digital Signal
Processing Lab
Aim

To write a program to find the inverse z-transform of z/(z-2)-z/(z-3).

Program

clf;
syms z;
f=z/(z-2)-z/(z-3);
y=iztrans(f);
display(y);

Output

Department of Electronics 142


CAS,calicut
Digital Signal
Processing Lab
y=

2^n-3^n

Result

The inverse z-transform of the equation is found.

Department of Electronics 143


CAS,calicut
Digital Signal
Processing Lab

IMAGE PROCESSING FUNDAMENTAL


EXPERIMENTS

Department of Electronics 144


CAS,calicut
Digital Signal
Processing Lab
Prog. No: 44 GENERATION OF A CHESS BOARD
8-12-09

Aim

Write a program to form a Chess Board.

Program

a=[0 1 0 1 0 1 0 1
10101010
01010101
10101010
01010101
10101010
01010101
1 0 1 0 1 0 1 0];
imshow(a,'notruesize');

Department of Electronics 145


CAS,calicut
Digital Signal
Processing Lab

Output

Result

A Chess Board is generated.

Department of Electronics 146


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 45 IMAGE PROCESSING - I


8-12-09
Aim

To write a program that displays a true-color image and its gray-scale image.

Program

clf;
b=imread('C:\Documents and Settings\King\My Documents\My Pictures\
St.Thomas college.jpg');
subplot(2,1,1);
imshow(b);
i=rgb2gray(b);
subplot(2,1,2);
imshow(i);

Department of Electronics 147


CAS,calicut
Digital Signal
Processing Lab

Output

Result

A true-color image, its gray-scale image are displayed.

Department of Electronics 148


CAS,calicut
Digital Signal
Processing Lab

Prog. No: 46 IMAGE PROCESSING - II


14-12-09

Aim

To write a program that displays a true-color image, its gray-scale image and
displaying pixel values of a true-color image.

Program

clf;
b=imread('D:\Department of Electronics\MSc\2006-2008 batch.jpg');
subplot(2,1,1);
imshow(b);
length(b);
b(1:400)
i=rgb2gray(b);
subplot(2,1,2);
imshow(i);

Department of Electronics 149


CAS,calicut
Digital Signal
Processing Lab

Output

ans =

Columns 1 through 16

213 213 213 213 213 213 213 213 213 213 213 213 214 214 214 214

Columns 17 through 32

Department of Electronics 150


CAS,calicut
Digital Signal
Processing Lab
214 214 214 214 214 215 214 216 214 214 214 214 214 214 214 214

Columns 33 through 48

214 214 214 212 213 214 212 214 213 213 213 213 213 213 213 213

Columns 49 through 64

213 213 214 213 213 213 213 212 214 214 213 213 213 213 213 213

Columns 65 through 80

213 213 213 213 213 213 213 213 212 213 214 214 213 213 212 214

Columns 81 through 96

215 215 214 215 216 215 214 215 215 216 215 216 217 217 218 217

Columns 97 through 112

217 217 216 217 217 217 215 215 216 216 216 215 215 215 214 214

Columns 113 through 128

215 215 214 213 213 213 213 212 213 213 213 213 213 213 213 213

Columns 129 through 144

212 212 213 213 213 213 212 212 213 213 213 214 214 214 215 215

Columns 145 through 160

213 214 214 214 214 214 213 213 213 213 213 213 213 213 213 213

Columns 161 through 176

213 213 213 213 213 213 213 213 213 213 213 213 213 213 213 213

Columns 177 through 192

213 213 213 213 213 213 213 213 213 213 213 213 213 213 213 213

Columns 193 through 208

213 213 213 213 213 213 213 213 213 213 213 213 213 213 213 213

Department of Electronics 151


CAS,calicut
Digital Signal
Processing Lab
Columns 209 through 224

213 213 213 213 213 213 213 212 212 212 212 212 212 212 212 212

Columns 225 through 240

212 211 211 211 211 211 210 210 210 210 208 207 208 209 208 207

Columns 241 through 256

207 207 207 207 207 207 207 207 207 207 208 207 208 207 206 206

Columns 257 through 272

206 206 206 206 206 206 206 206 206 206 207 208 209 210 211 212

Columns 273 through 288

212 213 212 213 213 212 211 210 210 210 209 209 209 209 208 208

Columns 289 through 304

208 207 207 206 206 206 206 206 206 206 206 206 206 206 206 206

Columns 305 through 320

206 206 206 206 206 206 206 206 206 206 206 206 206 206 206 206

Columns 321 through 336

206 206 206 206 206 206 206 206 206 206 206 206 206 206 206 206

Columns 337 through 352

206 206 206 206 206 206 206 206 206 206 206 206 206 206 206 206

Columns 353 through 368

206 206 206 206 205 205 205 205 204 204 204 205 205 205 205 206

Columns 369 through 384

206 206 206 206 206 206 206 206 206 206 206 206 206 206 206 206

Columns 385 through 400

206 206 206 206 206 206 206 206 206 206 206 206 206 206 206 206
Department of Electronics 152
CAS,calicut
Digital Signal
Processing Lab

Result

A true-color image, its gray-scale image and pixel values of the true-color
image are displayed.

Department of Electronics 153


CAS,calicut

You might also like