0% found this document useful (0 votes)
382 views49 pages

BEC502 Lab Manual

Manual

Uploaded by

rashmipriyabn527
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)
382 views49 pages

BEC502 Lab Manual

Manual

Uploaded by

rashmipriyabn527
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/ 49

DSP Lab Manual-

BEC502
INTRODUCTION TO SCILAB
Overview:
SCILAB is a freely distributed and open source scientific software package. A powerful open
computing environment for Engineering and Scientific applications. Developed since 1990
by researchers from INRIA 2 (Institut Nationale de Recherche en Informatique et en
Automatique) and ENPC (National School of Bridges and Roads). Now maintained and
developed by Scilab consortium since 2003. Since 1994 it is distributed freely along with
source code through the Internet. (www.scilab.org). Scilab users can develop their own
module so that they can solve their particular problems. The Scilab language allows to
dynamically compile and link other languages such as Fortran and C: this way, external
libraries can be used as if they were a part of Scilab built-in features. Scilab also interfaces
LabVIEW, a platform and development environment for a visual programming language
from National Instruments.
Scilab’s Main Features:
 A high-level programming language
 Scilab is an interpreted language
 Integarated object-oriented 2-D and 3-D graphics with animation
 A dedicated Editor
 An XML-based help system
 Interface with symbolic computing packages (Maple and MuPAD 3.0)
 An interface with Tcl/Tk
 Scilab works with most Unix systems including GNU/Linux and on Windows
(9X/NT/2000/XP/Vista/7), and Mac operating system
Scilab coded Toolboxes:
 Linear algebra and Sparse matrices
 Polynomials and Rational functions
 2-D and 3-D graphics with animation

Dept of ECE, NCEH Page 1


DSP Lab Manual-
BEC502
 Interpolation and Approximations
 Linear, Quadratic and Nonlinear Optimization
 ODE solver and DAE solver
 Classical and Robust Control, LMI Optimization
 Differentiable and Non-differential Optimization
 Signal Processing
 Statistic
 Scicos: A hybrid dynamic system modeler and simulator
 Parallel Scialab using PVM
 Metanet: Graphs and Networks
Typical uses:
 Educational Institutes, Research centers and companies
 Math and computation
 Algorithm development
 Modeling, simulation, and visualization
 Scientific and engineering graphics, exported to various formats so that can be
included into documents.
 Application development, including GUI building
Workspace in Scilab:
 The useful workspace in Scilab consists of several windows:
 The console for making calculations
 The editor for writing programs
 The graphics windows for displaying graphics
 The embedded help

Dept of ECE, NCEH Page 2


DSP Lab Manual-
BEC502
EXPERIMENT-1
PROGRAM TO GENERATE THE FOLLOWING DISCRETE
TIME SIGNALS.
A) UNIT SAMPLE SEQUENCE
B) UNIT STEP SEQUENCE
C) EXPONENTIAL SEQUENCE
D) SINUSOIDAL SEQUENCE
E) RANDOM SEQUENCE
F) UNIT RAMP SEQENCE
Aim: To generate basic signals like unit sample sequence, unit step sequence, Exponential
sequence, sinusoidal sequence, random sequence and Unit ramp Sequence.
Theory: In study of Discrete Time Signals and systems there are a number of basic signals play an
important role in Digital signal Processing. These signals are defined below
1.The unit sample sequence is denoted by δ(n) and is defined as

{
δ ( n )= 1 , for n=0
0 , for n ≠ 0 }
2. The unit step sequence is denoted by u(n) and is defined as

{
u ( n ) = 1 , for n≥ 0
0 , for n< 0 }
3. The exponential signal is a sequence is defined as
x ( n )=a n for all n
Where parameter is real, then x(n) is real signal and For decreasing a<1 and For increasing
exponential a>1.
4.A discrete time Sinusoidal Sequence signal may be expressed as

Dept of ECE, NCEH Page 3


DSP Lab Manual-
BEC502
x ( n )= A cos ⁡(2 π f n), −∞ <n<∞

5. A random signal -A signal that has uncertainty about its occurrence is known as random
signal. A random signal has irregular pattern and cannot be represented by the mathematical
equations.
Example-Noise

6. The unit ramp signal is a sequence is defined as


ur ( n )=n ; for all n
Scilab Program
clear ;
clc ;
close ;
//a) Unit sample sequence
L = 4;
n =-L:L;
x = [zeros(1,L),1,zeros(1,L) ];
subplot(421);
plot(n,x,'r.');
plot2d3(n,x);
xtitle('Unit Sample sequence','n' , 'x_1 [n]' );

//b)Unit step sequence


n1=0:5;
x1=[ones(1,6)];
subplot(422);
plot(n1,x1,'r.');
plot2d3(n1,x1);
xtitle( 'Unit Step sequence', 'n' , 'x_2[n]');

//c) Exponential sequence


a =1.5; // For decreasing a<1 and For increasing exponential a>1
n2 = 0:1:20;
x2 = (a).^n2 ;
subplot(423);
plot(n2,x2,'r.');
plot2d3(n2,x2);
xtitle( 'Exponential Sequence', 'n' , 'x_3 [n]' );

Dept of ECE, NCEH Page 4


DSP Lab Manual-
BEC502
//d)Sinusoidal sequence
fm=25;// Frequency input
k=3; // Number of cycles
A=2; // amplitude
tm=0:1/(fm*fm):k/fm;
x3=A*cos(2*%pi*fm*tm);
subplot(424);
plot(tm,x3,'r.');
plot2d3(tm,x3);
xtitle( 'Sinusoidal Signal','n','x_4[n]');

//e) Random sequence


n3 = 100; // number of samples
fs = 10; // frequency
t = 0:1/fs:(n3-1)/fs; // time vector
// Generate a random sequence
x4 = rand(1,n3); // uniform random distribution
subplot(425);
plot(t,x4,'r.');
plot2d3(t,x4);
xtitle( 'random Signal','n','x_5[n]');
// Generate a unit ramp signal
n4=0:1:20;
x5=n4;
subplot(426);
plot(n4,x5,'r.');
plot2d3(n4,x5);
xtitle( 'unit ramp Signal','n','x_6[n]');

Results: Elementary Discrete-Time signals like unit sample sequence, unit step sequence,
Exponential sequence, sinusoidal sequence and random sequence

Dept of ECE, NCEH Page 5


DSP Lab Manual-
BEC502

Outcome: After finishing this experiment the students are able to Generate elementary signals/
waveforms.

Dept of ECE, NCEH Page 6


DSP Lab Manual-
BEC502

EXPERIMENT-2

Program to perform the following operations on signals. a) Signal


addition, b) Signal multiplication, c) Scaling, d) Shifting, e) Folding

Aim: To perform operations on the dependent and independent variables of discrete time-signals
Theory:
Addition: The sum of two signals x 1(n) and x2(n) is a signal y(n), whose value at any instant is
equal to the sum of the values of these two signals at that instant, that is.
y(n) = x1(n) + x2(n) -∞ < n< ∞
Multiplication: The product of two signals x1(n) and x2(n) is a signal y(n), whose value at any
instant is equal to the product of the values of these two signals at that instant, that is.
y(n) = x1(n) * x2(n) -∞ < n< ∞
Scaling: Let x(n) be a discrete-time signal. Then the signal,
y(n)=c x(n)
is called scaled version of x(n) where c is a scaling factor. The signal y(n) is obtained by
multiplying the value of x(n) by scalar c for all n.
Shifting: A signal x(n) may be shifted in time by replacing the independent variable n by n-k,

where k is an integer.
If A: is a positive integer, the time shift results in a delay of the signal by k units of time.
If k is a negative integer, the time shift results in an advance of the signal by |k| units in time.
Time Folding:
Time folding of discrete time signal x(n) is reflected version of x(n). Time folding signal is
obtained by replacing n by-n.
Scilab Program
a) Signal addition, b) Signal multiplication
clc;
close;
clear all;
Dept of ECE, NCEH Page 7
DSP Lab Manual-
BEC502
x=input('Enter the sequence A=');
y=input('Enter the sequence B=');
m=length(x);
n=length(y);
if m>n then
y=[y,zeros(1,m-n)];
else
x=[x,zeros(1,n-m)];
end
z1=x+y;
L1=length(z1);
disp(z1, 'Addition of two sequences:=');
z2=x.*y;
L2=length(z2);
disp(z2, 'Multiplication of two sequences:=');
subplot(211);
plot(0:L1-1,z1,'r.');
plot2d3(0:L1-1,z1);
xtitle('Addition of two sequences','n' , 'z1=x1(n)+x2(n)' );
subplot(212);
plot(0:L2-1,z2,'r.');
plot2d3(0:L2-1,z2);
xtitle('Multiplication of two sequences','n' , 'z2=x1(n)*x2(n)' );

Output:
Enter the sequence A=[1 2 3 4]
Enter the sequence B=[1 2 3]
2. 4. 6. 4.
"Addition of two sequences:="
1. 4. 9. 0.
"Multiplication of two sequences:="

Dept of ECE, NCEH Page 8


DSP Lab Manual-
BEC502

c)Scaling
clc ;
clear ;
close ;
x = input('Enter input sequence x :') ;
a = input ( 'Enter amplification factor a : ') ;
b = input ( 'Enter amplitude reversal factor b : ') ;
y1 = a *x ; // Amplitude Scaling
y2 = b *x ;
n = length ( x ) ;
subplot (2 ,1 ,1) ;
plot(0: n -1 , y1,'r.') ;
plot2d3 (0: n -1 , y1 ) ;
xtitle('Amplified signal','n' , 'y1=a*x' );
subplot (2 ,1 ,2) ;
plot(0: n -1 , y2 ,'r.') ;

Dept of ECE, NCEH Page 9


DSP Lab Manual-
BEC502
plot2d3 (0: n -1 , y2 ) ;
xtitle('Attenuated signal','n' , 'y2=b*x' );

Enter input sequence x :[1 2 3 4]

Enter amplification factor a : 2

Enter amplitude reversal factor b : 0.5

d) Shifting
clc ;
clear ;
close ;
x = input('Enter input sequence x :') ;
n0 = input ('Enter the +ve shift :');
Dept of ECE, NCEH Page 10
DSP Lab Manual-
BEC502
n1 = input ('Enter the −ve shift :');
n = length ( x ) ;
L = length ( x ) ;
i = n0 : L+ n0 -1;
j = n1 : L+ n1 -1;
subplot (3 ,1 ,1) ;
plot(0: n -1 , x, 'r.') ;
plot2d3 (0: n -1 , x ) ;
xtitle('Input signal','n' , 'x' );
subplot (3,1,2) ;
plot(i ,x ,'r.') ;
plot2d3 (i ,x ) ;
xtitle('Positive[right] shifted signal','n' , 'x' );
subplot (3,1,3) ;
plot (j ,x ,'r.') ;
plot2d3 (j ,x ) ;
xtitle('Negative[left] shifted signal','n' , 'x' );

Enter input sequence x :[1 2 3 4]

Enter the +ve shift :2

Enter the −ve shift :-2

Dept of ECE, NCEH Page 11


DSP Lab Manual-
BEC502

e)Folding
clc ;
clear ;
close ;
x = input('Enter input sequence x :') ;
n = length ( x ) ;
n1=0:n-1;
subplot (2 ,1 ,1) ;
plot(n1, x ,'r.') ;
plot2d3 (n1, x ) ;
xtitle('Input signal','n' , 'x' );
subplot (2 ,1 ,2) ;
plot(-n1, x ,'r.') ;
plot2d3 (-n1, x ) ;
xtitle('Folded signal','n' , 'x' );

Enter input sequence x :[1 2 3 4]

Dept of ECE, NCEH Page 12


DSP Lab Manual-
BEC502

Outcome: After finishing this experiment the students are able to perform different operations on signals

Dept of ECE, NCEH Page 13


DSP Lab Manual-
BEC502
EXPERIMENT-3

Program to perform convolution of two given sequences (without


using built-in function) and display the signals

Aim: To obtain the linear convolutions of two given sequences


Theory:
Linear convolution:
The mathematical definition of linear convolution in discrete time domain

y ( n )=x ( n )∗h ( n )= ∑ x ( k ) h(n−k )
k=−∞

Where x(n) is input signal, h(n) is impulse response, and y(n) is output.*denotes convolution.
Here we multiply the terms of x(k) by the terms of a time-shifted h(n) and add them up. The
output length of y(n) =length[x(n)]+length[h(n)]-1.

Scilab Program:

clc;
clear;
close;
x=input('enter the 1st sequence=');
h=input('enter the 2nd sequence=');
xr=input('enter the range of 1st seq=');
hr=input('enter the range of 2nd seq=');
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for 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
Dept of ECE, NCEH Page 14
DSP Lab Manual-
BEC502
end
end
end
disp(Y,'Linear Convolution of two sequences=')
xr1=xr(1):xr(2);
hr1=hr(1):hr(2);
yr1=xr(1)+hr(1):xr(2)+hr(2);
subplot(311);
plot(xr1,x,'r.');
plot2d3(xr1,x);
xtitle('x input sequence','n' , 'x' );
subplot(312);
plot(hr1,h,'r.');
plot2d3(hr1,h);
xtitle('h input sequence','n' , 'h' );
subplot(313);
plot(yr1,Y,'r.');
plot2d3(yr1,Y);
xtitle('Y output sequence','n' , 'y' );

Result:
enter the 1st sequence=[1 2 3 4]
enter the 2nd sequence=[1 2 1 2]
enter the range of 1st seq=[-1 2]
enter the range of 2nd seq=[-1 2]

1.
4.
8.
14.
15.
10.
8.

"Linear Convolution of two sequences="

Dept of ECE, NCEH Page 15


DSP Lab Manual-
BEC502

Dept of ECE, NCEH Page 16


DSP Lab Manual-
BEC502
EXPERIMENT-5
COMPUTATION OF N POINT DFT OF A GIVEN
SEQUENCE AND TO PLOT MAGNITUDE AND
PHASE SPECTRUM

Aim: To obtain the Discrete Fourier Transform (DFT) of a given sequence and to plot its
magnitude and phase responses.
Theory:
Discrete Fourier Transform (DFT) is used for performing frequency analysis of discrete time
signals. DFT gives a discrete frequency domain representation whereas the other transforms
are continuous in frequency domain.
The N point DFT of discrete time signal x(n) is given by the equation
𝑁−1

𝑋(𝑘) = ∑ 𝑥(𝑛) 𝑒−𝑗2πkn/N 𝑘 = 0,1 … . 𝑁 − 1


𝑛=0

Where N is chosen such that N≥L, where L=length of x(n).


X(k) is a complex number. It has both magnitude and phase which are plotted versus k.
These plots are magnitude and phase spectrum of x(n). The ‘k’ gives us the frequency
information.
Magnitude is given by the equation
|𝑋(𝐾)| = √𝑋𝑅(𝐾)2 + 𝑋𝐼(𝐾)2

Phase is given by the equation


𝑋𝐼(𝐾)
𝑃ℎ𝑎𝑠𝑒 = 𝑡𝑎𝑛−1
𝑋𝑅(𝐾)
Scilab Program
clc;
clear;
close;

Dept of ECE, NCEH Page 17


DSP Lab Manual-
BEC502
x=input('enter the sequence x(n)=');//input time domain sequence
N=input('enter the length');//Length of the DFT
L=length(x);
if(N>=L)
x=[x zeros(1,N-L)];
elseif(N<L)
error('length of x(n) must be less than or equal to N');
end
n=0:N-1;
k=0:N-1;
nk=n'*k;
wn=exp(-%i*2*%pi/N);
wk=wn.^nk;
xk=wk*x';
disp('DFT of given sequence is');
yk=round(xk);
disp(yk);
magnitude=abs(yk);//Magnitude of frequency domain signal X(k)
disp('Magnitude Response of DFT is');
disp(magnitude);
disp('Phase Response of DFT is');
phase=atan(imag(yk),real(yk));//Phase of frequency signal X(k)
disp(phase);
p=0:N-1;
// Plot of Input sequence
subplot(3,1,1);
plot2d3(p,x);
xlabel('Time index n');

Dept of ECE, NCEH Page 18


DSP Lab Manual-
BEC502
ylabel('Amplitude');
title('Input sequence');
//Plot of Magnitude spectrum
subplot(3,1,2);
plot2d3(p,magnitude);
xlabel('Frequency sample Index K--->');
ylabel('|X(k)|');
title('Magnitude spectrum');
// Plot of Phase spectrum
subplot(3,1,3);
plot2d3(p,phase);
xlabel('Frequency sample Index K- - ->');
ylabel('<X(k) in radians');
title('Phase spectrum');

Result:
enter the sequence x(n)=[1 2 3 4]
enter the length 4

"DFT of given sequence is"

10. + 0.i -2. + 2.i -2. + 0.i -2. - 2.i

"Magnitude Response of DFT is"

10. 2.8284271 2. 2.8284271

"Phase Response of DFT is"

0. 2.3561945 -3.1415927 -2.3561945

Dept of ECE, NCEH Page 19


DSP Lab Manual-
BEC502

Figure: Output plot of magnitude and phase response.

Dept of ECE, NCEH Page 20


DSP Lab Manual-
BEC502

Dept of ECE, NCEH Page 21


DSP Lab Manual-
BEC502
EXPERIMENT-6
COMPUTATION OF LINEAR CONVOLUTION OF TWO
SEQUENCES USING DFT AND IDFT
Aim: To obtain the linear convolutions of two given sequences using DFT and IDFT.
Theory:

Suppose that we have a finite duration sequence 𝑥(𝑛) of length L which excites an FIR filter
having an impulse response ℎ(𝑛) of length M. The output of 𝑦(𝑛) of the filter in the time
domain can be expressed as a convolution of 𝑥(𝑛) and ℎ(𝑛), that is

𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) =


𝑘=∑𝑀−1 𝑥(𝑘)ℎ(𝑛 − 𝑘) In fact the 𝑦(𝑛), consists of 𝑀 + 𝐿
0 − 1 samples.

In the frequency domain, the same linear convolution 𝑦(𝑛) can be obtained by performing
N-point 𝐷𝐹𝑇 for which 𝑁 ≥ 𝑀 + 𝐿 − 1, that is

𝑌(𝑘) = 𝑋(𝑘)𝐻(𝑘)

𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = 𝐼𝐷𝐹𝑇{𝑌(𝑘)} = 𝐼𝐷𝐹𝑇{𝑋(𝑘)𝐻(𝑘)}

In turn this implies that the N-point circulation of 𝑥(𝑛) with ℎ(𝑛) must be equivalent to the
linear convolution of 𝑥(𝑛) with ℎ(𝑛).

Scilab Program:
clear all;
clc;
x=input('enter the x sequence');// x input sequence
h=input('enter the h sequence');// h input sequence
N1=length(x);
N2=length(h);
x=[x,zeros(1,N2-1)]; //append zeros to x(n)
disp(x);
Dept of ECE, NCEH Page 22
DSP Lab Manual-
BEC502
h=[h,zeros(1,N1-1)];//append zeros to h(n)

Dept of ECE, NCEH Page 23


DSP Lab Manual-
BEC502
disp(h);
Xk=fft(x);//DFT of x(n)
Hk=fft(h);//DFT of h(n)
disp('DFT of x');
disp(Xk);
disp('DFT of h');
disp(Hk);
Yk=Xk.*Hk;//Multiply two DFT’s
disp('Yk');
disp(Yk);
y=ifft(Yk);//IDFT of Yk
disp('linear convolution by using DFT and IDFT');
disp(y);// output sequence
//plot of x sequence
subplot(3,1,1);
plot2d3(x);
ylabel('x(n)-->');
xlabel('n-->');
title('input x(n)');
//plot of h sequence
subplot(3,1,2);
plot2d3(h);
ylabel('h(n)-->');
xlabel('n-->');
title('input h(n)');
//plot of y sequence
subplot(3,1,3);
plot2d3(y);
ylabel('y(n)-->');
xlabel('n-->');
title('linear convolution by using DFT and IDFT');
Result:
enter the 1st sequence[1 2]

Dept of ECE, NCEH Page 24


DSP Lab Manual-
BEC502
enter the 2nd sequence[1 2 3]
1. 2. 0. 0.
1. 2. 3. 0.
"DFT of x"
3. + 0.i 1. - 2.i -1. + 0.i 1. + 2.i
"DFT of h"
6. + 0.i -2. - 2.i 2. + 0.i -2. + 2.i
"Yk"
18. + 0.i -6. + 2.i -2. + 0.i -6. - 2.i
"linear convolution by using DFT and IDFT"
1. 4. 7. 6.

Figure: output plot of linear convolution using DFT and IDFT.

Dept of ECE, NCEH Page 25


DSP Lab Manual-
BEC502
EXPERIMENT-6
COMPUTATION OF CIRCULAR CONVOLUTION OF
TWO GIVEN SEQUENCES USING DFT AND IDFT

Aim: To obtain the circular convolutions of two given sequences using DFT and IDFT.
Theory:
Suppose that we have two finite-duration sequences of length N, 𝑥(𝑛) and ℎ(𝑛). Their

𝑋(𝑘) = ∑𝑁−1 𝑥(𝑛) 𝑊𝑛𝑘 0≤𝑘 ≤𝑁−1


respective N-point DFTs are

𝑛=0 𝑁
𝐻(𝑘) = ∑𝑁−1 ℎ(𝑛) 𝑊𝑛𝑘 0≤𝑘 ≤𝑁−1
𝑛=0 𝑁

If we multiply the two DFTs together, as a result 𝑌(𝑘)


𝑌(𝑘) = 𝑋(𝑘)𝐻(𝑘) 0 ≤ 𝑘 ≤ 𝑁 −
1
0≤𝑛≤𝑁−1
The IDFT of 𝑌(𝑘) is 𝑦(𝑛) = 𝑥(𝑛) ⊛ ℎ(𝑛) = ∑𝑁−1
( ) (
ℎ 𝑛 𝑥( 𝑚 − 𝑛 ))
𝑚=
0
𝑁

Scilab program:
clear all;
clc;
x=input('enter the 1st sequence');//x input sequence
h=input('enter the 2nd sequence');//h input sequence
N1=length(x);
N2=length(h);
N3=N1-N2;
if(N1>N2)
h=[h,zeros(1,N3)];//append zeros to h(n)
else if (N2>N1)
x=[x,zeros(1,-N3)]; //append zeros to x(n)
end
end
Xk=fft(x);//DFT of x(n)
Hk=fft(h); //DFT of h(n)
Dept of ECE, NCEH Page 26
DSP Lab Manual-
BEC502
disp('DFT of x(n)');

Dept of ECE, NCEH Page 27


DSP Lab Manual-
BEC502
disp(Xk);
disp('DFT of h(n)');
disp(Hk);
Yk=Xk.*Hk;//Multiply two DFTs
disp('Yk');
disp(Yk);
y=ifft(Yk);//IDFT of Yk
disp('circular convolution by using DFT and IDFT');
disp(y);//output sequence
//Plot of x sequence
subplot(3,1,1);
plot2d3(x);
ylabel('x(n)-->');
xlabel('n-->');
title('input x(n)');
//Plot of h sequence
subplot(3,1,2);
plot2d3(h);
ylabel('h(n)-->');
xlabel('n-->');
title('input h(n)');
//Plot of y sequence
subplot(3,1,3);
plot2d3(y);
ylabel('y(n)-->');
xlabel('n-->');
title('circular convolution by using DFT and IDFT method');

Result:
enter the 1st sequence[1 2 3 4]
enter the 2nd sequence[2 1 2 1]
"DFT of x(n)"
10. + 0.i -2. + 2.i -2. + 0.i -2. - 2.i

Dept of ECE, NCEH Page 28


DSP Lab Manual-
BEC502
"DFT of h(n)"
6. + 0.i -2. - 2.i 2. + 0.i -2. + 2.i
"Yk"
60. + 0.i 0. + 0.i -4. + 0.i 0. + 0.i
"circular convolution by using DFT and IDFT"
14. 16. 14. 16.

Figure: output plot of circular convolution using DFT and IDFT.

Dept of ECE, NCEH Page 29


DSP Lab Manual-
BEC502
EXPERIMENT-7
VERIFICATION OF LINEARITY PROPERTY, CIRCULAR
TIME SHIFT PROPERTY & CIRCULAR FREQUENCY
SHIFT PROPERTY OF DFT
Aim: To verify the properties of DFT such as Linearity, circular time shift and Circular
frequency shift.
Theory:
Linearity property
𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇 𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
If 𝑥1(𝑛) ↔−−−−−−−−→ 𝑋1(𝑘), and 𝑥2(𝑛) ↔−−−−−−−−→ 𝑋2(𝑘)
then for any real-valued or
𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
complex valued constants 𝑎1 and 𝑎2, 𝑎1𝑥1(𝑛) + 𝑎2𝑥2(𝑛) ↔−−−−−−−−→ 𝑎1𝑋1(𝑘) +
𝑎2𝑋2(𝑘)

Circular time shift property

𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
If 𝑥(𝑛) ↔−−−−−−−−→ 𝑋(𝑘) then

𝑥((𝑛 − 𝑙)) 𝑁−𝑃𝑜𝑖𝑛𝑡 𝑙𝑘


𝐷𝐹𝑇
𝑁 ↔−−−−−−−−→ 𝑊𝑁 𝑋(𝑘)

Circular frequency shift property

𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇
If 𝑥(𝑛) ↔−−−−−−−−→ 𝑋(𝑘) then

𝑦(𝑛) = −𝑙𝑛 𝑁−𝑃𝑜𝑖𝑛𝑡 𝐷𝐹𝑇


↔−−−−−−− (𝑘 − ))𝑁
𝑥(𝑛)𝑊𝑁 −→ 𝑋( 𝑙

Scilab Program for Linearity property:


clc;
clear;

Dept of ECE, NCEH Page 30


DSP Lab Manual-
BEC502
close;
x1=input('enter the 1st sequence=');
x2=input('enter the 2nd sequence=');

Dept of ECE, NCEH Page 31


DSP Lab Manual-
BEC502
a=input('enter the 1st constant a=');
b=input('enter the 2nd constant b=');
N=input('enter the length of DFT=');
term1=a.*x1+b.*x2;
LHS=fft(term1);
term2=fft(a.*x1);
term3=fft(b.*x2);
RHS=term2+term3;
if(LHS==RHS)
disp('Linear property is proved');
disp('LHS=');
disp(LHS);
disp('RHS=');
disp(RHS);
else
disp('DFT is not linear');
end
Result:
enter the 1st sequence=[1 2 3 4]

enter the 2nd sequence=[3 1 1 3]

enter the 1st constant a=1

enter the 2nd constant b=1

enter the length of DFT=4

"Linear property is proved"

"LHS="18. + 0.i 0. + 4.i -2. + 0.i 0. - 4.i

"RHS="18. + 0.i 0. + 4.i -2. + 0.i 0. - 4.i

Dept of ECE, NCEH Page 32


DSP Lab Manual-
BEC502
Scilab Program for circular Time Shift:
clc ;
clear;
close;
x=input('enter the sequence x='); //input sequence
N=length(x);
m=2;//shift value
xs=zeros(1, N);
for n=0:N-1
i=pmodulo((n-m),N);
if i<0 then
i=i+N;
end
xs(n+1)=x(i+1);
end
disp('xs=');
disp(xs);
//LHS
LHS=fft(xs);
LHS=round(LHS)
disp('circular time shift value LHS =');
disp(LHS);
//RHS
k=0:N-1;
RHS=exp(-%i*2*%pi*k*m/N).*fft(x);
RHS=round(RHS);
disp('circular time shift value RHS=');

Dept of ECE, NCEH Page 33


DSP Lab Manual-
BEC502
disp(RHS);
if(LHS==RHS) then
disp('It satisfies Circular Timeshift Property');
else
disp('It is not satisfies Circular Timeshift Property');
end;

Result:
enter the sequence x=[1,-1,1,-1]
"xs="
1. -1. 1. -1.
"circular time shift value lhs ="
0. 0. 4. 0.
"circular time shift value rhs="
0. + 0.i 0. + 0.i 4. + 0.i 0. + 0.i
"It satisfies Circular Timeshift Property"

Scilab Program for circular Frequency Shift:


clc ;
clear;
close;
x=input('enter the sequence x=');
N=length(x);
n=0:N-1;
L=input('enter the frequency Shift Factor=');
//LHS L1=exp(%i*2*
%pi*L*n/N).*x L2=fft(L1);

Dept of ECE, NCEH Page 34


DSP Lab Manual-
BEC502
LHS=round(L2);
disp('circular frequency shift value
LHS='); disp(LHS);
//RHS
xk=fft(x);
xks=zeros(1, N);
for n=0:N-1
i=pmodulo((n-L),N);
if i<0 then
i=i+N;
end
xks(n+1)=xk(i+1);
end
RHS=round(xks);
disp('circular frequency shift value RHS=');
disp(RHS);

// check for the property

if (LHS==RHS) then
disp('Frequency shift property
satisfied'); else
disp('Frequency shift property is not satisfied');
end
Result:

enter the sequence x=[1 0 1 0]


enter the frequency Shift

Dept of ECE, NCEH Page 35


DSP Lab Manual-
BEC502
Factor=2

Dept of ECE, NCEH Page 36


DSP Lab Manual-
BEC502
"circular frequency shift value LHS="
2. + 0.i 0. + 0.i 2. + 0.i 0. + 0.i
"circular frequency shift value RHS="
2. 0. 2. 0.
"Frequency shift property satisfied"

Dept of ECE, NCEH Page 37


DSP Lab Manual-
BEC502
EXPERIMENT-10
DESIGN AND IMPLEMENTATION OF IIR
(BUTTERWORTH) LOW PASS FILTER TO MEET GIVEN
SPECIFICATIONS

AIM: To design and implement an IIR filter for given specifications.

THEORY: A digital IIR(Infinite Impulse Response ) filter is a linear time invariant discrete
time systems which has infinite duration impulse response h(n).IIR filters are recursive i.e
the present output sample depends on the present and /or past input and past output samples.
The design of a digital IIR filter involves the design of the filter in the analog domain and
then transforms it into the digital domain using various analog to digital transformation
methods.
The different steps involved in the design of a digital IIR filter are,
(i) The frequency response specification in digital domain is converted into analog and an
equivalent analog filter Ha(s) is designed by using any one of the approximation techniques
like Butterworth, chebyshev etc.
(ii) The analog transfer function Ha(s) is converted to digital transfer function H(z) using
various analog to digital transformation methods like Impulse invariance, Bilinear
transformation, backward difference, matched Z-transform etc
Scilab program:

clc;
clear;
close;
fc=1000;//cutoff frequency
fs=3000; //Sampling Frequency

Dept of ECE, NCEH Page 38


DSP Lab Manual-
BEC502
N=30; //order of the filter
wc=fc/fs; //Normalize the Cutoff Frequency
hz=iir(N,'lp','butt',[wc,0],[0,0]);
[hzm,fr]=frmag(hz,256);
plot2d(fr*fs,hzm)
xlabel('Frequency');
ylabel('Magnitude');
title('IIR Low pass filter')

Result: Observed the magnitude response of Low pass filter for given specifications

Figure: Plot of Magnitude frequency response of IIR Low pass filter

Dept of ECE, NCEH Page 39


DSP Lab Manual-
BEC502
EXPERIMENT-11
DESIGN AND IMPLEMENTATION OF IIR
(BUTTERWORTH) HIGH PASS FILTER TO MEET
GIVEN SPECIFICATIONS

AIM: To design and implement an IIR filter for given specifications.

THEORY: A digital IIR(Infinite Impulse Response ) filter is a linear time invariant


discrete time systems which has infinite duration impulse response h(n).IIR filters are
recursive i.e the present output sample depends on the present and /or past input and past
output samples.
The design of a digital IIR filter involves the design of the filter in the analog domain and
then transforms it into the digital domain using various analog to digital transformation
methods.
The different steps involved in the design of a digital IIR filter are,
(i) The frequency response specification in digital domain is converted into analog and an
equivalent analog filter Ha(s) is designed by using any one of the approximation techniques
like Butterworth, chebyshev etc.
(ii) The analog transfer function Ha(s) is converted to digital transfer function H(z) using
various analog to digital transformation methods like Impulse invariance, Bilinear
transformation, backward difference, matched Z-transform etc
Scilab program:
clc;
clear;
close;
fc=1000;//cutoff frequency
fs=3000; //Sampling Frequency

Dept of ECE, NCEH Page 40


DSP Lab Manual-
BEC502
N=30; //order of the filter
wc=fc/fs; //Normalize the Cutoff Frequency
hz=iir(N,'hp','butt',[wc,0],[0,0]);
[hzm,fr]=frmag(hz,256);
plot2d(fr*fs,hzm)
xlabel('Frequency');
ylabel('Magnitude');
title('IIR High pass filter')

Result: Observed the magnitude response of High pass filter for given specifications

Figure: Plot of Magnitude frequency response of IIR High pass filter

Dept of ECE, NCEH Page 41


DSP Lab Manual-
BEC502
EXPERIMENT-9
DESIGN AND IMPLEMENTATION OF LOW PASS FIR
FILTER TO MEET GIVEN SPECIFICATIONS
AIM: To design and implement a Low pass FIR filter for given specifications.

THEORY: A FIR filter has finite number of samples in its impulse response. The FIR filters
are of non-recursive type, whereby the present output sample is depending on the present
input sample and previous input samples.
The Design Procedure of FIR filters using windows method.
Step 1: Select the desired frequency response of the filter
N−1
𝐻𝑑 (𝑒𝑗𝑤) = 𝑒−𝑗𝑤α 𝑤ℎ𝑒𝑟𝑒 α =
2
Step 2: Find the desired unit impulse response hd(n) from the desired frequency response
Hd(ejw) by obtaining the inverse Fourier transform using the equation
𝝅

ℎ𝑑 (𝑛) = 1
∫ (𝑒𝑗𝑤)𝑒𝑗𝑤𝑛𝑑𝑤
2
𝜋 𝐻𝑑
−𝝅

Step 3: Since hd(n) is an infinite sequence, truncate it to get a finite sequence of length N,say
from n=0 to N-1
i.e h(n)=hd(n)* w(n)
Where w(n) is a “window sequence”
Step 4: By taking Z-transform of h(n),obtain the Transfer function H(z) of the filter
Step 5: Obtain the frequency response i.e magnitude response and phase response
Table: Summary of important features of window functions

Name of window Transition Stopband attenuation Window function


function width (dB) minimum

Dept of ECE, NCEH Page 42


DSP Lab Manual-
4
BEC502
𝜋
Rectangular 21 1

Dept of ECE, NCEH Page 43


DSP Lab Manual-

8
BEC502
(𝑁 −
𝜋 |𝑛 − 2
)
1 1−2
25

𝑁 |
Bartlett (Triangular)
𝑁−1
8 2𝜋𝑛
𝜋 0.5 − 0.5cos ( )
𝑁−1
44
Hanning
𝑁
8 2𝜋𝑛
𝜋 0.54 − 0.46𝑐𝑜𝑠 ( )
𝑁−1
53
Hamming
𝑁

Scilab program for LP FIR:


clc;
clear;
close;
N=input ('enter the order');
wc=input('enter cutoff
frequency'); alpha=(N-1)/2;
for n=0:N-1
if(n==alpha)
hd(n+1)=wc/%pi;
else
hd(n+1)=sin(wc*(n-alpha))/(%pi*(n-alpha));
end

wha=window('re',N);//for Rectangular window ‘re’,Hamming window ‘hm’,Hanning


//window ‘hn’ Bartlett or triangular window ‘tr’
h=hd.*wha';
disp('impulse response h(n) of a filter specification
is'); disp(h);
[h,fr]=frmag(h,256);
h_dB=20*log10(h);
Dept of ECE, NCEH Page 44
DSP Lab Manual-
BEC502
plot(fr,h);
xlabel('dgital frequency') ;
ylabel('magnitude in dB');
Result:
enter the order 7
enter cutoff frequency 1
"impulse response h(n) of a filter specification is" 0.0149733
0.1447192
0.2678485
0.3183099
0.2678485
0.1447192
0.0149733

Figure: Plot of Magnitude frequency response of Low pass filter

Dept of ECE, NCEH Page 45


DSP Lab Manual-
BEC502
EXPERIMENT-10
DESIGN AND IMPLEMENTATION OF HIGH PASS FIR
FILTER TO MEET GIVEN SPECIFICATIONS
AIM: To design and implement a Low pass FIR filter for given specifications.

THEORY: A FIR filter has finite number of samples in its impulse response. The FIR filters
are of non-recursive type, whereby the present output sample is depending on the present
input sample and previous input samples.
The Design Procedure of FIR filters using windows method.
Step 1: Select the desired frequency response of the filter
N−1
𝐻𝑑 (𝑒𝑗𝑤) = 𝑒−𝑗𝑤α 𝑤ℎ𝑒𝑟𝑒 α =
2
Step 2: Find the desired unit impulse response hd(n) from the desired frequency response
Hd(ejw) by obtaining the inverse Fourier transform using the equation
𝝅

ℎ𝑑 (𝑛) = 1
∫ (𝑒𝑗𝑤)𝑒𝑗𝑤𝑛𝑑𝑤
2
𝜋 𝐻𝑑
−𝝅

Step 3: Since hd(n) is an infinite sequence, truncate it to get a finite sequence of length N,say
from n=0 to N-1
i.e h(n)=hd(n)* w(n)
Where w(n) is a “window sequence”
Step 4: By taking Z-transform of h(n),obtain the Transfer function H(z) of the filter
Step 5: Obtain the frequency response i.e magnitude response and phase response
Table: Summary of important features of window functions

Name of window Transition Stopband attenuation Window function


function width (dB) minimum

Dept of ECE, NCEH Page 46


DSP Lab Manual-
4
BEC502
𝜋
Rectangular 21 1

Dept of ECE, NCEH Page 47


DSP Lab Manual-

8
BEC502
(𝑁 −
𝜋 |𝑛 − 2
)
1 1−2
Bartlett(Triangular) 25

𝑁 |
𝑁−1
8 2𝜋𝑛
𝜋 0.5 − 0.5cos ( )
𝑁−1
Hanning 44

𝑁
8 2𝜋𝑛
𝜋 0.54 − 0.46𝑐𝑜𝑠 ( )
𝑁−1
Hamming 53

Scilab program for HP FIR:


clc;
clear;
close;
N=input ('enter the order');
wc=input('enter cutoff
frequency'); alpha=(N-1)/2;
for n=0:N-1
if(n==alpha)
hd(n+1)=1-(wc/%pi);
else
hd(n+1)=-(sin(wc*(n-alpha))/(%pi*(n-alpha)));
end
end
wha=window('hm',N);//for Rectangular window re,Hamming window hm,Hanning
//window hn Bartlett or traingular window
tr h=hd.*wha';
disp('impulse response h(n) of a filter specification
is'); disp(h);
[h,fr]=frmag(h,256);
h_dB=20*log10(h);
Dept of ECE, NCEH Page 48
DSP Lab Manual-
BEC502
plot(fr,h);
xlabel('dgital frequency') ;
ylabel('magnitude in dB');
Result:
enter the order 7
enter cutoff frequency 1
"impulse response h(n) of a filter specification is"
-0.0011979
-0.0448629
-0.2062434
0.6816901
-0.2062434
-0.0448629
-0.0011979

Figure: Plot of Magnitude frequency response of High pass filter

Dept of ECE, NCEH Page 49

You might also like