You are on page 1of 70

Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

INTRODUCTION TO SCILAB 6.0.0

Scilab Overview

Scilab is a programming language associated with a rich collection of numerical


algorithms covering many aspects of scientific computing problems. Scilab is an
interpreted language. The Scilab language can 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.
The following is a short list of capabilities of Scilab :
• Linear algebra, sparse matrices,
• Polynomials and rational functions,
• Interpolation, approximation,
• Linear, quadratic and non linear optimization,
• Ordinary Differential Equation solver and Differential Algebraic Equations
solver,
• Classic and robust control, Linear Matrix Inequality optimization,
• Differentiable and non-differentiable optimization,
• Signal processing,
• Statistics.

We will focus on signal processing in the present laboratory session to accomplish


the Digital Signal Processing (DSP) experiments prescribed in the syllabus.

Introduction to the User Interface (UI)

The use of user interface icons to manage your work can help you become more
productive with Scilab. You can use Scilab predefined functions to perform the
equivalent of most of the features found in the UI icons. The following illustration
shows the default configuration of the Scilab UI. You can modify the appearance
in a way that pleases you. The user interface is on display in the next page.

Page 1
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Arranging the Console UI

These are some common ways to customize the User Interface (UI):
 Resize any particular browser (File Browser, Variable Browser, Command
History or the News feed) by dragging one of its edges.
 Dock or undock a tool outside of the UI by clicking the undock button in
the tool's title bar.
 Customize the UI by clicking the Scilab Preferences icon in the console
menu bar. The Scilab Preferences icon is located third from right of the
menu bar. Use the tool tip displayed as you move your mouse over the menu
bar to figure out the icon.

Scilab Demonstration icon

The Scilab Demonstration icon provides easy access to tools, demos, shortcuts.
Click the Scilab Demonstration icon to see the options.

Page 2
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Console Window and Command History

Console Window

Use the Command Window to enter variables and to run Scilab functions and
scripts. Scilab echoes the results. To avoid the echoing terminate the
command/function by semi-colon (;).
The results of last performed operation are by default stored in variable called ans.

Press the up arrow key ↑ to recall a statement you previously typed. Edit the
statement as needed, and then press Enter to run it. To get help about various
functions and toolboxes of Scilab use the “help” command. The syntax is provided
here: help <command>. This will result in popping up of help browser with
suitable documentation help.

Command History

Statements you enter in the console Window are logged with a timestamp in the
Command History. From the Command History, you can view and search for
previously run statements, as well as copy and execute selected statements. You
can also create a file from selected statements.To save the input and output from a
Scilab session to a file, use the diary function.

Getting Help

Page 3
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

The various ways of finding help are discussed here. Click the help browser icon to
see the help browser pop. The icon is found on extreme right of the menu bar
showing question mark symbol (?). The help browser would look this:

The help browser is divided into two parts. The left half the help browser has two
icons at the top. The two icons are the table of contents icon and the search icon.
To the left half of the help browser window you have various nodes corresponding
to various capabilities of scilab. Expand the necessary node and look for
corresponding topic. Else you can click on search icon of the browser window and
give appropriate search string. By doing so you can see that the help browser
window will show the corresponding command/function and the suitable
navigation in the table of contents.

Variable Browser

The Scilab UI consists of variables browser. The variable browser houses variables
defined during a Scilab session and stored in memory. You add variables to the
variable browsers by using functions, running function and script files. The view of
the browser when undocked would look this way. It displays variable name, type
of variable and memory occupied in system.

Page 4
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

To delete variables from the variable browser, select the variables, and then right
click on the variable and choose delete <variable name>. Alternatively, use clear
function in console window.

Using the Folder Browser to Manage Files

The Current Folder browser is a key tool for managing files. Open the Folder
where your pieces of code are placed click the ‘select a directory’ icon in file
browser. Then a pop box would appear which would help you choose the folder.
The screen shot of the pop box that would appear is on display in the next page.
The necessary commands are explained as and when required.

Page 5
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Page 6
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

1. Generation of sinusoidal waveform based on recursive


difference equation
Aim: To generate Sinusoidal waveform based on recursive difference equations.
Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Pre-requisites: Through understanding of Z- transform.
Theory: We begin our analysis for developing this program by assuming a
impulse response which is causal and is sinusoidal of hundred hertz sampled at
eight thousand hertz. To this impulse response we apply Z- transform. The
transform is re-organized to get a difference equation. The difference equation is
used in the code for generation of sinusoidal waveform.

Inbuilt functions used in this piece of code


Clc Clear the console window
Clear Clear variables in variable browser
Close Close all graphic windows is open.
Plot Plot graph without interpolating the data
Xgrid To get the grid displayed on the graph
Color To set the color of the grid
Gca Returns handler to the axis object to set its properties
Xtitle To set the title and label for the graph

Program:
clc;
clear;
close;
x = [1 0.01 0.25 zeros(1,147)];
y(1) = 1;
y(2) = 1;
for n = 3:150
y(n) = 1.9938*y(n-1) -y(n-2) + 0.0784*x(n-1);
end
plot(y);xgrid(color("green"));
s = gca();s.x_location = "origin";s.y_location = "origin";
xtitle('Sine Signal','n Time','Amplitude');

Page 7
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output graph:

Result: Sinusoidal signal has been generated using recursive evaluation approach
and the corresponding Waveforms/Graphs have been plotted.

Page 8
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

2. Frequency response of a system given in transfer


function/Differential equation form

Aim: To find the frequency response of a continuous time system in Transfer


function form.
Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Theory: We begin developing this program by considering a transfer function and
assuming that the transfer function satisfies sufficient condition for existence of
fourier transform. After this we will replace with jω and find the frequency
response for a set of frequency inputs for the given transfer function.

Inbuilt functions used in this piece of code


Linspace Generates linearly spaced numbers between two reached bounds
Syslin Used for defining linear system in state space domain
Polar Used to representing given co-ordinates in polar form
Real Extract real part of a complex number
Subplot Used to define subplot in a graph

Program:
clc;
clear;
close;
s = %s;
f = linspace(0.01,7,1000);
w = 2*%pi*f;
num1 = s^3+ 2*s^2 - 0.9*s + 1;
den1 = s^3 + 0.9*s + 0.8;
p = syslin('c',num1,den1);
for k = 1:1000
P = ((-%i*w(k)^3 - 2*w(k)^2 - %i*0.9*w(k) + 1)/(-%i*w(k)^3 + %i*w(k)*0.9 +
0.8));
[Pmag(k) Pph(k)] = polar(P);
end
Pph = (180/%pi)*real(Pph);
subplot(2,1,1);
Page 9
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

plot(w,Pmag);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Frequency Response','f Frequency','Magnitude');
subplot(2,1,2);
plot(w,Pph);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Phase Response','f Frequency','Phase');

Output graph:

Result: Thus frequency response of continuous time and discrete time systems are
found and plotted

Page 10
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

3. Implementation of DFT/IDFT of a discrete time signal


Aim: to find Discrete Fourier Transform of given discrete time signal / sequence.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The DFT (Discrete Fourier Transform) is sampled version of


DTFT(Discrete Time Fourier Transform). The formula used for implementation of
DFT/IDFT is given below. The variables ‘k’ is used to represent the frequency
index and variable n is used to represent the time index. The index for frequency
and time vary from 0 to (N-1). The variable N is length of the input signal
sequence. The equations are self explanatory.

X(k) = ∑ x(n)e(-j*2*π*k*n/N) ---------- (1)

x(n) = (1/N)*∑ X(k)e(j*2*π*k*n/N) ------- (2)

Inbuilt functions used in this piece of code


Length Used to find the number of elements of given matrix
Tic Function to start the stop watch
Toc Function to stop the stop watch
Plot2d3 Plots the graph for the given data without interpolation

Program:
clc;
clear all;
close;
x = [1 2 3 4 5 6 7 8]
N=0;
subplot(3,1,1);
plot2d3(x);set(gca(),"grid",[1 1]);
a = gca();

Page 11
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

a.x_location = "origin";
a.y_location = "origin";
a.data_bounds = [0,0;10,10];
xgrid(color("green"));
xtitle('Input Sequence','n Time Axis','Amplitude');
N = length(x);
s = zeros(1,N);
tic();
for k=0:N-1
s(k+1) = 0;
for n = 0:N-1
s(k+1) = s(k+1) + (x(n+1).*exp((-%i*2*%pi*k*n)/N));
end
end
disp(toc());
subplot(3,1,2);
plot2d3(abs(s));xgrid(color("green"));
a = gca();
a.x_location = "origin";
a.y_location = "origin";
a.data_bounds = [0,0;10,60];
xtitle('Spectrum','k Frequency Axis','Magnitude');
N1=length(s);
for n=0:N1-1
y(n+1)=0
for k=0:N1-1
y(n+1)=y(n+1)+(s(k+1).*exp((%i*2*%pi*k*n)/N1));
end
end
disp('Inverse discrete fourier transform');
disp(abs(y/N1));
subplot(3,1,3);
plot2d3(abs(y/N1));xgrid(color("green"));
xtitle('Inverse DFT','n Time Axis','Amplitude');
a = gca();
a.x_location = "origin";
a.y_location = "origin";
a.data_bounds = [0,0;10,10];

Page 12
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output graph:

Result: The Discrete Fourier Transform (DFT) and Inverse Discrete Fourier
Transform of given sequence is obtained.

Page 13
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

4. Fast Fourier Transform


Aim: To compute the DFT of sequence using Fast Fourier Trnasform

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The approach used earlier is a direct one. This approach is very tedious
process and involves lot of complex multiplications and additions. A better
algorithm was proposed to calculate the DFT of a given sequence. This algorithm
is called Fast Fourier Transform. This approach takes the advantage of two
principles called, periodicity and symmetry. A comparison of mathematical
complexity gives better understanding how efficient this algorithm is. Let us
consider that we have a sequence of N samples. In the direct approach the number
of complex multiplications is given by relation N2. For the same of same length the
number of complex multiplications is given by relation (N/2)log 2(N). The
efficiency of this algorithm is more evident as the length of the sequence increases.

Inbuilt functions used in this piece of code


Fft Used for calculating DFT/IDFT of a given signal based on arguments.

Program:
clc;
clear;
close;
tic();
xn = [1 2 3 4 5 6 7 8] ;
n = 1:1:8;
xk = fft(xn);
disp(toc());
subplot(3,1,1);
plot2d3(n,xn);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Input Sequence','n Time','Amplitude');
subplot(3,1,2);
plot2d3(n,abs(xk));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Fast Fourier Transform','k Frequency','Magnitude');
xin = fft(xk,1);
Page 14
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

subplot(3,1,3);
plot2d3(n,xin);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Invers Fast Fourier Transform','n Time','Amplitude');

Output graph:

Result: The Discrete Fourier Transform of a sequence is found using FFT


algorithm

5. Power Spectrum of given signal


Page 15
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Aim: To plot power spectrum of a given signal.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The total average power of the signal is of little interest in any
given signal. We are more interested in power distribution of signal at
various frequencies. This can obtained by finding the Power Spectral
Density (PSD) of given signal. Since the given signal is discrete
sequence we use the relation given below.

PSD = (|FFT(x(n)|2)/N

The variable N denotes the length of the sequence.


Inbuilt functions used in this piece of code
Conj Function to find complex conjugate of a complex number.

Program:
clc;
clear;
close;
fs = 100;
t = 0:1/fs:10;
x = sin(2*%pi*15*t) + sin(2*%pi*30*t);
y = fft(x);
f = fs*(0:length(t)-1)/length(t);
power = y.*conj(y)/length(t);
plot(f,power);xgrid(color("green"));
a = gca();
a.x_location = "origin";
a.y_location = "origin";
xgrid(color("green"));
xtitle('Power Spectrum','F Frequency Axis','Magnitude');

Output graph :

Page 16
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Result: The Power Spectral Density (PSD) of signal has been calculated and
corresponding graph has been plotted.

Page 17
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

6. Implementation of butterworth LP IIR filter for a given sequence


Aim: To design butterworth low pass filter and implement it for a given
sequence

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The low pass butterworth filter is all pole filter whose magnitude is given
by the relation below. The terms in the filter will be explained below.

|Ha(jΩ)| = 1/[1 +(Ω/Ωc)2N](1/2)

The variable N indicates the order of the filter. The variable Ω is the frequency
variable. The variable Ωc is the cut-off frequency. From the above relation we
calculate the order of the filter and proceed further.

Inbuilt functions used in this piece of code


Log10 Used find the logarithm value of the numerical data
Iir Used to find the system function of filter with given specifications
Frmag Used to find the magnitude spectrum of the given system function
Flts Used to find the time domain response using system function

Program:
clc;
clear;
close;
fs = 8000;
omegap = 500;
omegas = 2000;
wp = omegap/fs;
ws = omegas/fs;

A1_dB = -3;
A2_dB = -40;
A1 = (10)^(A1_dB/20);
A2 = (10)^(A2_dB/20);
Page 18
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

N = 0.5*(log10(1/A1^2 -1)-log10(1/A2^2 -1))/(log10(wp)-log10(ws));


hz = iir(ceil(N),'lp','butt',[wp ws],[A1 A2]);
disp(hz);
[hzm fr] = frmag(hz,1024);
subplot(2,1,1);
plot(fr,hzm);xgrid(color("green"));
xtitle('Magnitude Spectrum','Normalized Frequency','Magnitude');
n = 0:1023;
x = sin(2*%pi*2500*n/fs);
y = flts(x,hz);
Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: Hence Butterworth low pass filter is designed and implemented on given
sequence.

7. Implementation of butterworth HP filter for a given sequence

Page 19
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Aim: To design butterworth high pass filter and implement it for a given
sequence

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The low pass butterworth filter is all pole filter whose magnitude is given
by the relation below. The terms in the filter will be explained below.

|Ha(jΩ)| = 1/[1 +(Ω/Ωc)2N](1/2)

The variable N indicates the order of the filter. The variable Ω is the frequency
variable. The variable Ωc is the cut-off frequency. From the above relation we
calculate the order of the filter and proceed further.

Inbuilt functions used in this piece of code


Log10 Used find the logarithm value of the numerical data
Iir Used to find the system function of filter with given specifications
Frmag Used to find the magnitude spectrum of the given system function
Flts Used to find the time domain response using system function

Program:
clc;
clear;
close;
fs = 8000;
omegap = 500;
omegas = 2000;
wp = omegap/fs;
ws = omegas/fs;
A1_dB = -3;
A2_dB = -40;
A1 = (10)^(A1_dB/20);
A2 = (10)^(A2_dB/20);
N = 0.5*(log10(1/A1^2 -1)-log10(1/A2^2 -1))/(log10(500)-log10(2000));
hz = iir(ceil(N),'hp','butt',[ws],[A1 A2]);
[hzm fr] = frmag(hz,1024);
Page 20
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

subplot(2,1,1);
plot(fr',hzm');xgrid(color("green"));
xtitle('Magnitude Spectrum','Normalized Frequency','Magnitude');
n = 0:1023;
x = 2*sin(2*%pi*2500*n/fs);
y = flts(x,hz);
Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: Hence Butterworth high pass filter is designed and implemented on given
sequence.

8. Implementation of Chebyshev I LP filter for a given sequence


Aim: To design chebyshev type I lowpass pass filter and implement it for
a given sequence

Page 21
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The type I chebyshev low pass filter has ripple in pass band only. The
magnitude response is given by relation

|Ha(jΩ)| = 1/[1 + ɛ2(TN) 2(Ω/Ωc)]1/2

The terms in the above relation are explained below:


ɛ = Constant related to the ripple in the pass band.
Ωc = Cut-off frequency of the given filter.
TN = Chebyshev polynomial of order N

TN = {cos(Ncos-1x) for |x| ≤ 1


{cos(Ncos-1x) for |x| > 1
Program:
clc;
clear;
close;
omegap = 500;
omegas = 1000;
fs = 8000;
A1_dB = -1;
A2_dB = -40;
A2 = 10^(A2_dB/20);
A_2= A2^2;
//N = log10((sqrt(1-A_2) + sqrt(1-A_2*1.259))/0.5088*A2)/(log10( 2 + sqrt(3)));
N = 4;
hz = iir(4,'lp','cheb1',[0.0625 0.125],[0.108,0.108]);
[hzm,fr] = frmag(hz,256);
subplot(2,1,1)
plot(fr,hzm);xgrid(color("green"));
xtitle('Chebyshev Type 1 Filter','Frequency','Magnitude');
n = 0:1023;
x = 2*sin(2*%pi*200*n/fs);
y = flts(x,hz);

Page 22
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot2d(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: Hence Chebyshev type I low pass filter is designed and implemented on
given sequence.
9. Implementation of Chebyshev I HP filter for a given sequence
Aim: To design chebyshev type I high pass filter and implement it for a
given sequence

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Page 23
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Theory: The type I chebyshev high pass filter has ripple in pass band only. The
magnitude response is given by relation

|Ha(jΩ)| = 1/[1 + ɛ2(TN) 2(Ω/Ωc)]1/2

The terms in the above relation are explained below:


ɛ = Constant related to the ripple in the pass band.
Ωc = Cut-off frequency of the given filter.
TN = Chebyshev polynomial of order N

TN = {cos(Ncos-1x) for |x| ≤ 1


{cos(Ncos-1x) for |x| > 1
Program:
clc;
clear;
close;
omegap = 500;
omegas = 1000;
fs = 8000;
A1_dB = -1;
A2_dB = -40;
A2 = 10^(A2_dB/20);
A_2= A2^2;
//N = log10((sqrt(1-A_2) + sqrt(1-A_2*1.259))/0.5088*A2)/(log10( 2 + sqrt(3)));
N = 4;
hz = iir(4,'hp','cheb1',[0.125],[0.108,0.108]);
[hzm,fr] = frmag(hz,256);

subplot(2,1,1)
plot(fr,hzm);xgrid(color("green"));
xtitle('Chebyshev Type 1 Filter','Frequency','Magnitude');
n = 0:1023;
x = 2*sin(2*%pi*2200*n/fs);
y = flts(x,hz);

Page 24
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot2d(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: The Chebyshev type I high pass filter is designed and


implemented for a given sequence.

10. Implementation of Chebyshev II LP filter for a given sequence


Aim: To design chebyshev type II lowpass pass filter and implement it
for a given sequence

Page 25
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The type II chebyshev low pass filter has ripple in pass band only. The
magnitude response is given by relation

|Ha(jΩ)| = 1/[1 + ɛ2((TN) 2(Ω/Ωc)/(TN)2(Ωs/Ω))]1/2

The terms in the above relation are explained below:


ɛ = Constant related to the ripple in the pass band.
Ωc = Cut-off frequency of the given filter.
Ωs = Stop band frequency of the given filter.
TN = Chebyshev polynomial of order N

TN = {cos(Ncos-1x) for |x| ≤ 1


{cos(Ncos-1x) for |x| > 1
Program:
clc;
clear;
close;
omegap = 500;
omegas = 1000;
fs = 8000;
A1_dB = -1;
A2_dB = -40;
A2 = 10^(A2_dB/20);
A_2= A2^2;
//N = log10((sqrt(1-A_2) + sqrt(1-A_2*1.259))/0.5088*A2)/(log10( 2 + sqrt(3)));
N = 4;
hz = iir(4,'lp','cheb2',[0.0625 0.125],[0.108,0.108]);
[hzm,fr] = frmag(hz,256);
subplot(2,1,1)
plot(fr,hzm);xgrid(color("green"));
xtitle('Chebyshev Type 2 Filter','Frequency','Magnitude');
n = 0:1023;
x = 2*sin(2*%pi*2200*n/fs);

Page 26
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

y = flts(x,hz);
Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot2d(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: The Chebyshev type II low pass filter is designed and implemented for the
given sequence.

11. Implementation of Chebyshev II HP filter for a given sequence


Aim: To design chebyshev type II high pass filter and implement it for a
given sequence

Page 27
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory:
Theory: The type II chebyshev high pass filter has ripple in pass band only. The
magnitude response is given by relation

|Ha(jΩ)| = 1/[1 + ɛ2((TN) 2(Ω/Ωc)/(TN)2(Ωs/Ω))]1/2

The terms in the above relation are explained below:


ɛ = Constant related to the ripple in the pass band.
Ωc = Cut-off frequency of the given filter.
Ωs = Stop band frequency of the given filter.
TN = Chebyshev polynomial of order N

TN = {cos(Ncos-1x) for |x| ≤ 1


{cos(Ncos-1x) for |x| > 1
Program:
clc;
clear;
close;
omegap = 500;
omegas = 1000;
fs = 8000;
A1_dB = -1;
A2_dB = -40;
A2 = 10^(A2_dB/20);
A_2= A2^2;
//N = log10((sqrt(1-A_2) + sqrt(1-A_2*1.259))/0.5088*A2)/(log10( 2 + sqrt(3)));
N = 4;
hz = iir(4,'hp','cheb2',[0.125],[0.108,0.108]);
[hzm,fr] = frmag(hz,256);
subplot(2,1,1)
plot(fr,hzm);xgrid(color("green"));
xtitle('Chebyshev Type 2 Filter','Frequency','Magnitude');
n = 0:1023;
Page 28
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

x = 2*sin(2*%pi*2200*n/fs);
y = flts(x,hz);
Y = abs(fft(y))/1024;
f = (0:1023)*fs/1024;
subplot(2,1,2);
plot2d(f,Y);xgrid(color("green"));
xtitle('Magnitude Spectrum Of Output','Frequency f','Magnitude');

Output graph:

Result: Hence the Chebyshev type II high pass filter is designed and implemented
for the given sequence.
12. Frequency Response of windows

Aim: To obtain the frequency Response of windows.

Page 29
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Theory: The various windows for the design of FIR filters are defined below. The
frequency response of the windows is plotted in this experiment. The windows are
defined below one after the other.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Rectangular Window
The rectangular window is defined as

Definition ( odd):

Transform:

The DTFT of a rectangular window is shown in Fig

Page 30
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Bartlett (``Triangular'') Window

Definition:

Transform:

The DTFT of a bartlett window is shown in Fig

Hamming window
Definition:
1   2 n  
w[ n]   1  cos  ,0  n  M 
2   M  

The DTFT of a hamming window is shown in Fig

Page 31
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Hanning window
If y represents the output sequence Hanning {X}, the Hanning Window VI obtains the elements
of y from
yi = xi[0.54 – 0.46cos(w)]

for i = 0, 1, 2, …, n – 1,
where n is the number of elements in the input sequence X.
The DTFT of a hanning window is shown in Fig

Page 32
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Blackman window
  2 n   4 n 
w[n]  0.42  0.5cos    0.08cos  
  M   M 

The DTFT of a blackman window is shown in Fig

Inbuilt functions used in this piece of code


Window Used for defining various windows of constant per-defined length

Program:
clc;
clear;
close;
N = 25;
whm = window('hm', N);
wkr = window('kr', N, 6);
wch = window('ch', N, [0.005 -1]);
whn = window('hn',N);
subplot(2,1,1);
plot((1:N)', [whm; wkr; wch; whn]')
a = gca();a.x_location=”origin”;a.y_location=”origin”;
xtitle('Profile plot','n','w_n');
n = 256;

Page 33
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

[Whm,fr] = frmag(whm, n);


[Wkr,fr] = frmag(wkr, n);
[Wch,fr] = frmag(wch, n);
[Whn,fr] = frmag(whn, n);
subplot(2,1,2);
plot(fr', 20*log10([Whm; Wkr; Wch; Whn]'))
a = gca();a.x_location=”origin”;a.y_location=”origin”;
xtitle('Magnitude plot','Pulsation (rad/s)','Magnitude');
legend(["Hamming N=25"; "Kaiser N=25, Beta=6"; "Chebychev N=25,
dp=0.005"; "Hanning N = 25"]);

Output graph:

Result: Frequency response of windowing sequence has been verified.

Page 34
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

13. FIR Filter Design using windows

Aim: To write a program of FIR Filter design using windows


a) Low pass filter using windows
b) High pass filter using windows
Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Rectangular Window
The rectangular window is defined as

Definition ( odd):

Transform:

Bartlett (``Triangular'') Window

Definition:

Transform:

Hamming window
Definition:

Page 35
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

1   2 n  
w[ n]   1  cos  ,0  n  M 
2   M  

Hanning window
If y represents the output sequence Hanning {X}, the Hanning Window VI obtains the elements
of y from
yi = xi[0.54 – 0.46cos(w)]

for i = 0, 1, 2, …, n – 1,
where n is the number of elements in the input sequence X.
Blackman window
  2 n   4 n 
w[n]  0.42  0.5cos    0.08cos  
  M   M 

Program:
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;
wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('lp',ceil(N),[wp ws],"re",[0 0]);

Page 36
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Rectangle Window','f Frequecy','Magnitude');

Output graph :

Result: Hence the FIR low pass filter is designed and magnitude spectrum plotted.
Program:
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;

Page 37
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('hp',floor(N),[ws],"re",[0 0]);
plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Rectangular Window','f Frequecy','Magnitude');

Output graph:

Result : The Finite Impulse Response high pass filter with rectangular window is
designed.
Page 38
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Program:
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;
wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('lp',ceil(N),[wp ws],"hm",[0 0]);
plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Hamming Window','f Frequecy','Magnitude');

Output graph:

Result: The Finite Impulse Response low pass filter using Hamming window is
designed.

Page 39
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Program:
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;
wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('hp',floor(N),[ws],"hm",[0 0]);
plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Hamming Window','f Frequecy','Magnitude');

Output graph:

Result: The Finite Impulse Response high pass filter using Hamming window is
designed.

Page 40
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Program:
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;
wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('lp',ceil(N),[wp ws],"hn",[0 0]);
plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Hanning Window','f Frequecy','Magnitude');
Output graph:

Result: The Finite Impulse Response low pass filter using Hanning window is
designed.

Page 41
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Program
clc;
clear;
close;
omegap = 1200;
omegas = 1700;
fs = 10000;
rp = 0.01;
rs = 0.02;
wp = omegap/fs;
ws = omegas/fs;
N = ((-20*log10(sqrt(rp*rs)))-13)/(14.6*((omegas - omegap)/fs));
if (modulo(N,2)~=0) then
N1 = N;
N = N1-1;
else
N1 = N + 1;
end
disp(N);
[wft,hm,fr]=wfir('hp',floor(N),[ws],"hn",[0 0]);
plot(fr,hm);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Hanning Window','f Frequecy','Magnitude');
Output graph

Result: Hence Finite Impulse Response filter with Hanning window is designed.

Page 42
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

14. Generation of DTMF Signals

Aim: To generate DTMF signal tone.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Theory: DTMF stands for dual tone multi frequency. It is popular switching
technique between telephones and switching centers. A unique sinusoidal signal is
generated upon dialing each number. The signal so generated will have two
different frequency components. The signal format so generated is pictorially
represented below.

1209 Hz 1336 Hz 1477 Hz


697 Hz 1 2 3
770 Hz 4 5 6
852 Hz 7 8 9
941 Hz * 0 #
Program
clc;
clear;
close;
number = string("1");
fs = 8000;
t = 0:(1/fs):1';
key_1 = sin(2*%pi*697*t) + sin(2*%pi*1209*t);
key_2 = sin(2*%pi*697*t) + sin(2*%pi*1336*t);
key_3 = sin(2*%pi*697*t) + sin(2*%pi*1447*t);
key_4 = sin(2*%pi*770*t) + sin(2*%pi*1209*t);
key_5 = sin(2*%pi*770*t) + sin(2*%pi*1336*t);
key_6 = sin(2*%pi*770*t) + sin(2*%pi*1477*t);
key_7 = sin(2*%pi*852*t) + sin(2*%pi*1209*t);
key_8 = sin(2*%pi*852*t) + sin(2*%pi*1336*t);
key_9 = sin(2*%pi*852*t) + sin(2*%pi*1447*t);
key_str = sin(2*%pi*941*t) + sin(2*%pi*1209*t);
key_0 = sin(2*%pi*941*t) + sin(2*%pi*1336*t);
key_# = sin(2*%pi*941*t) + sin(2*%pi*1477*t);
tone = zeros(1,8000);
if(number == "1") then
tone = key_1;

Page 43
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

sound(tone);
end
if(number == "2") then
tone = key_2;
sound(tone);
end
if(number == "3") then
tone = key_3;
sound(tone);
end
if(number == "4") then
tone = key_4;
sound(tone);
end
if(number == "5") then
tone = key_5;
sound(tone);
end
if(number == "6") then
tone = key_6;
sound(tone);
end
if(number == "7") then
tone = key_7;
sound(tone);
end
if(number == "8") then
tone = key_8;
sound(tone);
end
if(number == "9") then
tone = key_9;
sound(tone);
end
if(number == "*") then
tone = key_str;
sound(tone);
end

Page 44
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

if (number == "0") then


tone = key_0;
sound(tone);
end
if (number == "#") then
tone = key_#;
sound(tone);
end
subplot(2,1,1);
plot2d(t,tone);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Generated Tone','t Time','Amplitude');
fd = fs*(0:(length(t)-1))/length(t);
ffk = fft(tone);
subplot(2,1,2);
plot2d3(fd,abs(ffk));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Magnitude Spectrum','f Frequency','Amplitude');

Output graph

Result: The DTMF signal for respective number dialed is generated.

Page 45
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

15. Generation of sinusoidal signal through filtering

Aim: To generate the sinusoidal waveform through the concept of filtering

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: In this approach we will use a IIR filter for obtaining the sinusoidal signal.
In this approach the difference equation we will use to design the filter is given
below.

..y(n) = -a1*y(n-1) –a1*y(n-2) +b0*∂(n)

The initial conditions for the above difference equation are assumed to be zero.
There by assuming that the system is assumed to be relaxed. The constants of the
above difference equation are obtained as done in experiment one. Here we will
assume a 300Hz sampled at 8000Hz.
Program
clc;
clear;
close;
x = [1 zeros(1,1200)];
num = [0.4669];
den = [1 -1.9447 1];
y = filter(num,den,x);
plot(y);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Sinusoidal Signal','n Time','Amplitude');

Page 46
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output graph

Result: A sinusoidal signal waveform is generated through concept of filtering.

Page 47
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

16. Implementation of Decimation process

Aim: To implement decimation process on a given sequence

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: Multirate sampling is nothing but multiple sample rates. This is very
important because a given system could be build with a number of small
subsystems. Each subsystem could operate at different rate. To synchronize the
operation between systems we go for multirate sampling.

Two basic operations in multirate systems are decimation(downsampling) and


interpolation(upsampling).

Program
clc;
clear all;
close;
fm=10;
fs=160;
t=0:1/fs:0.5;
m=cos(2*%pi*fm*t);
subplot(3,1,1);plot(m(1:50));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('sinusoidal signal before sampling','t Time Axis','Amplitude' );
subplot(3,1,2);plot2d3(m(1:50));xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('sinusoidal signal after sampling','t Time Axis','Amplitude');
downsampling_m = m(1:2:length(m));
subplot(3,1,3);plot(1:length(downsampling_m),downsampling_m);
xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('sinusoidal signal after sampling after decimation','t Time Axis','Amplitude');

Page 48
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output graph

Result: Decimated signal is obtained and is plotted.

Page 49
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

17. Implementation of interpolation process

Aim: To implement Interpolation process on a given sequence.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS
Program
clc;
clear;
close;
fm = 10;
fs = 1000;
t = 0:(1/fs):1;
x = sin(2*%pi*fm*t);
subplot(2,1,1);
plot(t,x);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Original Signal','t Time','Amplitude');
us=zeros(1,2*length(x));
us(1:2:2*length(x))=x;
subplot(2,1,2);
plot2d3(1:length(us),us);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('Upsampled Signal','t Time','Amplitude');

Output graph

Result: Hence the interpolation signal is obtained and plotted.

Page 50
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

18. Implementation of I/D sampling rate converter


Aim: To implement sampling rate conversion by a rational factor on a given
sequence.

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Program
clc;
clear;
close;
Fs1 = 10000;
Fs2 = 14000;
t1 = 0:1/Fs1:10;
t2 = 0:1/Fs2:10;
F0 = 500;
u1 = sin(2*%pi*F0*t1);
u2 = sin(2*%pi*F0*t2);
u2b = intdec(u1, Fs2/Fs1)
plot(u2b, u2);xgrid(color("green"));
a = gca();a.x_location="origin";a.y_location = "origin";
xtitle('I/D sampled signal','t Time','Amplitude');

Output graph

Result: Hence the I/D sampled signal is obtained and plotted.

Page 51
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

19. Impulse response of first order and second order


system

Aim: To find the impulse response of first and second order system

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: The impulse response of a LTI system can be obtained by taking


convolving the filter with the impulse.

Program:
clc;
clear;
close;
x = [1 zeros(1,99)];
num1 = [1]
den1 = [1 -0.375];
num2 = [1 0.25];
den2 = [1 -0.375 -0.666]
y1 = filter(num1,den1,x);
subplot(2,1,1);
plot2d3(y1);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('First Order Impulse Response','n time','Amplitude');
y2 = filter(num2,den2,x);
subplot(2,1,2);
plot2d3(y2);xgrid(color("green"));
a = gca();a.x_location = "origin";a.y_location = "origin";
xtitle('Second Order Impulse Response','n time','Amplitude');

Page 52
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output graph

Result: The impulse response of first order and second order system are obtained
and plotted.

Page 53
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

20. Noise Removal


Aim: To add noise above 3 KHz removing the interference & suppression by a
400Hz tone

Software: Scilab 6.0.0 and system loaded with Linux flavor of ubuntu 16.04 LTS

Theory: Noise reduction is the process of removing noise from a signal. All
recording devices, both analogue or digital, have traits which make them
susceptible to noise. Noise can be random or white noise with no coherence, or
coherent noise introduced by the device's mechanism or processing algorithms.
In electronic recording devices, a major form of noise is hiss caused by random
electrons that, heavily influenced by heat, stray from their designated path. These
stray electrons influence the voltage of the output signal and thus create detectable
noise.

In the case of photographic film and magnetic tape, noise (both visible and
audible) is introduced due to the grain structure of the medium. In photographic
film, the size of the grains in the film determines the film's sensitivity, more
sensitive film having larger sized grains. In magnetic tape, the larger the grains of
the magnetic particles (usually ferric oxide or magnetite), the more prone the
medium is to noise. To compensate for this, larger areas of film or magnetic tape
may be used to lower the noise to an acceptable level.

Page 54
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Architecture of DSP chips-TMS 320C 6713 DSP Processor

A signal can be defined as a function that conveys information, generally about the state or
behavior of a physical system. There are two basic types of signals viz Analog (continuous time
signals which are defined along a continuum of times) and Digital (discrete-time).
Remarkably, under reasonable constraints, a continuous time signal can be adequately
represented by samples, obtaining discrete time signals. Thus digital signal processing is an ideal
choice for anyone who needs the performance advantage of digital manipulation along with
today’s analog reality.

Hence a processor which is designed to perform the special operations(digital


manipulations) on the digital signal within very less time can be called as a Digital signal
processor. The difference between a DSP processor, conventional microprocessor and a
microcontroller are listed below.

Microprocessor or General Purpose Processor such as Intel xx86 or Motorola 680xx family
Contains - only CPU
-No RAM
-No ROM
-No I/O ports
-No Timer
Microcontroller such as 8051 family
Contains - CPU
- RAM
- ROM
-I/O ports
- Timer &
- Interrupt circuitry
Some Micro Controllers also contain A/D, D/A and Flash Memory

DSP Processors such as Texas instruments and Analog Devices


Contains - CPU
- RAM
-ROM
- I/O ports
- Timer
Optimized for – fast arithmetic
- Extended precision
- Dual operand fetch
- Zero overhead loop
- Circular buffering

Page 55
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

The basic features of a DSP Processor are

Feature Use
Fast-Multiply accumulate Most DSP algorithms, including filtering, transforms, etc. are
multiplication- intensive

Multiple – access memory Many data-intensive DSP operations require reading a program
architecture instruction and multiple data items during each instruction cycle
for best performance

Specialized addressing modes Efficient handling of data arrays and first-in, first-out buffers in
memory
Specialized program control Efficient control of loops for many iterative DSP algorithms.
Fast interrupt handling for frequent I/O operations.

On-chip peripherals and I/O On-chip peripherals like A/D converters allow for small low cost
interfaces system designs. Similarly I/O interfaces tailored for common
peripherals allow clean interfaces to off-chip I/O devices.

ARCHITECTURE OF 6713 DSP PROCESSOR

This chapter provides an overview of the architectural structure of the TMS320C67xx DSP,
which comprises the central processing unit (CPU), memory, and on-chip peripherals. The
C67xE DSPs use an advanced modified Harvard architecture that maximizes processing power
with eight buses. Separate program and data spaces allow simultaneous access to program
instructions and data, providing a high degree of parallelism. For example, three reads and one
write can be performed in a single cycle. Instructions with parallel store and application-specific
instructions fully utilize this architecture. In addition, data can be transferred between data and
program spaces. Such
Parallelism supports a powerful set of arithmetic, logic, and bit-manipulation operations that can
all be performed in a single machine cycle. Also, the C67xx DSP includes the control
mechanisms to manage interrupts, repeated operations, and function calling.

Page 56
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Fig BLOCK DIAGRAM OF TMS 320VC 6713

Bus Structure

The C67xx DSP architecture is built around eight major 16-bit buses (four program/data buses
and four address buses):
_ The program bus (PB) carries the instruction code and immediate operands from program
memory.
_ Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU, data
address generation logic, program address generation logic, on-chip peripherals, and data
memory.
_ The CB and DB carry the operands that are read from data memory.
_ The EB carries the data to be written to memory.
_ Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for instruction
execution.

Page 57
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

The C67xx DSP can generate up to two data-memory addresses per cycle using the two auxiliary
register arithmetic units (ARAU0 and ARAU1). The PB can carry data operands stored in
program space (for instance, a coefficient table) to the multiplier and adder for
multiply/accumulate operations or to a destination in data space for data move instructions
(MVPD and READA). This capability, in conjunction with the feature of dual-operand read,
supports the execution of single-cycle, 3-operand instructions such as the FIRS instruction. The
C67xx DSP also has an on-chip bidirectional bus for accessing on-chip peripherals. This bus is
connected to DB and EB through the bus exchanger in the CPU interface. Accesses that use this
bus can require two or more cycles for reads and writes, depending on the peripheral’s structure.

Central Processing Unit (CPU)

The CPU is common to all C67xE devices. The C67x CPU contains:

_ 40-bit arithmetic logic unit (ALU)


_ Two 40-bit accumulators
_ Barrel shifter
_ 17 × 17-bit multiplier
_ 40-bit adder
_ Compare, select, and store unit (CSSU)
_ Data address generation unit
_ Program address generation unit

Arithmetic Logic Unit (ALU)

The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit (ALU)
and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean
operations. The ALU uses these inputs:

_ 16-bit immediate value


_ 16-bit word from data memory
_ 16-bit value in the temporary register, T
_ Two 16-bit words from data memory
_ 32-bit word from data memory
_ 40-bit word from either accumulator

The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.

Page 58
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Fig ALU UNIT


Accumulators

Accumulators A and B store the output from the ALU or the multiplier/adder block. They can
also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder.
Each accumulator is divided into three parts:
_ Guard bits (bits 39–32)
_ High-order word (bits 31–16)
_ Low-order word (bits 15–0)
Instructions are provided for storing the guard bits, for storing the high- and the low-order
accumulator words in data memory, and for transferring 32-bit accumulator words in or out of
data memory. Also, either of the accumulators can be used as temporary storage for the other.

Barrel Shifter

The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data memory
(using CB or DB), and a 40-bit output connected to the ALU or to data memory (using EB). The
barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the input
data. The shift requirements are defined in the shift count field of the instruction, the shift count
field (ASM) of status register ST1, or in temporary register T (when it is designated as a shift
count register).The barrel shifter and the exponent encoder normalize the values in an

Page 59
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

accumulator in a single cycle. The LSBs of the output are filled with 0s, and the MSBs can be
either zero filled or sign extended, depending on the state of the sign-extension mode bit (SXM)
in ST1. Additional shift capabilities enable the processor to perform numerical scaling, bit
extraction, extended arithmetic,
and overflow prevention operations.
Multiplier/Adder Unit
The multiplier/adder unit performs 17 _ 17-bit 2s-complement multiplication with a 40-bit
addition in a single instruction cycle. The multiplier/adder block consists of several elements: a
multiplier, an adder, signed/unsigned input control logic, fractional control logic, a zero detector,
a rounder (2s complement), overflow/saturation logic, and a 16-bit temporary storage register
(T). The multiplier has two inputs: one input is selected from T, a data-memory operand, or
accumulator A; the other is selected from program memory, data memory, accumulator A, or an
immediate value. The fast, on-chip multiplier allows the C54x DSP to perform operations
efficiently such as convolution, correlation, and filtering. In addition, the multiplier and ALU
together execute multiply/accumulate (MAC) computations and ALU operations in parallel in a
single instruction cycle. This function is used in determining the Euclidian distance and in
implementing symmetrical and LMS filters, which are required for complex DSP algorithms. See
section 4.5, Multiplier/Adder Unit, on page 4-19, for more details about the multiplier/adder unit.

Page 60
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Fig MULTIPLIER/ADDER UNIT

These are the some of the important parts of the processor and you are instructed to go through
the detailed architecture once which helps you in developing the optimized code for the required
application.

Page 61
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

21. Convolution

Aim: To perform the linear & circular convolution using DSP Processor.
Theory:

Convolution is a formal mathematical operation, just as multiplication, addition, and integration.


Addition takes two numbers and produces a third number, while convolution takes two signals
and produces a third signal. Convolution is used in the mathematics of many fields, such as
probability and statistics. In linear systems, convolution is used to describe the relationship
between three signals of interest: the input signal, the impulse response, and the output signal.

Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is
folded and right shifted before the convolution sum is found.

Program:
#include<stdio.h>
main()
{
int m=4;
int n=4;
int i=0,j;
int x[10]={1,2,3,4,0,0,0};
int h[10]={1,2,3,4,0,0,0};
int y[10];
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}

Page 62
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Output:

Page 63
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

// circular convolution//
#include<stdio.h>

void main()
{
int m,n,x[10],h[10],y[10],i,j,k,x2[10],a[10];
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if((m-n)!=0)
{
if(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}

for(i=m;i<n;i++)
x[i]=0;
m=n;
}

y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];

Page 64
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

y[k]+=x[i]*x2[i];
}
}
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);

Output:

Page 65
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Result: Convolution of two sequences has been performed and verified by using DSP
processor.

Page 66
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

22. Fast Fourier Transform

Aim: To perform fast Fourier transform of a sequence using DSP processor.

Theory:
A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform
(DFT) and its inverse. There are many different FFT algorithms involving a wide range of
mathematics, from simple complex-number arithmetic to group theory and number theory; this
article gives an overview of the available techniques and some of their general properties, while
the specific algorithms are described in subsidiary articles linked below.

The DFT is obtained by decomposing a sequence of values into components of different


frequencies. This operation is useful in many fields (see discrete Fourier transform for properties
and applications of the transform) but computing it directly from the definition is often too slow
to be practical. An FFT is a way to compute the same result more quickly: computing the DFT of
N points in the naive way, using the definition, takes O(N2) arithmetical operations, while an FFT
can compute the same DFT in only O(N log N) operations. The difference in speed can be
enormous, especially for long data sets where N may be in the thousands or millions. In practice,
the computation time can be reduced by several orders of magnitude in such cases, and the
improvement is roughly proportional to N / log(N). This huge improvement made the calculation
of the DFT practical; FFTs are of great importance to a wide variety of applications, from digital
signal processing and solving partial differential equations to algorithms for quick multiplication
of large integers.

The best-known FFT algorithms depend upon the factorization of N, but there are FFTs with
O(N log N) complexity for all N, even for prime N. Many FFT algorithms only depend on the
fact that is an N-th primitive root of unity, and thus can be applied to analogous transforms
over any finite field, such as number-theoretic transforms. Since the inverse DFT is the same as
the DFT, but with the opposite sign in the exponent and a 1/N factor, any FFT algorithm can
easily be adapted for it.

Program:
#include <stdio.h>
#include <math.h>

void butterfly(double *,double *,double *,double *,double *,double *);


int main()
{
int i;
double x[8]={1,2,3,4,4,3,2,1};
//double x[8]={4,3,2,1,0,0,0,0};
double XR[8];
double XI[8]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
double WNR[4]={0.999969, 0.707092, 0.0, -0.707092};
double WNI[4]={0.0 , -0.707092,-0.999969,-0.707092};

Page 67
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

double spectrum[8];

// store data in bit reversal order


XR[0]=x[0];
XR[1]=x[4];
XR[2]=x[2];
XR[3]=x[6];
XR[4]=x[1];
XR[5]=x[5];
XR[6]=x[3];
XR[7]=x[7];
// FIRST STAGE OF BUTTERFLY
butterfly(&XR[0],&XI[0],&XR[1],&XI[1],&WNR[0],&WNI[0]);
butterfly(&XR[2],&XI[2],&XR[3],&XI[3],&WNR[0],&WNI[0]);
butterfly(&XR[4],&XI[4],&XR[5],&XI[5],&WNR[0],&WNI[0]);
butterfly(&XR[6],&XI[6],&XR[7],&XI[7],&WNR[0],&WNI[0]);

// SECOND STAGE OF BUTTERFLY

butterfly(&XR[0],&XI[0],&XR[2],&XI[2],&WNR[0],&WNI[0]);
butterfly(&XR[1],&XI[1],&XR[3],&XI[3],&WNR[2],&WNI[2]);
butterfly(&XR[4],&XI[4],&XR[6],&XI[6],&WNR[0],&WNI[0]);
butterfly(&XR[5],&XI[5],&XR[7],&XI[7],&WNR[2],&WNI[2]);

// THIRD STAGE OF BUTTERFLY


butterfly(&XR[0],&XI[0],&XR[4],&XI[4],&WNR[0],&WNI[0]);
butterfly(&XR[1],&XI[1],&XR[5],&XI[5],&WNR[1],&WNI[1]);
butterfly(&XR[2],&XI[2],&XR[6],&XI[6],&WNR[2],&WNI[2]);
butterfly(&XR[3],&XI[3],&XR[7],&XI[7],&WNR[3],&WNI[3]);

for(i=0;i<8;i++)
{
XR[i]*=64.0;
XI[i]*=64.0;
}
for(i=0;i<8;i++)
{
printf("\n FFT XR[%d] = %lf XI[%d]= %lf",i,XR[i],i,XI[i]);
}
return(0);
}
void butterfly(double *ar,double *ai,double *br,double *bi,double *wr,double *wi)
{
double tr,ti;
*ar/=4.0;
*ai/=4.0;

Page 68
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

tr=*ar*2;
ti=*ai*2;
*br/=4.0;
*bi/=4.0;
*ar+=*br * *wr - *bi * *wi;
*ai+=*br * *wi + *bi * *wr;
*br= tr - *ar;
*bi= ti - *ai;
}
Output:

Page 69
Jagruti Institute of Engineering & TechnologyDSP Lab Manual (2018-2019)

Result: Fast Fourier transform has been performed and verified using DSP processor.

Page 70

You might also like