0% found this document useful (0 votes)
95 views

DSP Lab Manual 2022-2023

vtu EEE dsp lab manual

Uploaded by

syedriyan.rk
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

DSP Lab Manual 2022-2023

vtu EEE dsp lab manual

Uploaded by

syedriyan.rk
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 76

GURU NANAK DEV ENGINEERING COLLEGE, BIDAR - 585403 (K.S.

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING.

LABORATORY MANUAL

DIGITAL SIGNAL PROCESSING LAB

BE VI SEMESTER ( Electrical & Electronics Engineering )


SUB. CODE : 18EEL67
(CBCS 2018 Scheme)
2022-2023

LAB INSTRUCTOR LAB I/C HOD


ASHOK KUMAR N C SHRAVAN KUMAR Dr.NEELSHETTY K

1
The Vision and Mission of Electrical and Electronics Engineering Department of
Guru Nanak Dev Engineering College, Bidar are as follows:

VISION
To be a premier department known for its quality education, cutting edge
research and accomplished graduates to serve the society.

MISSION

M1: To provide quality education and skills to the students of Electrical and
Electronics Engineering, with a focus to develop critical-thinking and problem-
solving skills to face the challenges in their career .

M2: To promote research activities and life-long learning required for


successful professional career.

M3: To contribute to the society through technical and professional education


that is embedded with ethics and humanity.

The undergraduate curriculum of Electrical and Electronics Engineeringat Guru


Nanak Dev Engineering College strives to produce graduates that:

 PEO1: Apply fundamentals of Electrical and Electronics Engineering and skills


needed to identify, analyze and provide modern engineering solution to real-
world problems (Fundamental Knowledge and Skills).
 PEO2:Apply analytical, critical thinking, lifelong learning abilities & managerial
skills to develop & manage various Electrical Engineering systems. (Skills for
Future)
 PEO3: Use professional skills with ethical values to take cognizant decisions
keeping in view the impact of Electrical Engineering solutions in global,
environmental, economical and societal contexts (Ethics and Professionalism)

2
B.E ELECTRICAL AND ELECTRONICS ENGINEERING(EEE)
CHOICE BASED CREDIT SYSTEM (CBCS)
SEMESTER - VI
DIGITAL SIGNAL PROCESSING LABORATORY
Subject Code 18EEL67 IA 4
Marks 0
Number of Practical 03 Exam 0
Hours/Week Hours 3
Total Number of 42 Exam 6
Practical Hours Marks 0
Credits - 02
Sl. Experiments
No
1 Verification of Sampling Theorem both in time and frequency
domains
2 Evaluation of impulse response of a system
3 To perform linear convolution of given sequences
4 To perform circular convolution of given sequences using (a) the
convolution summation formula (b) the matrix method and (c)
Linear convolution from circular convolution with zero padding.
5 Computation of N – point DFT and to plot the magnitude and
phase spectrum.
6 Linear and circular convolution by DFT and IDFT method.
7 Solution of a given difference equation.
8 Calculation of DFT and IDFT by FFT
9 Design and implementation of IIR filters to meet given
specification (Low pass, high pass, band pass and band reject
filters)
10 Design and implementation of FIR filters to meet given
specification (Low pass, high pass, band pass and band reject
filters) using different window functions
11 Design and implementation of FIR filters to meet given
specification (Low pass, high pass, band pass and band reject

3
filters) using frequency sampling technique.
12 Realization of IIR and FIR filters

GURU NANAK DEV ENGG. COLLEGE, BIDAR


EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.01 Date: / /2020

Aim: Write a Matlab program for Verification of sampling theorem

clc;
close all;
t=0:.001:.2;
Fmax=50;
x=cos(2*pi*Fmax*t);

subplot(4,1,1);
plot(t,x);
title('Analog sinusoid');
Fs=100; %equal to 2Fmax
%Fs=200; %greater than 2Fmax
%Fs=90; %less than 2Fmax
n=0:1/Fs:.2;
xn=cos(2*pi*Fmax*n);

subplot(4,1,2);
stem(n,xn);
title ('Discrete');
L=4;
ni=0:1/(L*Fs):.2;
xni=interp1(n,xn,ni,'cubic');

subplot(4,1,3);
stem(ni,xni);
hold on;
plot(ni,xni,'r');
legend('discrete','reconstructed');
title ('Interpolation');

subplot(4,1,4);
plot(t,x,'b',ni,xni,'r');

4
legend('analog','reconstructed');

1. Verification of sampling theorem

The theorem states, “a continuous time signal can be completely


represented in its samples and reconstructed back if the sampling
frequency fs ≥ 2fmax. Here fs is the sampling frequency and fmax is the
maximum frequency present in the signal”.

Aliasing
Aliasing is the effect in which high frequency component in the spectrum
of the signal takes identity of lower frequency component in the spectrum
of its sampled version.
If fs < 2fmax then aliasing occurs and reconstruction is not possible.

Interpolation
Interpolation is one method for reconstruction of continuous time signal
for its samples. Interpolation increases the sampling rate. The
interpolation involves inserting samples with appropriate consideration to
the samples around the point of insertion.

5
Analog sinusoid
1

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Discrete
1

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Interpolation
1
discrete
reconstructed
0

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Fs=2Fmax
1
analog
reconstructed
0

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2

Analog sinusoid
1
0
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Discrete
1
0
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Interpolation
1
discrete
0
reconstructed
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Fs>2Fmax
1
analog
0
reconstructed
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2

6
Analog sinusoid
1

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Discrete
1

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Interpolation
1
discrete
0
reconstructed
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
Fs<2Fmax
1
analog
0
reconstructed
-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2

7
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.02 Date: / /2020

Aim: Write a Matlab program to find impulse response of a given


system. Given difference equation
a0y(n)+a1y(n-1)=b0x(n)+b1x(n-1)

Ex: y(n)-y(n-1)=x(n)+x(n-1)

clc;
close all;
disp('impluse response of a given system');
b=input('enter the Nr coefficients of transfer function i.e… x
coefficients=');
a=input('enter the Dr coefficients of transfer function i.e… y
coefficients=');
n=input('enter length of unit sample response n=');
[h,t]=impz(b,a,n);
disp(h);
stem(t,h);
grid on;
xlabel('samples n','color','M');
ylabel('amplitude h(n)','color','M');
title('unit sample response','color','r');

8
2. Impulse Response of a given system

The response or output signal obtained from a discrete time system when
the input signal is a unit sample sequence is known as the unit sample
response (impulse response).

The output y(n) of an LTI system for an input signal x(n) can be obtained
by convolving the impulse response h(n) and input signal x(n)

y(n) =x (n)*h(n)

Ex: Given difference equation y(n)-y(n-1)=x(n)+x(n-1)

Solution: for impulse response x(n)=δ(n) and hence y(n)=h(n)

h(n) – h(n-1) = δ(n) + δ(n-1)


taking Z-trans on both side

H(z)=z-1 H(z) = 1+ z-1

1+ z-1 1 z-1
H(z)= -------- = ------- + -------
1 - z-1 1- z-1 1- z-1

Taking inverse Z-transform


h(n) = u(n) + u(n-1)
for n=4
h(0)=1+0=1
h(1)=1+1=2
h(2)=1+1=2
h(3)=1+1=2

9
Result:
impluse response of a given system
enter the Nr coefficients=[1 1]
enter the Dr coefficients=[1 -1]
enter length of unit sample response n=4
1
2
2
2

unit sample response


2

1.8

1.6

1.4
amplitude h(n)

1.2

0.8

0.6

0.4

0.2

0
0 0.5 1 1.5 2 2.5 3
samples n

10
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.03 Date: / /2020

Aim: Write a Matlab program to find Linear convolution of two


given sequences
x(n) = {1,1,1} and h(n) = {1,1,1}
↑ ↑
clc;
close all;
xn=input('enter the first sequence x(n)=');
hn=input('enter the second sequence h(n)=');
xs=input('enter the starting index of x(n)=');
hs=input('enter the starting index of h(n)=');

yn=convn(hn,xn);
disp('linear convolution is');
disp(yn);
xlen=length(xn)-1;
hlen=length(hn)-1;
ylen=length(yn)-1;

n=xs:1:xs+xlen;
subplot(3,1,1);
stem(n,xn);
grid on;
title('linear convolution','color','r');
ylabel('amplitude xn','color','m');

n=hs:1:hs+hlen;
subplot(3,1,2);
stem(n,hn);
grid on;
ylabel('amplitude hn','color','m');

ys=xs+hs;
n=ys:1:ys+ylen;
subplot(3,1,3);
stem(n,yn);
grid on;
ylabel('amplitude yn','color','m');
xlabel('samples n','color','m');

11
3. Linear Convolution of two given sequences

Let x(n) be the input to an LTI system and y(n) be the output of the
system. Let h(n) be the response of the system to an impulse. The output
y(n) can be obtained by convolving the impulse response h(n) and the
input signal x(n).


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

The above equation is called as the convolution sum and is represented as


y(n) = x(n) * h(n), where * denotes the convolution operation.

Ex: Consider x(n) = {1 1 1} and h(n) = {1 1 1}


↑ ↑

xs = Starting index of x(n)


hs = Starting index of h(n)
ys = Starting index of y(n)
ys = xs + hs

h(n) 1 1 1
x(n)
1 1 1 1
1 1 1 1
1 1 1 1

y(n)= {1 2 3 2 1}

12
Result:
enter the first sequence x(n)=[1 1 1]
enter the second sequence h(n)=[1 1 1]
enter the starting index of x(n)=-1
enter the starting index of h(n)=-1
linear convolution is
1 2 3 2 1

linear convolution
1
amplitude xn

0.5

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
1
amplitude hn

0.5

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
3
amplitude yn

0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
samples n

13
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.04 Date: / /2020

Aim: Write a Matlab program to find Circular convolution of two


given sequences (Matrix method)
x(n) = {2,1,2,1} and h(n) = {1,2,3,4} for N=4

clc;
close all;
clear all;
x=input('enter the sequence x=');
h=input('enter the sequence h=');
N=input('enter the value of N=');
N1=length(x);
N2=length(h);
x=[x,zeros(1,(N-N1))];
h=[h,zeros(1,(N-N2))];
x
h
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('The Circular convolution of x(n) and h(n) is');
y

14
4. Circular convolution of two given sequences
(Matrix Method)

Let x(n) and h(n) are finite duration sequences both of length N then the
output y(n) obtained by circular convolution is

N-1
y(n)=x(n) N h(n) = ∑ x(k)h((n-k))N n= 0,1,……N-1
k=0

This equation can be formulated in matrix form as follows:

y(1) h(1) h(4) h(3) h(2) x(1)


y(2) = h(2) h(1) h(4) h(3) x(2)
y(3) h(3) h(2) h(1) h(4) x(3)
y(4) h(4) h(3) h(2) h(1) x(4)
: : : : :
: : : : :
y(n) h(n) h(n-1) … h(0) x(n)

Consider x(n)={2 1 2 1} and h(n)={1 2 3 4} for N=4

y(1) 1 4 3 2 2
y(2) = 2 1 4 3 1
y(3) 3 2 1 4 2
y(4) 4 3 2 1 1

y(n) = {14 16 14 16}

15
Result:
enter the sequence x(n)=[2 1 2 1]
enter the sequence h(n)=[1 2 3 4]
enter the value of N=4

x=

2 1 2 1

h=

1 2 3 4

The Circular convolution of x(n) and h(n)is

y=

14 16 14 16

16
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.05 Date: / /2020

Aim: Write a Matlab program to find auto-correlation of given


sequence and verify of its properties.
x(n) = {1 2 1 1}
clc;
close all;
x=input('enter the sequence x(n)=');
n=0:1:length(x)-1;
subplot(2,1,1);
stem(n,x);
xlabel('x(n) n-->');

disp('the auto-correlation of x(n) is');


Rxx=xcorr(x,x)
nRxx=-length(x)+1:length(x)-1;
subplot(2,1,2);
stem(nRxx,Rxx,'r');
legend('auto correlation');
xlabel('Rxx l-->');

%Property 1
energy=sum(x.^2);
center_index=ceil(length(Rxx)/2);
Rxx_0=Rxx(center_index);

if ceil(Rxx_0) == energy
disp('Rxx(0) gives energy -- proved');
else
disp('Rxx(0) gives energy -- not proved');
end

%Property 2
if Rxx == fliplr(Rxx)
disp('Rxx is even');
else
disp('Rxx is not even');
end

17
5. Auto correlation of given sequence and verification of its
properties
Auto-correlation function gives the measure of similarity, match or
coherence between a signal & its delayed replica. For example in digital
communication, a set of data symbols is represented by a set of unique
discrete-time sequences. If one sequence is transmitted, the receiver has
to determine which particular sequence has been received by comparing
the received signal with every member of possible sequences from the
set. Similarly, in radar & sonar applications, the received signal reflected
from the target is the delayed version of the transmitted signal and by
measuring the delay; one can determine the location of the target. It is
given by

rxx(l) = ∑ x(n)x(n-l) l = 0, ±1, ±2,…….
n=-∞
The parameter l called lag indicates the time shift between the pair.

rxy(l) = ∑ x(n)x(-(l-n))
n=-∞
rxy(l) = x(l) * x(-l)
We find that correlation process is essentially the convolution of two data sequences

in which one of the sequences has been reversed.

The properties of autocorrelation are


1. rxx(0) = Energy of x(n)

Where Energy = ∑ |x(n)|2
n=-∞
2. rxx(l) = rxx(-l)
Compute the autocorrelation of the sequence x(n) = {1, 2, 1, 1}
x(l) = {1 2 1 1}
x(-l) = {1 1 2 1}
x(l) 1 2 1 1
x(-l) 1 1 2 1
--------------------------
1 2 1 1
2 4 2 2 +
1 2 1 1 +
1 2 1 1 +
--------------------------------------------------
1 3 5 7 5 3 1
rxx(l) = {1 3 5 7 5 3 1}

18
Result:
enter the sequence x(n)=[1 2 1 1]
the auto-correlation of x(n) is

Rxx =

1.0000 3.0000 5.0000 7.0000 5.0000 3.0000 1.0000

Rxx(0) gives energy -- proved


Rxx is even

1.5

0.5

0
0 0.5 1 1.5 2 2.5 3
x(n) n-->

8
auto correlation
6

0
-3 -2 -1 0 1 2 3
Rxx l-->

19
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.06 Date: / /2020

Aim: Write a Matlab program to find cross-correlation of given


sequence and verification of its properties.
x(n) = {1,3,-2,1,2,-1,4,4,2} and h(n) = {2,-1,4,1,-2,3}

clc;
close all;
x=input('enter the sequence x(n)=');
y=input('enter the sequence y(n)=');

n=0:length(x)-1;
subplot(2,2,1)
stem(n,x);
xlabel('x(n) n-->');
ylabel('amplitude');
n1=0:length(y)-1;
subplot(2,2,2)
stem(n1,y);
xlabel('y(n) n-->');
ylabel('amplitude');

m=max(length(x),length(y));
Rxy=xcorr(x,y);
disp('cross-correlation of x(n) and y(n) is');
disp(Rxy);
nRxy=-m+1:m-1;
subplot(2,2,3:4);
stem(nRxy,Rxy,'r');
xlabel('Rxy l-->');
%property 1
Ex=sum(x.^2);
Ey=sum(y.^2);
Rxx=xcorr(x);
Ryy=xcorr(y);

center_index=ceil(length(Rxx)/2);
Rxx_0=Rxx(center_index);
center_index1=ceil(length(Ryy)/2);
Ryy_0=Ryy(center_index1);

20
if ceil(Rxx_0*Ryy_0) == (Ex*Ey)
disp('Rxy[l]<=sqrt(Rxx_0*Ryy_0)=sqrt(Ex*Ey) -- proved');
else
disp('Rxy[l]<=sqrt(Rxx_0*Ryy_0)=sqrt(Ex*Ey) -- not proved');
end
%property 2
Ryx=xcorr(y,x);
if Rxy == fliplr(Ryx)
disp('Rxy is even');
else
disp('Rxy is not even');
end

21
6. Cross-correlation of given sequence and verification of its
properties
The cross-correlation between two signals explains how much one signal
is related to the time-delayed version of another signal. It is given by


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

The parameter l called lag indicates the time shift between the pair.

rxy(l) = ∑ x(n)y(-(l-n))
n=-∞

rxy(l) = x(l) * y(-l)


We find that correlation process is essentially the convolution of two data
sequences in which one of the sequences has been reversed.
The properties of cross correlation are
1.
rxx (0) * ryy (0) =Ex * Ey

∞ ∞
Where Ex = ∑ |x(n)|2 Ey = ∑ |y(n)|2
n=-∞ n=-∞
2.
rxy(l) = ryx(-l)
Consider x(n) = {1,3,-2,1,2,-1,4,4,2} and y(n) = {2,-1,4,1,-2,3}

x(n) 1 3 -2 1 2 -1 4 4 2
y(-l) 3 -2 1 4 -1 2
-------------------------------------------------------------------------
2 6 -4 2 4 -2 8 8 4
-1 -3 2 -1 -2 1 -4 -4 -2 +
4 12 -8 4 8 -4 16 16 8 +
1 3 -2 1 2 -1 4 4 2 +
-2 -6 4 -2 -4 2 -8 -8 -4 +
3 9 -6 3 6 -3 12 12 6 +
-----------------------------------------------------------------------------------------
3 7 -11 14 13 -15 28 6 -2 21 12 12 6 4

rxy(l) = {0,0,0,3,7,-11,14,13,-15,28,6,-2,21,12,12,6,4}

22
Result:
enter the sequence x(n)=[1 3 -2 1 2 -1 4 4 2]
enter the sequence y(n)=[3 -2 1 4 -1 2]
enter the starting index of x(n)=0
enter the starting index of y(n)=0
cross-correlation of x(n) and y(n) is

Rxy =

Columns 1 through 8

0.0000 0.0000 0.0000 2.0000 5.0000 -3.0000 17.0000 -4.0000

Columns 9 through 16

5.0000 31.0000 -6.0000 14.0000 26.0000 1.0000 6.0000 8.0000

Column 17

6.0000

Ex =

56

Ey =

35

Rxx =

Columns 1 through 8

2.0000 10.0000 12.0000 5.0000 -1.0000 19.0000 8.0000


15.0000

Columns 9 through 16

56.0000 15.0000 8.0000 19.0000 -1.0000 5.0000 12.0000


10.0000

Column 17

23
2.0000

Rxx_0 =

56

Ryy_0 =

35

Rxy[l]<=sqrt(Rxx_0*Ryy_0)=sqrt(Ex*Ey) -- proved

Ryx =

Columns 1 through 7

6.0000 8.0000 6.0000 1.0000 26.0000 14.0000 -6.0000

Columns 8 through 14

31.0000 -5.0000 -4.0000 17.0000 -3.0000 5.0000 2.0000

Columns 15 through 17

0.0000 0.0000 -0.0000

Rxy is even

24
4 4

2 2
amplitude

amplitude
0 0

-2 -2
0 2 4 6 8 0 2 4 6
x(n) n--> y(n) n-->

40
Cross Correlation
30

20

10

-10
-8 -6 -4 -2 0 2 4 6 8
Rxy l-->

25
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.07 Date: / /2020

Aim: Write a Matlab program for solving a given difference


equation.
y(n) + 3y(n-1) = x(n) with x(n) = u(n) and initial condition y(-1) = 1

clc;
close all;
disp('implementation of general difference equation');
b=input('enter the x(n) coefficient b=');
a=input('enter the y(n) coefficient a=');
x=input('enter the input samples x=');
yi=input('enter the initial conditions for y');
xi=input('enter the initial conditions for x');
zi= filtic( b,a,yi,xi);
y=filter(b,a,x,zi);
disp(y);
n=0:length(x)-1;
stem(n,y);
xlabel('samples n');
ylabel('y(n)');
grid on;
title('implementation of difference equation');

26
7. Solving a given difference equation

Difference equations are used to represent discrete-time systems. The


general form of a difference equation is,
N M
∑ aky(n-k) = ∑ bkx(n-k)
k=0 k=0
where x(n) is the input to the system and y(n) is the output of the system.
The integer N is known as the order of the difference equation.

Ex: Solve the following difference equation y(n) + 3y(n-1) = x(n)


With x(n) = u(n) and the initial condition y(-1) = 1

Solution: y(n) + 3y(n-1) = x(n)

Taking z-trans on both sides

Y(z) + 3[ y(-1) + z-1Y(z) ] = X(z)

We have x(n) = u(n)


1
X(z) = --------
1 – z-1
1
-1
Y(z) + 3[ 1+ z Y(z) ] = ---------
1 – z-1
-3 1
Y(z) = -------- + ---------------------
1+3z-1 (1+3z-1)( 1 – z-1)

By partial fraction expansion we get,


-3 ¾ ¼
Y(z) = -------- + ----------- + ----------
1+3z-1 (1+3z-1) (1 – z-1)
-9/4 ¼
Y(z) = -------- + ---------
1+3z-1 1 – z-1
Taking inverse Z-trans on both sides
y(n) = -9/4 (-3)n u(n) + ¼ u(n)
y(n) = [ ¼ - 9/4 (-3)n] u(n)

27
Result:
implementation of general difference equation
enter the x(n) coefficint b=[1]
enter the y(n) coefficint a=[1 3]
enter the input samples x=[1 1 1 1]
enter the initial conditons for y[1]
enter the initial conditons for x[0]
-2 7 -20 61

implementation of difference equation


70

60

50

40

30
y(n)

20

10

-10

-20
0 0.5 1 1.5 2 2.5 3
samples n

28
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.08a Date: / /2020

Aim: Write a Matlab program to find N point DFT of a given


sequence and to plot magnitude and phase spectrum.
x(n) = {1,1,2,2} for N=4 & 8

clc;
close all;
xn=input('enter the sequence x(n)=');
N=input('enter the value of N=');
n=0:N-1;
k=0:N-1;
disp('DFT of x(n) is');
Xk=fft(xn,N)

subplot(2,1,1);
stem(k,abs(Xk));
xlabel('k');
ylabel('magnitude of X(k)');
title('DFT of x(n)=X(k)');

phase=atan(imag(Xk)./real(Xk))*180/pi
subplot(2,1,2);
stem(k,phase);
xlabel('k');
ylabel('phase of X(k)');

29
8. Computation of N point DFT of a given sequence and to plot the
magnitude and phase spectrum

The N-point discrete Fourier transform (DFT) of a finite-length sequence


x[n], defined for 0 ≤ n ≤ N − 1, is given by

N−1
X[k] = ∑ x[n]WknN k= 0, 1, . . . , N − 1,
n=0
where WN = e−j2π/N.

IDFT:
N−1
x[n] =1/N ∑ X[k]W-knN n= 0, 1, . . . , N − 1,
k=0
where WN = e−j2π/N

30
Result:
enter the sequence x(n)=[0 1 2 3]
enter the value of N=4
DFT of x(n) is

Xk =

6.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i

mag =

6.0000 2.8284 2.0000 2.8284

phase =

0 -45 0 45

DFT of x(n)=X(k)
6

4
magnitude of X(k)

0
0 0.5 1 1.5 2 2.5 3
k

50
phase of X(k)

-50
0 0.5 1 1.5 2 2.5 3
k

31
Result:
enter the sequence x(n)=[0 1 2 3]
enter the value of N=8
DFT of x(n) is

Xk =

Columns 1 through 5

6.0000 -1.4142 - 4.8284i -2.0000 + 2.0000i 1.4142 - 0.8284i -


2.0000

Columns 6 through 8

1.4142 + 0.8284i -2.0000 - 2.0000i -1.4142 + 4.8284i

mag =

6.0000 5.0313 2.8284 1.6390 2.0000 1.6390 2.8284


5.0313

phase =

0 73.6751 -45.0000 -30.3612 0 30.3612 45.0000 -


73.6751

DFT of x(n)=X(k)
6

5
magnitude of X(k)

0
0 1 2 3 4 5 6 7
k

100

50
phase of X(k)

-50

-100
0 1 2 3 4 5 6 7
k

32
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.08b Date: / /2020

Aim: Write a Matlab program to find N point IDFT of a given


sequence and to plot magnitude and phase spectrum.
X(k) = {6,-1+j,0,-1-j} for N=4 & 8

clc;
close all;
Xk=input('enter the sequence X(k)=');
N=input('enter the value of N=');
n=0:N-1;
k=0:N-1;
disp('IDFT of X(k) is');
xn=ifft(Xk,N)

subplot(2,1,1);
stem(n,abs(xn));
xlabel('n');
ylabel('magnitude of x(n)');
title('IDFT of X(k)=x(n)');

subplot(2,1,2);
stem(n,angle(xn));
xlabel('n');
ylabel('phase of x(n)');

33
Result:
enter the sequence X(k)=[6 -2+2i -2 -2-2i]
enter the value of N=4
IDFT of X(k) is

xn =

0 1 2 3

IDFT of X(k)=x(n)
3

2.5

2
magnitude of x(n)

1.5

0.5

0
0 0.5 1 1.5 2 2.5 3
n

0.5
phase of x(n)

-0.5

-1
0 0.5 1 1.5 2 2.5 3
n

34
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.09 Date: / /2020

Aim: Write a Matlab program to find Linear convolution of two


given sequences Using DFT & IDFT.
x(n) = {1,2} and h(n) = {1,2,3}

clc;
close all;
xn=input('enter the sequence x(n)=');
xlen=length(xn);
hn=input('enter the sequence h(n)');
hlen=length(hn);
N=xlen+hlen-1;
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk.*Hk;
yn=ifft(Yk);
disp(yn);
n=0:1:N-1;
stem(n,yn);
xlabel('n-->');
ylabel('y(n)');
title('sequence resulting from linear convolution');

35
9. Linear convolution of two sequences using DFT and IDFT

Consider x(n) = {1,2} and h(n) = {1 2 3}

For linear convolution N = L + M - 1


Here L=2&M=3
N=2+3-1
=4
Zero pad N-L zeros to x(n) & N-M zeros to h(n)
Consider
x(n) = {1,2,0,0}
h(n) = {1,2,3,0}

DFT of x(n) X(k) = { 3, 1-2j, -1, 1+2j }


DFT of h(n) H(k) = { 6, -2-2j, 2, -2+2j }

DFT of y(n) be Y(k)


Y(k) = X(k).H(k)
Y(k) = { 18, -6+2j, -2, -6-2j }
IDFT of Y(k)
y(n) = { 1, 4, 7, 6}

36
Result:
enter the sequence x(n)=[1 2]
enter the sequence h(n)=[1 2 3]

xk =

3.0000 1.0000 - 2.0000i -1.0000 1.0000 + 2.0000i

hk =

6.0000 -2.0000 - 2.0000i 2.0000 -2.0000 + 2.0000i

yk =

18.0000 -6.0000 + 2.0000i -2.0000 -6.0000 - 2.0000i

linear convolution is

yn =

1 4 7 6

sequence resulting from linear convolution


7

4
y(n)

0
0 0.5 1 1.5 2 2.5 3
n-->

37
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.10 Date: / /2020

Aim: Write a Matlab program to find Circular convolution of two


given sequences Using DFT & IDFT.
x(n) = {2,1,2,1} and h(n) = {1,2,3,4} for N=4

clc;
close all;
N=input('enter the length of circular convolution N=');
xn=input('enter the sequence x(n)=');
xlen=length(xn);
hn=input('enter the sequence h(n)');
hlen=length(hn);
Xk=fft(xn,N);
Hk=fft(hn,N);
Yk=Xk.*Hk;
yn=ifft(Yk);
disp(yn);
n=0:1:N-1;
stem(n,yn);
xlabel('n-->');
ylabel('y(n)');
title('sequence resulting from circular convolution');

38
10. Circular convolution of two given sequences Using DFT & IDFT

DFT
If x(n) ←→ X(k)
DFT
And h(n) ←→ H(k)
DFT
Then x(n) N h(n) ←→ X(k) H(K)

Y(k) = X(k) H(k)

y(n) = IDFT{Y(k)}

Consider x(n) = { 2 1 2 1 } and h(n) = { 1 2 3 4} for N=4

X(k) = {6 0 2 0}
H(k) = {10 -2+2j -2 -2-2j}

Y(k) = X(k).H(k) = {60 0 -4 0}

IDFT of Y(k) y(n) = {14 16 14 16}

39
Result:
enter the length of circular convolution N=4
enter the sequence x(n)=[2 1 2 1]
enter the sequence h(n)=[1 2 3 4]
cricular convolution is
14 16 14 16

sequence resulting from circular convolution


16

14

12

10

8
y(n)

0
0 0.5 1 1.5 2 2.5 3
n-->

40
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12a Date: / /2020

Aim: Write a Matlab program to design Butterworth lowpass IIR


analog filter
% Given specifications are
% passband edge freq=1 kHz
% stopband edge freq=5 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db
clc;
close all;
clear all;
Omegap = 2*pi*1000;
Omegas = 2*pi*5000;
Ap = 1;
As = 40;
[N,Wn] = buttord(Omegap,Omegas,Ap,As,'s')
[num,den] = butter(N,Wn,'s');
printsys(num,den,'s')
omega = [0:200:12000*pi];
h = freqs(num,den,omega)
G = 20*log10(abs(h));
plot(omega/(2*pi),G);
xlabel('freq,Hz');
ylabel('Gain,db');
title('Butterworth lowpass IIR analog filter');

41
12a. Butterworth lowpass IIR analog filter
% Given specifications are
% passband edge freq=1 kHz
% stopband edge freq=5 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db

Ωp=2*pi*1000
Ωs=2*pi*5000
Ap=.1
As=40

Order N

1 log{(10.1As-1)/ (10.1Ap-1)}
N = --- ---------------------------------------
2 Log(Ωs/ Ωp)

N=4

Cut-off frequency

Ωc = Ωs/(10.1As-1)1/2N
Ωc = 9934.7 rad/sec

System Function Ha(s) :

(Ωc)N
Ha(s) = --------------------------------
(s-s1)(s-s1*)(s-s2)(s-s2*)

42
Result
N =4

Wn = 9.9347e+003

num/den = 9741396185386870
---------------------------------------------------------------
s^4 + 25960.6547 s^3 + 336977796.7754 s^2 +
2562277980262.151 s + 9741396185386870

Butterworth lowpass IIR analog filter


0

-5

-10

-15

-20
Gain,db

-25

-30

-35

-40

-45

-50
0 1000 2000 3000 4000 5000 6000
freq,Hz

43
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12b Date: / /2020

Aim: Write a Matlab program to design Butterworth lowpass IIR


digital filter using bilinear transformation
% Given specifications are
% passband edge freq=250 Hz
% stopband edge freq=550 Hz
% passband attenuation=.5 db
% stopband attenuation=15 db
% sampling frequency=2000 Hz
clc;
close all;
clear all;
Ap = .5;
As = 15;
fp = 250;
fs = 550;
ft = 2000;
Wp = 2*pi*fp/ft; %0.25pi
Ws = 2*pi*fs/ft; %0.55pi
Omegap = tan(Wp/2); %0.4142136
Omegas = tan(Ws/2); %1.1708496
[N,Wn] = buttord(Omegap,Omegas,Ap,As,'s')
[B,A] = butter(N,Wn,'s')
[num,den] = bilinear(B,A,.5);
printsys(num,den,'z');
omega = [0:.01:3];
h = freqz(num,den,omega);
G = 20*log10(abs(h));
plot(omega/pi,G);
xlabel('\omega/\pi,Hz');
ylabel('Gain,db');
title('Butterworth lowpass IIR digital filter');

44
12b. Butterworth lowpass IIR digital filter using Bilinear
transformation

%Given specifications are


% passband edge freq=250 Hz, % stopband edge freq=550 Hz
% passband attenuation=.5 db, % stopband attenuation=15 db
% sampling frequency=2000 Hz

Ap = .5;As = 15; Fp = 250; fs = 550; ft = 2000;


wp = 2*pi*fp/ft = 2*pi*250/2000 = 0.25pi
ws = 2*pi*fs/ft = 2*pi*550/2000 = 0.55pi

Specifications of equivalent analog filter for bilinear transformation:

Ωp = (2/T) tan(wp/2) = tan(.25pi/2) = 0.4142136


Ωs = (2/T) tan(ws/2) = tan(.55pi/2) = 1.1708496

Assume 2/T = 1

1 log{(10.1As-1)/ (10.1Ap-1)}
N = --- ---------------------------------------
2 Log(Ωs/ Ωp)
N=3
Ωc = Ωs/(10.1As-1)1/2N
Ωc = 0.6620 rad/sec

System Function Ha(s) :

(Ωc)N
Ha(s) = --------------------------------
(s-s1)(s-s1*)(s-s2)(s-s2*)

H(z) using bilinear transformation:


Apply bilinear transformation to Ha(s) to get H(z). Bilinear
transformation is given by
2 1-z-1
S= -- ------ Assume (2/T)=1
-1
T 1+z
So, in bilinear function we are passing 0.5
Applying transformation
Ha(z) = Ha(s)|s=1-z-1
-------
1+z-1

45
Result:

N=3

Wn = 0.6620
B= 0 0 0 0.2901

A= 1.0000 1.3239 0.8764 0.2901

num/den =

0.083103 z^3 + 0.24931 z^2 + 0.24931 z + 0.083103


-------------------------------------------------
z^3 - 0.73843 z^2 + 0.47844 z - 0.07518

Butterworth lowpass IIR digital filter


0

-10

-20

-30
Gain,db

-40

-50

-60

-70

-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/,Hz

46
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12c Date: / /2020

Aim: Write a Matlab program to design Butterworth highpass IIR


analog filter
% Given specifications are
% passband edge freq=4 kHz
% stopband edge freq=1 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db
clc;
close all;
clear all;
Ap = .1;
As = 40;
Fp = 4000;
Fs = 1000;
Omegap = 2*pi*Fp;
Omegas = 2*pi*Fs;
Omegapn = 1;
Omegasn = Omegap/Omegas;
[N,Wn] = buttord(Omegapn,Omegasn,Ap,As,'s')
[B,A] = butter(N,Wn,'s');
[num,den] = lp2hp(B,A,Omegap);
printsys(num,den,'s');
omega = [2600:200:12000*pi];
h = freqs(num,den,omega);
G = 20*log10(abs(h));
plot(omega/(2*pi),G);
xlabel('freq,Hz');
ylabel('Gain,db');
title('Butterworth highpass IIR analog filter');

47
12c. Butterworth highpass IIR analog filter

%Given specifications are


% passband edge freq=4 kHz, % stopband edge freq=1 kHz
% passband attenuation=0.1 db, % stopband attenuation=40 db
Ap=0.1
As=40
Ωp=2*pi*4000
Ωs=2*pi*1000

First create prototype lowpass filter


Ωpn = 1 rad/sec
Ωsn = Ωp/ Ωs = (2*pi*4000)/(2*pi*1000) = 4

Order N

1 log{(10.1As-1)/ (10.1Ap-1)}
N = --- ---------------------------------------
2 Log(Ωs/ Ωp)

N=5

Cut-off frequency

Ωc = Ωs/(10.1As - 1)1/2N = 4/(10.1*40 – 1) 1(2*5)


Ωc = 1.5924 rad/sec

System Function Ha(s) :

Normalized prototype lowpass butterworth filter system function:


1
Han(s) = ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1

let us use lowpass to highpass frequency transformation

s → Ωp ΩHp
-----------
s
System function of highpass filter is given as
HHP = Han(s)|s→ Ωp ΩHp
-----------
s

48
Result:

N= 5

Wn = 1.5924

num/den =

s^5 - 1.4304e-012 s^4 - 5.1402e-007 s^3 - 0.0090657 s^2 - 3.1636 s

+ 0.00059326
------------------------------------------------------------------
s^5 + 51073.2108 s^4 + 1304236429.337 s^3 + 20584098516049.44
s^2

+ 200779670279706940 s + 979214026939196640000

Butterworth highpass IIR analog filter


0

-10

-20

-30
Gain,db

-40

-50

-60

-70

-80
0 1000 2000 3000 4000 5000 6000
freq,Hz

49
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12d Date: / /2020

Aim: Write a Matlab program to design Butterworth highpass IIR


digital filter using bilinear transformation
% Given specifications are
% passband edge freq=700 Hz
% stopband edge freq=500 Hz
% passband attenuation=1 db
% stopband attenuation=32 db
% Sampling freq=2 KHz
clc;
close all;
clear all;
Ap = 1;
As = 32;
Fp = 700;
Fs = 500;
Ft = 2000;
Wp = 2*pi*Fp/Ft;
Ws = 2*pi*Fs/Ft;
Omegap = tan(Wp/2);
Omegas = tan(Ws/2);
Omegapn = 1; %prototype analog lowpass filter
Omegasn = Omegap/Omegas; %prototype analog lowpass filter
[N,Wn] = buttord(Omegapn,Omegasn,Ap,As,'s')
[B,A] = butter(N,Wn,'s');
[BT,AT] = lp2hp(B,A,Omegap);
[num,den] = bilinear(BT,AT,.5);
printsys(num,den,'z');
omega = [1:.01:3.5];
h = freqz(num,den,omega);
plot(omega/pi,20*log10(abs(h)));
xlabel('\omega/\pi,Hz');
ylabel('Gain,db');
title('Butterworth highpass IIR digital filter');

50
12d. Butterworth highpass IIR digital filter using bilinear
transformation
%Given specifications are
% passband edge freq=700 Hz
% stopband edge freq=500 Hz
% passband attenuation=1 db
% stopband attenuation=32 db
% Sampling freq=2 KHz

Ap=1
As=32
Fp=700
Fs=500
Ft=2000
wp=2*pi*Fp/Ft = 2*pi*700/2000 = 0.7pi
ws=2*pi*Fs/Ft = 2*pi*500/2000 = .5pi

Specifications of equivalent analog filter for bilinear transformation:

Ωp=tan(wp/2) = tan(.7pi/2) = 1.9626


Ωs=tan(ws/2) = tan(.5pi/2) = 1.0000

First create prototype lowpass filter

Ωpn = 1
Ωsn = Ωp/Ωs = 1.9626/1 = 1.9626

Order N

1 log{(10.1As-1)/ (10.1Ap-1)}
N = --- ------------------------------------
2 Log(Ωs/ Ωp)

N=7

Cut-off frequency

Ωc = Ωs/(10.1As - 1)1/2N = 1.9626/(10.1*32 – 1) 1(2*7)


Ωc = 1.1595 rad/sec

System Function Ha(s) :

51
Normalized prototype lowpass butterworth filter system function:
1
Han(s) = ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1

let us use lowpass to highpass frequency transformation

s → Ωp ΩHp
-----------
s

System function of highpass filter is given as


HaHP = Han(s)|s→ Ωp ΩHp
-----------
s

H(z) using bilinear transformation:


Apply bilinear transformation to Ha(s) to get H(z). Bilinear
transformation is given by
2 1-z-1
S= -- ------ Assume (2/T)=1
-1
T 1+z

So, in bilinear function we are passing 0.5


Applying transformation
HaHP(z) = Ha(s)|s=1-z-1
-------
1+z-1

52
Result:

N=7

Wn = 1.1595

num/den =

0.0019463 z^7 - 0.013624 z^6 + 0.040872 z^5 - 0.068121 z^4 +


0.068121 z^3

- 0.040872 z^2 + 0.013624 z - 0.0019463


-------------------------------------------------------------------------
z^7 + 2.2284 z^6 + 2.8686 z^5 + 2.2275 z^4 + 1.1426 z^3 + 0.37092
z^2

+ 0.07069 z + 0.0059961

Butterworth highpass IIR digital filter


0

-10

-20

-30
Gain,db

-40

-50

-60

-70
0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3
/,Hz

53
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12e Date: / /2020

Aim: Write a Matlab program to design Type-I chebyshev lowpass IIR


analog filter
%Given specifications are
% passband edge freq=1 kHz
% stopband edge freq=5 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db
clc;
close all;
clear all;
Ap = 1;
As = 40;
Omegap = 2*pi*1000;
Omegas = 2*pi*5000;
[N,Wn] = cheb1ord(Omegap,Omegas,Ap,As,'s')
[num,den] = cheby1(N,Ap,Wn,'s');
printsys(num,den,'s');
omega = [0:200:12000*pi];
h = freqs(num,den,omega);
G = 20*log10(abs(h));
plot(omega/(2*pi),G);
xlabel('freq,Hz');
ylabel('Gain,db');
title('Type-I chebyshev lowpass IIR analog filter');

54
12e. Type-I chebyshev lowpass IIR analog filter
% Given specifications are
% passband edge freq=1 kHz
% stopband edge freq=5 kHz
% passband attenuation=1 db
% stopband attenuation=40 db

Ωp=2*pi*1000
Ωs=2*pi*5000
Ap=1
As=40

Order N:

Cosh-1{(10.1As-1)/ (10.1Ap-1)}1/2
N = ---------------------------------------
Cosh-1(Ωs/ Ωp)

N=3

r = Minor axis of ellipse R = Major axis of ellipse

r = Ωp (β2 – 1)/2 β R = Ωp (β2 + 1)/2 β

β = {(√(1+ ε2) + 1)/ ε}1/N

The pole positions are


Sk = rcosΦk + jRsinΦk

& Φk = Π + (2k+1) Π
--- -------------- k = 0,1,2……N-1
2 2N
Transfer function is
k
Ha(s) = ----------------------------------
(s-s1)(s-s2)……….(s-sN)

k
= ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1
& k = bo for N odd
k = bo/√(1+ ε2) for N even

55
Result:

N= 3
Wn = 6.2832e+003

num/den =

121868727358.1179
--------------------------------------------------------
s^3 + 6209.931 s^2 + 48890434.5196 s + 121868727358.1179

Type-I chebyshev lowpass IIR analog filter


0

-10

-20
Gain,db

-30

-40

-50

-60
0 1000 2000 3000 4000 5000 6000
freq,Hz

56
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12f Date: / /2020

Aim: Write a Matlab program to design Type-I Chebyshev lowpass IIR


digital filter using bilinear transformation
%Given specifications are
% passband edge freq=250 Hz
% stopband edge freq=550 Hz
% passband attenuation=1 db
% stopband attenuation=15 db
% sampling frequency = 2 khz
clc;
close all;
clear all;
Ap = 1;
As = 15;
fp =250;
fs = 550;
ft = 2000;
Wp = 2*pi*fp/ft; %0.25pi
Ws=2*pi*fs/ft; %0.55pi
Omegap = tan(Wp/2) %0.4142136
Omegas = tan(Ws/2) %1.1708496
[N,Wn] = cheb1ord(Omegap,Omegas,Ap,As,'s')
[B,A] = cheby1(N,Ap,Wn,'s');
[num,den] = bilinear(B,A,.5);
printsys(num,den,'z');
omega = [0:.01:3];
h = freqz(num,den,omega);
G = 20*log10(abs(h));
plot(omega/pi,G);
xlabel('\omega/\pi,Hz');
ylabel('Gain,db');
title('Type-I chebyshev lowpass IIR digital filter');

57
12f. Type-I Chebyshev lowpass IIR digital filter using bilinear
transformation

%Given specifications are


% passband edge freq=250 Hz
% stopband edge freq=550 Hz
% passband attenuation=1 db
% stopband attenuation=15 db
% sampling frequency = 2 khz

Ap = 1;
As = 15;
Fp = 250;
fs = 550;
ft = 2000;
wp = 2*pi*fp/ft = 2*pi*250/2000 = 0.25pi
ws = 2*pi*fs/ft = 2*pi*550/2000 = 0.55pi

Specifications of equivalent analog filter for bilinear transformation:

Ωp = (2/T) tan(wp/2) = tan(.25pi/2) = 0.4142136


Ωs = (2/T) tan(ws/2) = tan(.55pi/2) = 1.1708496

Assume 2/T = 1

Cosh-1{(10.1As-1)/ (10.1Ap-1)}1/2
N = ---------------------------------------
Cosh-1(Ωs/ Ωp)

System Function Ha(s) :

r = Minor axis of ellipse R = Major axis of ellipse

r = Ωp (β2 – 1)/2 β R = Ωp (β2 + 1)/2 β

β = {(√(1+ ε2) + 1)/ ε}1/N

The pole positions are


Sk = rcosΦk + jRsinΦk

& Φk = Π + (2k+1) Π
--- -------------- k = 0,1,2……N-1
2 2N

58
Transfer function is
k
Ha(s) = ----------------------------------
(s-s1)(s-s2)……….(s-sN)

k
= ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1
& k = bo for N odd
k = bo/√(1+ ε2) for N even

H(z) using bilinear transformation:


Apply bilinear transformation to Ha(s) to get H(z). Bilinear
transformation is given by
2 1-z-1
S= -- ------ Assume (2/T)=1
-1
T 1+z

So, in bilinear function we are passing 0.5


Applying transformation
Ha(z) = Ha(s)|s=1-z-1
-------
1+z-1

59
Result:

Omegap = 0.4142

Omegas = 1.1708
`
N =2

Wn = 0.4142

num/den =

0.10256 z^2 + 0.20511 z + 0.10256


---------------------------------
z^2 - 0.98651 z + 0.44679

Type-I chebyshev lowpass IIR digital filter


0

-10

-20

-30
Gain,db

-40

-50

-60

-70
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
/,Hz

60
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12g Date: / /2020

Aim: Write a Matlab program to design Type-I Chebyshev highpass


IIR analog filter
%Given specifications are
% passband edge freq=4 kHz
% stopband edge freq=1 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db
clc;
close all;
clear all;
Ap = .1;
As = 40;
Fp = 4000;
Fs = 1000;
Omegap = 2*pi*Fp;
Omegas = 2*pi*Fs;
Omegapn = 1;
Omegasn = Omegap/Omegas;
[N,Wn] = cheb1ord(Omegapn,Omegasn,Ap,As,'s')
[B,A] = cheby1(N,Ap,Wn,'s');
[num,den] = lp2hp(B,A,Omegap);
printsys(num,den,'s');
omega = [2600:200:12000*pi];
h = freqs(num,den,omega);
G = 20*log10(abs(h));
plot(omega/(2*pi),G);
xlabel('freq,Hz');
ylabel('Gain,db');
title('Type-I chebyshev highpass IIR analog filter');

61
12g.Type-I Chebyshev highpass IIR analog filter

%Given specifications are


% passband edge freq=4 kHz
% stopband edge freq=1 kHz
% passband attenuation=.1 db
% stopband attenuation=40 db

Ap=0.1
As=40
Ωp=2*pi*4000
Ωs=2*pi*1000

First create prototype lowpass filter


Ωpn = 1 rad/sec

Ωsn = Ωp/ Ωs = (2*pi*4000)/(2*pi*1000) = 4

Cosh-1{(10.1As-1)/ (10.1Ap-1)}1/2
N = ---------------------------------------
Cosh-1(Ωs/ Ωp)

Transfer function is

k
Ha(s) = ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1
& k = bo for N odd
k = bo/√(1+ ε2) for N even

System function of highpass filter is given as


HHP = Han(s)|s→ Ωp ΩHp
-----------
s

62
Result:

N=4

Wn = 1

num/den =

0.98855 s^4 + 6.8325e-008 s^3 + 2.777e-007 s^2 + 1.9198e-014 s

- 2.9617e-020
----------------------------------------------------------------
s^4 + 61443.3445 s^3 + 2002668018.3419 s^2 + 34562406189280.35 s

+ 481572930645911940

Type-I chebyshev highpass IIR analog filter


0

-10

-20

-30

-40
Gain,db

-50

-60

-70

-80

-90
0 1000 2000 3000 4000 5000 6000
freq,Hz

63
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.12h Date: / /2020

Aim: Write a Matlab program to design Type-I Chebyshev highpass


IIR digital filter using bilinear transformation
%Given specifications are
% passband edge freq = 700 Hz
% stopband edge freq = 500 Hz
% passband attenuation = 1 db
% stopband attenuation = 32 db
% sampling frequency = 2 khz
clc;
close all;
clear all;
Ap = 1;
As = 32;
Fp = 700;
Fs = 500;
Ft = 2000;
Wp = 2*pi*Fp/Ft;
Ws = 2*pi*Fs/Ft;
Omegap = tan(Wp/2);
Omegas = tan(Ws/2);
Omegap1 = 1
Omegas1 = Omegap/Omegas
[N,Wn] = cheb1ord(Omegap1,Omegas1,Ap,As,'s')
[B,A] = cheby1(N,Ap,Wn,'s');
[BT,AT] = lp2hp(B,A,Omegap);
[num,den] = bilinear(BT,AT,.5);
printsys(num,den,'z');
omega = [1:.01:3.5];
h = freqz(num,den,omega);
plot(omega/pi,20*log10(abs(h)));
xlabel('\omega/\pi,Hz');
ylabel('Gain,db');
title('Type-I chebyshev highpass IIR digital filter');

64
12h.Type-I Chebyshev highpass IIR digital filter using bilinear
transformation
%Given specifications are
% passband edge freq = 700 Hz
% stopband edge freq = 500 Hz
% passband attenuation = 1 db
% stopband attenuation = 32 db
% sampling frequency = 2 khz

Ap=1
As=32
Fp=700
Fs=500
Ft=2000
wp=2*pi*Fp/Ft = 2*pi*700/2000 = 0.7pi
ws=2*pi*Fs/Ft = 2*pi*500/2000 = .5pi

Specifications of equivalent analog filter for bilinear transformation:

Ωp=tan(wp/2) = tan(.7pi/2) = 1.9626


Ωs=tan(ws/2) = tan(.5pi/2) = 1.0000

First create prototype lowpass filter

Ωpn = 1
Ωsn = Ωp/Ωs = 1.9626/1 = 1.9626

Order N
Cosh-1{(10.1As-1)/ (10.1Ap-1)}1/2
N = ---------------------------------------
Cosh-1(Ωs/ Ωp)
Transfer function is

k
Ha(s) = ------------------------------------
sN + bN-1sN-1 +……+ b1s + 1
& k = bo for N odd
k = bo/√(1+ ε2) for N even
System function of highpass filter is given as
HHP = Han(s)|s→ Ωp ΩHp
-----------
s
H(z) using bilinear transformation:

65
Apply bilinear transformation to Ha(s) to get H(z). Bilinear
transformation is given by
2 1-z-1
S= -- ------ Assume (2/T)=1
-1
T 1+z

So, in bilinear function we are passing 0.5


Applying transformation
HaHP(z) = Ha(s)|s=1-z-1
-------
1+z-1

66
Result:

Omegap1 = 1

Omegas1 = 1.9626

N=4

Wn = 1

num/den =

0.0083632 z^4 - 0.033453 z^3 + 0.050179 z^2 - 0.033453 z +


0.0083632
--------------------------------------------------------------------
z^4 + 2.3741 z^3 + 2.7057 z^2 + 1.5917 z + 0.41032

Type-I chebyshev highpass IIR digital filter


0

-10

-20
Gain,db

-30

-40

-50

-60
0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3
/,Hz

67
DSP KIT PROCEDURE

1. To test the DSP starter kit double click on 6713 dsk diagnostic icon
which is displayed on the desk top. click on start it tests the
USB diagnostics,external memory,DSP memory,LED memory,
codec diagnostics,flash diagnostics,emulation diagnostics.
After testing it displays the diagnostic status pass,click on stop
close the window.
2. To start the code composer studio double click on 6713 DSK
CC studio_v 3.1 icon on the desk top.
Select the debug option in that we have to select connect which
Connects DSK boardto the system.
3. Start a new project using ‘project- new’
Target type – executable(.out)
Target – TMS 320 C67XX
Finish
4. Select file option in that new, source file .we have to write the
program and save it in a separate directory(c:\cc studio_v3.1\my
projects) with extension dot c(.c).
Dragout the project right click on source add file to project select the
file name c:\ cc studio_v3.1\my projects(in the form of note pad).
5. Add the linker command file hello.cmd right click on library
(path: c:\cc studio_v3.1\tutorial\dsk 6713\hello1\ hello.cmd files of
type linker command file)
6. Add the run time support library file rts 6700.lib right click on
library(path: c:\cc studio_v3.1\c6000\cg tools\lib\rts 6700.lib)
7. Compile the program using the
Project -- pull down the menu select compile option.
8. Build the program using the
Project -- pull down the menu select build option.
9. Load the program in program memory of DSP chip using the file--
pull down the menu select load program.
10.Select debug double click file name .out.
Select the debug option pull down the menu run the program.
It displays the result.
11.To view the output graphically
Select the view option
Graph – time/frequency
Start address – ‘y’(o/p program variable)
Display data size – 16 bit unsigned integer
Data plot style – line(curve) or bar(discrete) .

68
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.1 Date: / /2020

Aim: Write a C program to find linear convolution of two given


sequences

#include<stdio.h>
int y[10];
void main( )
{
int L = 4;
int M = 4;
int n,k;
int x[10] = {2,1,1,2,0,0,0,0};
int h[10] = {1,-1,-1,1,0,0,0,0};
for(n = 0; n<L+M-1; n++)
{
y[n] = 0;
for(k=0; k<=n; k++)
y[n]+= x[k] *h[n-k];
}
printf("linear convolution is\n");
for(n = 0; n<L+M-1; n++)
printf("%d\n",y[n]);
}

69
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.2 Date: / /2020

Aim: Write a C program to find Circular convolution of two given


sequences

#include<stdio.h>
int y[30];
void main( )
{
int N1,N2,x[30],h[30],i,j,n,N;

printf("enter the length of first sequence\n");


scanf("%d",&N1);
printf("enter the length of the second sequence\n");
scanf("%d",&N2);
printf("enter N=");
scanf("%d",&N);
printf("enter the Ist sequence\n");
for(i=0;i<N1;i++)
scanf("%d",&x[i]);
printf("enter the IInd sequence\n");
for(j=0;j<N2;j++)
scanf("%d",&h[j]);
if(N-N2!=0)
{
for(i=N2;i<N;i++)
h[i]=0;
}
if(N-N1!=0)
{
for(i=N1;i<N;i++)
x[i]=0;
}
for(n=0;n<=N-1;n++)
{
y[n]=0;
for(i=0;i<=N-1;i++)
{
j=n-i;
if(j<0)

70
j=N+j;
y[n]=y[n]+x[i]*h[j];
}
}
printf("Circular Convolution is\n");
for(i=0;i<N;i++)
printf("%d\t",y[i]);
}

71
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.3 Date: / /2020

Aim: Write a C program to find DFT of given sequence.

#include<stdio.h>
#include<math.h>
void main()
{
int N=8,n,k;
float x[8]={1,1,1,1,0,0,0,0};
float pi = 3.1416;
float sumre, sumim;
float cosine =0,sine=0;
float out_real[8],out_imag[8];

printf("DFT X(k) is\n");


for(k=0;k<N;k++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
cosine = cos(2*pi*k*n/N);
sine = sin(2*pi*k*n/N);
sumre = sumre + x[n]*cosine;
sumim = sumim - x[n]*sine;
}
out_real[k] = sumre;
out_imag[k] = sumim;
printf("%.4f %.4fi\n",out_real[k],out_imag[k]);
}
}

72
GURU NANAK DEV ENGG. COLLEGE, BIDAR
EEE DEPARTMENT
Class: 6th sem Sub:DSP Lab Sub Code:18EEL67
Exp. No.4 Date: / /2020

Aim: Write a C program to find Impulse response of given system.


Given first order difference equation a0y(n)+a1y(n-1)=b0x(n)+b1x(n-1)
Ex: y(n)-y(n-1)=x(n)+x(n-1)

#include<stdio.h>
#define order 1
#define len 4

float y[len],sum;

void main()
{
int n,k;
float a[order+1]={1,-1};
float b[order+1]={1,1};

for(n=0;n<len;n++)
{
sum=0;
for(k=1;k<=order;k++)
{
if((n-k)>=0)
sum=sum+(a[k]*y[n-k]);
}
if(n<=order)
y[n]=b[n]-sum;
else
y[n]=-sum;

printf("response[%d] =%f\n",n,y[n]);
}
}
VIVA QUESTIONS
Q1)State sampling theorem and write the condition for
reconstruction of analog signals.

73
2)What should be the minimum sampling frequency for
reconstruction.
3)What is sampling frequency.
4)Why sampling is required?
5)What is impulse response of a system?
6)What is the importance of impulse response?
7)Write the expression for circular convolution.
8) Write the circular convolution equation in matrix form.
9)What is zero padding?
10)What is the condition to evaluate linear convolution from circular
convolution?
11)What is DFT?Write the expression for it.
12)Why computation of DFT is required?
13)Write time shift property of DFT.
14)Write frequency shift property of DFT.
15)How a digital filter differs from an analog filter?
16)What is an IIR filter?
17)What is an FIR filter?
18)What is order of a filter.
19)Advantages of digital filter.
20)What is frequency transformation?
21)When a digital filter(system) is said to be stable.
22)What are all pole filters.
23)What is Butterworth characteristic?
24)Write the equation to find the order of a chebyshev filter.
25)Typical specifications required to design a digital filter.
26)What is a cascade structure?
27)What is a parallel structure?
28)What is periodic convolution?

74
29)Give examples of one dimensional signals.
30)Examples of two dimensional signals.

75
Digital Signal Processing Lab(18EEL67)
List of Experiments

1)Verification of sampling theorem.


2)Evaluation of impulse response of asystem.
3)To perform linear convolution of given sequences.
4)To perform circular convolution of given sequences using.
5)Computation of N point DFT and plot magnitude and phase
spectrum.
6)Linear and circular convolution by DFT and IDFT.
7)Solution of a given difference equation.
8)Calculation of DFT IDFT by FFT.
9)Design and implementation of FIR filters to meet given
specifications(low pass, high pass, band pass, band reject) using
different windowing functions.
10) Design and implementation of IIR filters to meet given
specifications(low pass, high pass, band pass, band reject).
11)Realization of IIR and FIR filters.

CONTENT BEYOND SYLLABUS


1)Assess the stability of a given digital IIR filter based on the location
of poles in Z plane.
2)Write a program to determine the order of a given chebyshev filter
for given specifications.

76

You might also like