0% found this document useful (0 votes)
21 views39 pages

DSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views39 pages

DSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT

OF ELECTRONICS & COMMUNICATION

LAB RECORD

Lab Name : Digital Signal Processing

Branch : Electronics & Communications Engineering

Year : IIIrd Year

Jaipur Engineering College and Research Center, Jaipur


Department of Electronics & Communication
(Rajasthan Technical University, KOTA)

ECE/LAB MANUAL/DSPLAB Page 1


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 1

AIM: Generation of continuous and discrete elementary signals (Periodic and non periodic) using
mathematical expression.

Software requirement: - SCI LAB

Theory: A wave is a disturbance that transfers energy from one place to another without requiring any
net flow of mass. Waves can be broadly separated into pulses and periodic waves. A pulse is a single
disturbance while a periodic wave is a continually oscillating motion. There is a close connection
between simple harmonic motion and periodic waves; in most periodic waves, the particles in the
medium experience simple harmonic motion.

Waves can also be separated into transverse and longitudinal waves. In a transverse wave, the motion
of the particles of the medium is at right angles (i.e., transverse) to the direction the wave moves. In a
longitudinal wave, such as a sound wave, the particles oscillate along the direction of motion of the
wave.

Surface waves, such as water waves, are generally a combination of a transverse and a longitudinal
wave. The particles on the surface of the water travel in circular paths as a wave moves across the
surface.

Periodic waves

A periodic wave generally follows a sine wave pattern, as shown in the diagram.

ECE/LAB MANUAL/DSPLAB Page 2


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM CODE

//continous time cosine //discrete time cosine


signal t=-5:0.01:5; y1=cos(t); signal n = -20:.01:20;
subplot(3,2,1); plot2d3(t,y); y4=cos(n); subplot(3,2,2);
xlabel('Time'); plot2d3(n,y4);
ylabel('Magnitude'); xlabel('Time');
title('continous time cosine signal'); ylabel('Magnitude');
title('discrete time cosine signal');
//continous time sine
signal y2=sin(t); //discrete time sine signal
subplot(3,2,3); y5=sin(n); subplot(3,2,4);
plot2d3(t,y2); plot2d3(n,y5);
xlabel('Time'); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('continous time sine signal'); title('discrete time sine signal');

//continous time aperiodic //discrete time aperiodic signal


signal y3=sin(2*F*t*pi).*t; y6=cos(2*f*n*pi).*n;
subplot(3,2,5); plot2d3(t,y3); subplot(3,2,6);
xlabel('Time'); plot2d3(n,y6); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('continous time aperiodic signal'); title('discrete time aperiodic signal');

ECE/LAB MANUAL/DSPLAB Page 3


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure (Expected output):

Figure 2.2 Continuous and Discrete Time Elementary Signals

PROGRAM 2

AIM: Generation of Continuous and Discrete Unit Step Signal.

Software requirement: - SCI LAB

ECE/LAB MANUAL/DSPLAB Page 4


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Unit step: A signal with magnitude one for time greater than zero. We can assume it as a dc signal which
got switched on at time equal tozero.

Unit step function is denoted by u (t). It is defined as u (t) =

Figure 2.3Continuous Time Unit Step Signal

• It is used as best test signal.


• Area under unit step function is unity.

ECE/LAB MANUAL/DSPLAB Page 5


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

t=-10:1:10; n=-10:1:10;
y1=[zeros(1,10),ones(1,11)]; y7=[zeros(1,10),ones(1,11)];
subplot(4,3,1); subplot(4,3,7);
plot2d3(t,y1); xlabel('Time'); plot2d3(n,y7); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('Continuous Unit Step Function'); title('discrete Unit Step u(n) Function');

y2=[zeros(1,16),ones(1,5)]; y8=[zeros(1,16),ones(1,5)];
subplot(4,3,2); subplot(4,3,8);
plot2d3(t,y2); xlabel('Time'); plot2d3(n,y8); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('Continuous Unit Step u(t-6) Function'); title('discrete Unit Step u(n-6) Function');

y3=[zeros(1,4),ones(1,17)]; y9=[zeros(1,4),ones(1,17)];
subplot(4,3,3); subplot(4,3,9);
plot2d3(t,y3); xlabel('Time'); plot2d3(n,y9); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('Continuous Unit Step u(t+6) Function'); title('discrete Unit Step u(n+6) Function');

y4=[zeros(1,6),ones(1,15)]; y10=[zeros(1,6),ones(1,15)];
subplot(4,3,4); subplot(4,3,10);
plot2d3(t,y4); xlabel('Time'); plot2d3(n,y10); xlabel('Time');
ylabel('Magnitude'); ylabel('Magnitude');
title('Continuous Unit Step u(-t+4) Function'); title('discrete Unit Step u(-n+4) Function');

y5 = y3 - y2; y11 = y9 - y8; subplot(4,3,11);


subplot(4,3,5); plot2d3(n,y11); xlabel('Time');
plot2d3(t,y5); ylabel('Magnitude');
xlabel('Time'); title('discrete Unit Step u(n+6)-u(n-6) Function');
ylabel('Magnitude');
title('Continuous Unit Step u(t+6)-u(t-6) Function');
y12 = y9 + y8;
subplot(4,3,12);
y6 = y3 + y2; plot2d3(n,y12); xlabel('Time');
subplot(4,3,6); ylabel('Magnitude');
plot2d3(t,y6); title('discrete Unit Step u(n+6)+u(n-6) Function');
xlabel('Time');
ylabel('Magnitude');
title('Continuous Unit Step u(t+6)+u(t-6) Function');

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 6


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 2.4 Continuous and Discrete Unit Step Signals

VIVA VOICE QUESTION:


PROGRAM 3

AIM: Adding and subtracting two given signals (continuous as well as discrete signals).

ECE/LAB MANUAL/DSPLAB Page 7


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Software requirement: - SCI LAB


PROGRAM CODE
clc; //discrete
//continuous signal signal
t = 0:0.001:30; n=0:1:30; a=n;
y1 = t; y2 = 2*t; b=2*n;
//First Signal //First Signal
subplot(4,2,1); subplot(4,2,5);
plot2d3(t,y1); plot2d3(n,a);
xlabel('time'); xlabel('time');
ylabel('magnitude') ylabel('magnitude');
; title('First Signal');
title('First Signal'); //Second Signal
//Second Signal subplot(4,2,6);
subplot(4,2,2); plot2d3(n,b);
plot2d3(t,y2); xlabel('time');
xlabel('time'); ylabel('magnitude');
ylabel('magnitude'); title('Second Signal');
title('Second Signal'); c=a+b;
y3 = y1+y2; y4 = d=a-b; //Addition
y1-y2; //Addition subplot(4,2,7);
subplot(4,2,3); plot2d3(n,c);
plot2d3(t,y3); xlabel('time');
xlabel('time'); ylabel('magnitude')
ylabel('magnitude') ; title('Addition');
; title('Addition'); //subtraction
//subtraction subplot(4,2,8);
subplot(4,2,4); plot2d3(n,d);
plot2d3(t,y4); xlabel('time');
xlabel('time'); ylabel('magnitude')
ylabel('magnitude') ;
; title('Subtraction');
title('Subtraction');

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 8


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 3.1 Continuous and Discrete Signals with addition and subtraction

ECE/LAB MANUAL/DSPLAB Page 9


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 4

AIM: Continuous and Discrete Time Convolution (Using Basic Definition).

Software requirement: - SCI LAB

Theory: A convolution is an integral that expresses the amount of overlap of one function as it is
shifted over another function.It therefore "blends" one function with another. For example, in
synthesis imaging, the measured dirty map is a convolution of the "true" CLEAN map with the
dirty beam (the FOURIER TRANSFORM of the sampling distribution). The convolution is
sometimes also known by its German name, faltung ("folding").

Abstractly, a convolution is defined as a product of functions and that are objects in the algebra
of SCHWARTZ FUNCTIONS in. Convolution of two functions and over a finite range is given
by

Where the symbol denotes convolution of and .

Convolution is more often taken over an infinite range,

ECE/LAB MANUAL/DSPLAB Page 10


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

(4A) (4B) (4C)


x=input('enter first sequence'); x = input('enter the first seq');
b1=input('enter the lower N1 = length(x); n1
limit'); u1=input('enter the t1=-5:1:0 = 0:1:N1-1;
upper limit'); t2=0:1:2; t3=2:1:5; subplot(2,2,1);
x1=b1:1:u1; plot2d3(n1,x);
h=input('enter second h1=zeros(size(t1)); xlabel('time');
sequence'); b2=input('enter the h2=ones(size(t2)); ylabel('mag');
lower limit'); u2=input('enter the h3=zeros(size(t3)); title('seq of x');
upper limit');
h1=b2:1:u2; t=[t1 t2 t3]; h = input('enter the second
b=b1+b2; h=[h1 h2 h3]; seq');
u=u1+u2; a=b:1:u; subplot(3,1,1); N2 = length(h); n2
m=length(x); plot2d3(t,h); = 0:1:N2-1;
n=length(h); xlabel('time'); subplot(2,2,2);
X=[x,zeros(1,n)]; ylabel('magnitude'); plot2d3(n2,h);
subplot(2,2,1); xlabel('time');
disp('x(n) is:'); ylabel('mag');
disp(x); a1=-5:1:0;
a2=0:1:4; title('seq of h');
plot2d3(x1,x);
xlabel('n'); a3=4:1:6;
y=conv(x,h); n =
ylabel('x(n)');
title('first x1=zeros(size(a1)); 0:1:N1+N2-2;
squence'); grid on; x2=ones(size(a2)); subplot(2,2,[3 4]);
H=[h,zeros(1,m)]; x3=zeros(size(a3)); plot2d3(n,y);
subplot(2,2,2); xlabel('time');
disp('h(n) is;'); a=[a1 a2 a3]; x=[x1 ylabel('mag');
disp(h); plot2d3(h1,h); x2 x3]; title('convolution');
xlabel('n'); subplot(3,1,2);
ylabel('h(n)'); plot2d3(a,x);
title('second xlabel('time');
sequence'); grid on; for ylabel('magnitude');
i=1:n+m-1 Y(i)=0;
for j=1:m; if((i-j+1)>0)
Y(i)=Y(i)+(X(j)*H(i-j+1)); else c=conv(x2,h2);
end end end subplot(3,1,3);
subplot(2,2,[3 4]); plot2d3(c); xlabel('time');
disp('y(n) is:'); ylabel('magnitude');
disp(Y); plot2d3(a,Y);
xlabel('n');
ylabel('Y(n)');
title('output
sequence'); grid on;

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 11


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 4(a):

Figure 4.1 Discrete Time Sequence along with Convolution

Input & Output


enter first sequence:=[-2 -4 5 6]
enter the lower limit:=-1 enter
the upper limit:=2 enter second
sequence:=[3 4 5] enter the
lower limit:=0 enter the upper
limit:=2 x(n) is:
-2 -4 5 6

h(n) is;
3 4 5

y(n) is:
-6 -20 -11 18 49 30 38 24

ECE/LAB MANUAL/DSPLAB Page 12


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 4(b):

Figure 4.2Continuous Signals along with Convolution

ECE/LAB MANUAL/DSPLAB Page 13


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 4(c):

Input:
enter the first seq:=[0 1 2 3]
enter the second seq:=[2 3 4]

Output
y(n)= [0 2 7 16 17 12]

Figure 4.3 Discrete Signals along with Convolution

ECE/LAB MANUAL/DSPLAB Page 14


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 5

AIM: Checking Linearity and Time variance property of a system using convolution, shifting.

Software requirement: - SCI LAB Theory:


Convolution is a mathematical operation used to express the relation between input and output of
an LTI system. It relates input, output and impulse response of an LTI system as y(n)=x(n) h(n)

ECE/LAB MANUAL/DSPLAB Page 15


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Where y (n) = output of LTI x

(n) = input of LTI h (n) =

impulse response of LTI

Discrete Convolution y(n)=x(n) h(n) = By using convolution we can find zero state response of
the system.

PROGRAM CODE
clc; n2=0:M-1; subplot(312);
//Linearity and Time variance stem(n2,x2); grid on;
x1=input('Enter the first sequence x1(n) = '); xlabel('n2--->');
x2=input('Enter the second sequence x2(n) = '); ylabel('amplitude--->');
L=length(x1);
M=length(x2);
N=L+M-1; yn=conv(x1,x2); disp(‘The title('Second sequence');
values of yn are= ‘); disp(yn); n3=0:N-1; subplot(313);
stem(n3,yn);
grid on; xlabel('n3--->'); ylabel('amplitude---
n1=0:L-1; >');
subplot(311); title('Convolved output');
stem(n1,x1); grid on;
xlabel('n1--->'); ylabel('amplitude---
>'); title('First sequence');

n2=0:M-1;
Enter the first sequence x1(n) = [1 2 3 4 5]
Enter the second sequence x2(n) = [5 8 3 5 4 6]

The values of yn are= 5 18 34 55 80 81 59 59 44 30

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 16


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 5.1 Continuous and Discrete Signals with addition and subtraction

PROGRAM 6

ECE/LAB MANUAL/DSPLAB Page 17


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

AIM: To generate and verify random sequences with arbitrary distributions, means and variances
for: (a) Rayleigh distribution
(b) Normal distributions: N(0,1)
(c) Poisson distributions: N(m, x) Software requirement: - SCI LAB

Theory:

(a)The Rayleigh distribution- it is a special case of the WEIBULL DISTRIBUTION. If A and


B are the parameters of the Weibull distribution, then the Rayleigh distribution with parameter b
is equivalent to the Weibull distribution with parametersA=21/2 b and B = 2.

If the component velocities of a particle in the x and y directions are two independent normal
random variables with zero means and equal variances, then the distance the particle travels per
unit time is distributed Rayleigh.

In communications theory NAKAGAMI DISTRIBUTION, RICIAN DISTRIBUTION, and


Rayleigh distributions are used to model scattered signals that reach a receiver by multiple paths.
Depending on the density of the scatter, the signal will display different fading characteristics.
Rayleigh and Nakagami distributions are used to model dense scatters, while Rician distributions
model fading with a stronger line-of-sight. Nakagami distributions can be reduced to Rayleigh
distributions, but give more control over the extent of the fading.

(b) The Normal distributions-

Figure 6.1 Normal Probability Distribution Graph


A normal distribution in a VARIATE with MEAN and VARIANCE is a statistic distribution
with probability density function

ECE/LAB MANUAL/DSPLAB Page 18


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

(1)

on the domain . While statisticians and mathematicians uniformly use the term
"normal distribution" for this distribution, physicists sometimes call it a Gaussian distribution
and, because of its curved flaring shape, social scientists refer to it as the "bell curve."

The so-called "standard normal distribution" is ,given


so by taking and in a general
normal distribution. An arbitrary normal distribution can be converted to a standard normal
distribution by changing variables to , yielding

(c) The Poisson distributions-

A Poisson random variable is the number of successes that result from a Poisson experiment. The
probability distribution of a Poisson random variable is called a Poisson distribution.

Given the mean number of successes (μ) that occur in a specified region, we can compute the
Poisson probability based on the following formula:

Poisson Formula. Suppose we conduct a Poisson experiment, in which the average number of successes
within a given region is μ. Then, the Poisson probability is:

P(x; μ) = (e-μ) (μx) / x!

Where x is the actual number of successes that result from the experiment and e is approximately equal
to
2.71828.

The Poisson distribution has the following properties:


• The mean of the distribution is equal to μ .

• The variance is also equal to σ.

ECE/LAB MANUAL/DSPLAB Page 19


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM CODE
//normal distribution x = //rayleigh //poission
-5:0.01:5; y1 = distribution x = - distribution x = -
(normpdf(x,0,1)); y2 = 5:1:15; y1 = 5:1:15; y1 =
(normpdf(x,0.1,2)); y3 (poisspdf(x,4)); y2 = (raylpdf(x,4)); y2 =
= (normpdf(x,0,0.5)); (poisspdf(x,2)); y3 = (raylpdf(x,2)); y3 =
subplot(3,1,1); (poisspdf(x,1)); (raylpdf(x,1));
plot2d3(x,y1,'.',x,y2,'-',x,y3,'*') subplot(3,1,2); subplot(3,1,3);
; plot2d3(x,y1,'.',x,y2,'-',x,y3,'*' plot2d3(x,y1,'.',x,y2,'-',x,y3,'*')
xlabel('value of x'); ) ;
ylabel('value of y'); ; xlabel('value of x');
title('normal distribution'); xlabel('value of x'); ylabel('value of y');
ylabel('value of y'); title('poission distribution');
title('rayleigh distribution');

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 20


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 6.2 Graphs of Various Distribution Function in Continuous Time Domain

ECE/LAB MANUAL/DSPLAB Page 21


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 7

AIM: To find DFT / IDFT of given DT signal.

Software requirement: - SCI LAB

Theory: Basic equation to find the DFT of a sequence is given below.

Basic equation to find the IDFT of a sequence is given below.

PROGRAM CODE
//pdf
xn=input('Enter the sequence x(n)'); % Find the phases of individual DFT points %
ln=length(xn); xk=zeros(1,ln); plot the magnitude sequence
xk=zeros(1,ln); t=0:ln-1;
subplot(223);
%DFT of sequence stem(t,phase); ylabel
('Phase'); xlabel
for k=0:ln-1 for ('K');
n=0:ln-1 title ('Phase Response');
xk(k+1)=xk(k+1)+
(xn(n+1)*exp((i)*2*pi*k*n/ ln)); end end %IDFT of the sequence
%Plotting input sequence for n=0:ln-1
for k=0:ln-1
t=0:ln-1; ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/
ln));
end end

ECE/LAB MANUAL/DSPLAB Page 22


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

subplot(221); stem(t,xn); ixk=ixk./ln;


ylabel ('Amplitude'); xlabel %code block to plot the input sequence
('Time Index'); t=0:ln-1; subplot(224); stem(t,ixk);
title('Input Sequence'); magnitude=abs(xk); ylabel ('Amplitude'); xlabel ('Time
Index'); title ('IDFT sequence');
% plot the magnitude response
t=0:ln-1; subplot(222);
stem(t,magnitude); ylabel
('Amplitude');
xlabel ('K');
title('Magnitude Response');subplot(2,1,2);
phase=angle(xk);

Output:

Xn=[1 2 3 4 5]

Xk = 15,-2.50+3.44i,-2.50+0.81i,-2.49-0.81i,-2.49-3.44i Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 23


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 7.1DFT and IDFT Sequnce

ECE/LAB MANUAL/DSPLAB Page 24


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Software requirement: - SCI LAB Theory:

DFT of a sequence

Where N= Length of sequence. K= Frequency Coefficient. n = Samples in time domain.

FFT: -Fast Fourier transform. There are two methods.

1. Decimation in time (DIT ) FFT.

2. Decimation in Frequency (DIF) FFT.

Why we need FFT?

The no of multiplications in DFT = N2.

The no of Additions in DFT = N (N-1).

For FFT

The no of multiplication = N/2 log 2N.

The no of additions = N log2 N.

PROGRAM CODE
close all; xlabel('n---->');
x=input('Enter the sequence : ') ylabel('magnitude');
N=length(x) title('magnitude response');
xK=fft(x,N) subplot (2,2,3);
xn=ifft(xK) stem(n,angle(xK));
n=0:N-1; xlabel('n---->'); ylabel('phase');
subplot (2,2,1);
stem(n,x); xlabel('n---->'); title('Phase responce');
ylabel('amplitude'); subplot (2,2,4); stem(n,xn);
title('input sequence'); xlabel('n---->');
subplot (2,2,2); ylabel('amplitude');
stem(n,abs(xK));

ECE/LAB MANUAL/DSPLAB Page 25


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

xlabel('n---->');
ylabel('magnitude');
title('magnitude
response'); subplot
(2,2,3);
stem(n,angle(xK));
xlabel('n---->');
ylabel('phase');

OUTPUT

Enter the sequence: [1 2 3 4 5]

x=12345N=5

xK = 15.0000, -2.5000 + 3.4410i, -2.5000 + 0.8123i , -2.5000 - 0.8123i, -2.5000 - 3.4410i

xn = 1 2 3 4 5

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 26


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 8.1 DFT Sequence

PROGRAM 9

ECE/LAB MANUAL/DSPLAB Page 27


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

AIM: To implement Circular convolution.

Software requirement: - SCI LAB

PROGRAM CODE
Clc;
xl = input ('Enter the First Sequence to xlabel('Time');
be convoluted:'); 11 = length(x1); ylabel('Amplitude');
x2 = input ('Enter the Second Sequence to be title('First Sequence');
convoluted:'); 12 = length(x2); 13 = 11 + 12 subplot(312); stem(x2);
-1; xl =[x1 ,zeros( 1,13-11)]; x2= xlabel('Time');
[x2,zeros(1,13-l2)]; disp('The Input ylabel('Amplitude');
Squence:'); x1,x2 f = cconv(x1,x2,13); title('First Sequence');
disp('The Circular Convoluted Sequence subplot(313); stem(f);
is:'); disp(f); subplot(311); xlabel('Time');
stem(x1); ylabel('Amplitude');
title('Circular Convoluted sequence');

OUTPUT

xl = 1 2 0 0
x2 = 1 2 4 0

The Circular Convoluted Sequence is: 1 488

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 28


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 9.1 Circular Convolution

ECE/LAB MANUAL/DSPLAB Page 29


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 10

AIM: MATLAB code for implementing z-transform.

Software requirement: - SCI LAB

PROGRAM CODE

Clc;
%Compute the Z-transform of sin(n)
syms n
f = sin(n);
ztrans(f)

ans = (z*sin(1))/(z^2 - 2*cos(1)*z + 1)

% Compute the Z-transform of exp(m+n)


syms m n f = exp(m+n); ztrans(f)

ans = (z*exp(m))/(z - exp(1))

%Compute the Z-transform of symbolic


functions syms f1(x) f2(x) a b f1(x) =
exp(x); f2(x) = x;
ztrans([f1 f2],x,[a b])

ans = [ a/(a - exp(1)), b/(b - 1)^2]

PROGRAM 11

AIM: MATLAB program to find frequency response of analog LP/HP filters.

ECE/LAB MANUAL/DSPLAB Page 30


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Software requirement: - SCI LAB

Theory:

1. Buttord

Syntax [n,Wn] = buttord(Wp,Ws,Rp,Rs)

Description calculates the minimum order of a digital or analog Butterworth filter required to
meet a set of filter design

Parameters Description

Wp Passband corner frequency


Ws Stopband corner frequency
Rp Passband ripple, in decibels
Rs Stopband attenuation, in decibels
n the lowest order the proposed Butterworth filter

Wn corresponding cut-off frequency

2. Butter

Syntax

[b,a] = butter(n,Wn)
[b,a] = butter(n,Wn,'ftype’)

[b,a] = butter(n,Wn,'s’)

Description : Designs lowpass, bandpass, highpass, and bandstop digital and analog
Butterworth filters. Butterworth filters are characterized by a magnitude response that is
maximally flat in the passband and monotonic overall.

ECE/LAB MANUAL/DSPLAB Page 31


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM CODE
clc; clear
all; close clc; clear all; close all;
all; format format long;
long; % Program fopr Butterworth HPF
% Program for Butterwoth LPF wp=input('Please enter the first pass band
wp=input('Please enter the first pass band frequency (Hz): ');
frequency (Hz): '); ws=input('Please enter the first stop band
ws=input('Please enter the first stop band frequency (Hz): '); rp=input('Please enter the
frequency (Hz): '); pass band ripple: '); rs=input('Please enter the
rp=input('Please enter the pass band ripple: '); stop band ripple: '); fs=input('Please enter the
rs=input('Please enter the stop band ripple: '); sampling frequency:
fs=input('Please enter the sampling frequency: (Hz)');
(Hz)'); w1=2*wp/fs; w1=2*wp/fs; w2=2*ws/fs;
w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs);
[n,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(n,wn,'high'); w=0:0.01:pi;
[b,a]=butter(n,wn) w=0:0.01:pi; [h,om]=freqz(b,a,w);
[h,om]=freqz(b,a,w); m=20*log10(abs(h)); m=20*log10(abs(h));
an=angle(h); an=angle(h);
subplot(2,1,1); plot(om/pi,m); subplot(2,1,1); plot(om/pi,m);
ylim([-300 50]); ylabel('gain ylim([-300 50]); ylabel('gain
in dB'); xlabel('Normalised in dB');
frequency'); xlabel('Normalised frequency');
subplot(2,1,2);plot(om/pi,an); subplot(2,1,2);plot(om/pi,an); ylabel('Phase in
ylabel('Phase in Radian'); Radian’); xlabel('Normalised frequency');
xlabel('Normalised frequency');

Figure (Expected output for Butterworth LPF):

ECE/LAB MANUAL/DSPLAB Page 32


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 11.1 Butterworth Low Pass Filter

Figure (Expected output for Butterworth HPF):

Figure 11.2 Butterworth High Pass Filter

ECE/LAB MANUAL/DSPLAB Page 33


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

PROGRAM 12

AIM: MATLAB program to find frequency response of analog LP/HP filters.

Software requirement: - SCI LAB

Theory:

FIR filters are digital filters with finite impulse response. They are also known as non-recursive
digital filters as they do not have the feedback. An FIR filter has two important advantages over
an IIR design:

Firstly, there is no feedback loop in the structure of an FIR filter. Due to not having a feedback
loop, an FIR filter is inherently stable. Meanwhile, for an IIR filter, we need to check the
stability. Secondly, an FIR filter can provide a linear-phase response. As a matter of fact, a linear-
phase response is the main advantage of an FIR filter over an IIR design otherwise, for the same
filtering specifications; an IIR filter will lead to a lower order.

FIR FILTER DESIGN An FIR filter is designed by finding the coefficients and filter order that meet
certain specifications, which can be in the time-domain (e.g. a matched filter) and/or the frequency

ECE/LAB MANUAL/DSPLAB Page 34


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

domain (most common). Matched filters perform a cross-correlation between the input signal and a
known pulse-shape. The FIR convolution is a cross-correlation between the input signal and a time-
reversed copy of the impulse-response. Therefore, the matched-filter's impulse response is
"designed" by sampling the known pulse-shape and using those samples in reverse order as the
coefficients of the filter. When a particular frequency response is desired, several different design
methods are common:

1. Window design method

2. Frequency Sampling method

ECE/LAB MANUAL/DSPLAB Page 35


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

clc; clear
all; close %Band Pass filter wn=[wp
all; ws]; b=fir1(n,wn, ‘band',
% Program code for FIR Butterworth filter y); [h,o]=freqz(b,1,256);
using Rectangular window m=20*log10(abs(h));
fp=input('Please enter the pass band frequency subplot(2,2,3); plot(o/pi,m);
(Hz): '); ylim([-120 20]);
fs=input('Please enter the stop band frequency ylabel('Gain in dB');
(Hz): '); xlabel('Normalised frequency');
rp=input('Please enter the pass band ripple: '); title('Band pass filter');
rs=input('Please enter the stop band ripple: ');
sf=input('Please enter the sampling frequency: % Band stop filter
(Hz)'); wp=2*fp/sf; b=fir1(n,wn,'stop',y);
ws=2*fs/sf; [h,o]=freqz(b,1,256);
num=-20*log10(sqrt(rp*rs))-13; m=20*log10(abs(h));
dem=14.6*(fs-fp)/sf; subplot(2,2,4); plot(o/pi,m);
n=ceil(num/dem); n1=n+1; ylim([-15 5]); ylabel('Gain
if(rem(n,2)~=0) n1=n; n=n-1; in dB');
end xlabel('Normalised frequency');
y=rectwin(n1) title('Stop pass filter');

%Low pass filter


b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1); plot(o/pi,m);
ylim([-120 20]); ylabel('Gain
in dB');
xlabel('Normalised frequency');
title('Low pass filter'); %High
pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2); plot(o/pi,m);

ylim([-100 20]);
ylabel('Gain in dB');
xlabel('Normalised frequency');
title('High pass filter');

ECE/LAB MANUAL/DSPLAB Page 36


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure (Expected output):

Figure 12.1 Low Pass and High Pass Filter

PROGRAM CODE
clc; clear
all; close %Band Pass filter
all; wn=[wp ws];
fp=input('Please enter thepass band frequency b=fir1(n,wn, ‘band', y);

ECE/LAB MANUAL/DSPLAB Page 37


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

(Hz): '); [h,o]=freqz(b,1,256);


fs=input('Please enter the stop band frequency m=20*log10(abs(h));
(Hz): '); rp=input('Please enter the pass band subplot(2,2,3);
ripple: '); rs=input('Please enter the stop band plot(o/pi,m); ylim([-120
ripple: '); sf=input('Please enter the sampling 20]); ylabel('Gain in dB');
frequency: xlabel('Normalised frequency');
(Hz)'); title('Band pass filter'); %
beta=input('Please enter the value of Band stop filter
beta'); wp=2*fp/sf; ws=2*fs/sf; b=fir1(n,wn,'stop',y);
num=-20*log10(sqrt(rp*rs))-13; [h,o]=freqz(b,1,256);
dem=14.6*(fs-fp)/sf; m=20*log10(abs(h));
n=ceil(num/dem); n1=n+1; subplot(2,2,4);
if(rem(n,2)~=0) n1=n; n=n-1; plot(o/pi,m); ylim([-15 5]);
end ylabel('Gain in dB');
y=kaiser(n1,beta); xlabel('Normalised frequency');
title('Stop pass filter');
%Low pass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1); plot(o/pi,m);
ylim([-120 20]);
ylabel('Gain in dB');
xlabel('Normalised frequency');
title('Low pass filter');
%High pass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2); plot(o/pi,m);
ylim([-100 20]);
ylabel('Gain in dB');
xlabel('Normalised frequency');
title('High pass filter');

Figure (Expected output):

ECE/LAB MANUAL/DSPLAB Page 38


JAIPUR ENGINEERING COLLEGE AND RESEARCH CENTRE, JAIPUR DEPARMENT
OF ELECTRONICS & COMMUNICATION

Figure 12.2 High Pass Filter

ECE/LAB MANUAL/DSPLAB Page 39

You might also like