KEMBAR78
DSP Lab Manual | PDF | Sampling (Signal Processing) | Matrix (Mathematics)
0% found this document useful (0 votes)
24 views113 pages

DSP Lab Manual

The document outlines the syllabus for a Digital Signal Processing lab course, detailing a comprehensive list of experiments including sequence generation, convolution, filter design, and DSP kit usage. It also introduces MATLAB, covering its basic functionalities, arithmetic operations, variable assignments, vectors, matrices, and plotting techniques. Additionally, it includes programming concepts such as script and function files, loops, and conditional statements, providing a foundational understanding for students in numerical computation and visualization.

Uploaded by

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

DSP Lab Manual

The document outlines the syllabus for a Digital Signal Processing lab course, detailing a comprehensive list of experiments including sequence generation, convolution, filter design, and DSP kit usage. It also introduces MATLAB, covering its basic functionalities, arithmetic operations, variable assignments, vectors, matrices, and plotting techniques. Additionally, it includes programming concepts such as script and function files, loops, and conditional statements, providing a foundational understanding for students in numerical computation and visualization.

Uploaded by

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

EC 113 - DIGITAL SIGNAL PROCESSING AND DSP PROCESSORS LAB

Semester – V
List of Experiments
1. GENERATION OF SEQUENCES (FUNCTIONAL & RANDOM)
2. AUTO-CORRELATION AND CROSS CORRELATION
3. LINEAR AND CIRCULAR CONVOLUTION
i) Linear Convolution using inbuilt command
ii) Linear Convolution using for loop
iii) Circular Convolution using inbuilt command
iv) Circular Convolution using for loop
v) Circular Convolution using FFT
4. VERIFICATION OF SAMPLING THEOREM
5. SAMPLING AND EFFECT OF ALIASING
6. SPECTRUM ANALYSIS USING DFT / FFT
7. DESIGN OF IIR FILTER
i) Butterworth analog filters – LP, HP, BP and BS
ii) Chebyshev Type-I analog filters – LP, HP, BP and BS
iii) Chebyshev Type-II analog filters – LP, HP, BP and BS
iv) Butterworth digital filters – LP and HP
v) Chebyshev Type-I analog filters – LP and HP
vi) Chebyshev Type-II analog filters – LP and HP
8. DESIGN OF FIR FILTER
i) Rectangular window
ii) Barlet window
iii) Blackman window
iv) Hamming window
v) Hanning window
9. MULTIRATE FILTERS
10. STUDY OF TMS320C6745 DSP KIT
11. LINEAR CONVOLUTION USING DSP KIT
12. a) FFT 8-POINT DIT USING TMS320C6745 DSP KIT
b) FFT 8-POINT DIF USING TMS320C6745 DSP KIT
13. WAVEFORM GENERATION USING TMS320C6745 DSP KIT
14.a) FIR LOW PASS FILTER USING TMS320C6745 DSP KIT
b) IIR LOW PASS FILTER USING TMS320C6745 DSP KIT
INTRODUCTION TO MATLAB

What is MATLAB?

MATLAB (“MATrix LABoratory”) is a tool for numerical computation and visualization. The
basic data element is a matrix, so if you need a program that manipulates array-based data it is
generally fast to write and run in MATLAB (unless you have very large arrays or lots of
computations, in which case you’re better off using C or Fortran)

First Steps

You should start MATLAB by simply typing matlab if you are working on a Unix system or
just by double clicking the MATLAB icon if you are using a Windows based system. If all
goes well you will see a MATLAB prompt

>>

inviting you to initiate a calculation. In what follows, any line beginning with >> indicates
typed input to MATLAB. You are expected to type what follows by not the >> prompt itself.
MATLAB supplies that automatically.

Arithmetic with MATLAB

MATLAB understands the basic arithmetic operations: +, -, *, /. Powers are indicated with ^,
thus typing

>> 5*4 + 3^2

and pressing enter, results in

ans = 29

The laws of precedence are built in but if in doubt, you should put parentheses appropriately.
For example,

>> 7+3*(2/(8-2))

ans = 8

The sort of elementary functions familiar on hand calculators are also available. For example,
>> sqrt(3^2+4*4)

ans = 5

>> exp(log(3.2))

ans = 3.2
Using Variables

You can assign numerical values to variables for use in subsequent calculations. For example
the volume of a sphere can be calculated via the following sequence:

>> radius = 3;

>> volume=(4/3)*pi*radius^3

volume = 113.0973

Note that the first line did not seem to produce a result in screen. When MATLAB encounters
an instruction followed by a semi-colon ; it suppresses any visual confirmation. It really does
obey the instruction and records the value of the variable in the memory. This is useful if you
want to avoid cluttering up the screen with intermediate results. Each variable must somehow
be assigned before you make use of it in further calculations. For example if you have followed
the above example with,

>> x=4*pi*radius*h

you should get the result,

??? Undefined function or variable 'h'

This is self-explanatory. If you now type

>> h=3;

>> x=4*pi*radius*h

you should have more success. Incidentally, a quick way of repeating a previous MATLAB
instruction is to press the ‘up-arrow’ key until you recover the command you need. You may
also use the sideways arrows to modify any of the previous commands.

At any point typing the command,

>> who

tells about all the variables that are in the workspace of the current MATLAB session.
Vectors

A vector can be input in several ways. For example,

>> u=[1 3 5];

>> v=[1,3,5];

>> w=1:2:5;

All three commands above yield the same vector. One can perform vector operations such as,

>> z=u+v-w;

Note that the vectors described so far are row vectors. To get a corresponding column vector,
we invoke the transpose of a vector. For example,

>> u’

ans =

The difference between the vectors u and u’ can be understood by typing the commands

>> size(u)

>> size(u’)

which yields the row size followed by the column size for each vector. One can now multiply
vectors appropriately to either yield an innerproduct

>> z=u*u’

or a matrix,

>> z=u’*u
Multiplication of vectors only happens if the inner matrix dimensions agree. For example,

>> u*u

would yield,

??? Error using ==> *

Inner matrix dimensions must agree.

Suppose we want a set of values z given by z = u2 then we want

>> z = u.*u;

where the . is inserted before the * symbol which forces an element-by-element operation.
Similarly u./v and u.^3 can be understood to be the corresponding element-by-element
operations.

Example: Suppose we want to find the distance between two points A and B whose position
vectors are given by a = (1, 2) and b = (5, 5) respectively. The following sequence of commands
can be executed in MATLAB to obtain the desired result:

>> a=[1 2];

>> b=[5 5];

>> d = b – a;

>> dd = d*d’;

>> dist_ab = sqrt(dd)

Script Files

Now suppose we want to modify the position vectors and find the distance between the new
coordinates, it will not be worthwhile to type all the commands again. Instead one can create a
script file, which will contain all the necessary information. To create a new script file, one can
open the text editor and type the following commands,
% dist_ab.m

% Calculates distance between any two position vectors a and b

d=b-a;

dd=d*d’;

dist_ab=sqrt(dd)

Save these contents in a file named dist_ab.m and note that the script file has a ‘.m’ extension
which denotes that it is a MATLAB file. Now one can pick values for the vectors a and b by
simply typing say,

>> a=[1 2 3];

>> b=[5 5 3];

Then find the distance by simply typing

>> dist_ab

dist_ab =

This program can be called repeatedly to find the distance between any two position vectors
that are entered by the user.

Function Files

It was tedious to have to assign the two vectors each time before using the above script file.
One can combine the assignment of input values with the actual instruction, which invokes the
script file by using a function m-file. Not only that, but also one can at the same time assign the
answer to an output variable.

To create a new function file, one can open the text editor and type the following commands,

% distfn.m

% Calculates the distance between two vectors a and b


% Input: a, b (position vectors)

% Output: dist_ab is the distance between a and b

function dist_ab = distfn(a , b)

d= b – a;

dd = d*d’;

dist_ab = sqrt(dd);

Save these contents in a file named distfn.m and we should now be able to run,

>> dist_ab=distfn([1 2 3], [ 5 5 3])

or

>> a=[1 2 3];

>> b=[5 5 3];

>> dist_ab=distfn(a , b);

To save a certain part of the work in the MATLAB session, one can type,

>> diary work1

>> ….

>> ….

>> diary off

All the work between the diary commands will be saved into a file called work1.

Matrices

To define a matrix you start with its name. Square brackets are used to begin and end each
matrix. You can separate elements with a space or a comma, and end each row with a semi-
colon like this:
>> A = [1, 2, -6; 7, 5, 2; -2, 1, 0]

or this:

>> A = [1 2 -6; 7 5 2; -2 1 0]

In either case you have defined the same 3 by 3 matrix named A and you can use it at any time
in a calculation or to define another matrix by using its name (A).

Examples:

>> B = [2 -4 7 ]

B is a 1 by 3 row matrix

>> C = [2; -4; 7; ]

C is a 3 by 1 column matrix

>>D = [5, 8,-2; 3,-4, 5]

D is a 2 by 3 matrix

You can edit individual elements of a matrix as follows:

>> A(1,1) = -5 changes the element in row1 column1 of matrix A to -5

>> D(2,3) = 0 changes the element in row2 column3 of matrix D to 0

To perform operations on matrices you use the symbols ( +, -, * ) from the number keypad or
above the numbers across the top of the keyboard.

Examples:

>> A + A adds the matrix A to itself.

>> B * C multiplies B and C

>> C*B - A A is subtracted from the product of C and B

The symbol ^ (above the number 6) is used to raise a matrix to an exponent as follows:
>> A^3 cubes the matrix A (you might also use A*A*A for the same calculation)

>> C*D an error message is displayed Matlab will give an error message when the

calculation cannot be done because of a dimension mismatch.

To solve the system of equations for (x, y, z) using Gaussian Elimination:

ax+by+cz=u

ex+fy+gz=v

px+qy+rz=w

we perform the following steps in matlab.

>> A = [a b c; e f g; p q r];

>> b = [u; v; w];

>> M = [A b];

>> R = rref(M);

>> X = R(4, 1:3);

More helpful MATLAB commands:

quit or exit either of these closes the program and ends your matlab session.

save filename this command will save all variables (and ONLY the variables - NOT the whole
session) that you have defined in the current session. This is helpful when you enter large
matrices that you want to work with at a later date.

load filename this command loads the variables that you saved in a previous session.

lpr this is the command used to print your diary file. EXIT THE MATLAB PROGRAM. At
the osf1 prompt, type: lpr -Pst220 filename (note: st220 is the printer in ST I room 220. At
other locations you will use another printer name after the -P )

who displays variables you have defined in your current session


why matlab answers the question.(again and again)

clear clears all variables from your current session. Only use this command if you want to lose
everything.

% this is used for comments. Matlab ignores any line that begins with %

Matlab has many built in matrix functions and operators. Some of the useful commands are
listed here:

>> size(A) gives the dimension of the matrix A

>> inv(A) calculates the inverse of the matrix A , if it exists.

>> det(A) calculates the determinant of the matrix A

>> rref(A) calculates the row reduced echelon form of the matrix A

>> A' forms the transpose of the matrix A.

>> eye (2,2) this is the 2 by 2 identity

>> zeros (3,3) builds the zero matrix of any dimension

>> ones (3,2) fills a matrix of any size with ones.

>> rats(A) displays elements of the matrix A as fractions

>> format long displays all numbers with 15 digits instead of the usual 4 digits

Some useful built-in functions:

Elementary trigonometric functions and their inverses

sin, cos, tan, sec, csc, cot, asin, acos, atan, asec, acsc, acot

Elementary hyperbolic functions and their inverses

sinh, cosh, tanh, sech, csch, coth, asinh, acosh, atanh, asech, acsch, acoth

Basic logarithmic and exponentiation functions


log, log2, log10, exp, sqrt, pow

Basic Statistical functions

max, mean, min, median, std, var, sum

Basic complex number functions

imag, real, i, j, abs, angle, cart2pol

Basic data analysis functions

fft, ifft, interpn, spline, diff, del2, gradient

Basic logical functions

and, or, xor, not, any, all, isempty, is*

Basic polynomial operations

poly, roots, residue, polyfit, polyval,conv

Function functions that allows users to manipulate mathematical expressions

feval, fminbnd, fzero, quad, ode23, ode45, vectorize, inline, fplot, explot

Basic matrix functions

zeros, ones, det, trace, norm, eig

Try the following:

>> f='2+cos(x)';

>> f=inline(f);

>> fplot(f,[0,2*pi])

>> x=fzero(inline('cos(x)','x'),1)

Plotting Basics
Suppose we wish to plot the graph y=x2 in the interval [-1, 1], then just type,

>> x = -1:0.1:1

>> y=x.*x

>> plot(x,y)

Note that the axes are automatically chosen to suit the range of variables used. One can add
more features to the plot using the following commands:

>> title(‘Graph of y=x^2’)

>> xlabel(‘x’)

>> ylabel(‘y’)

Suppose now we want to plot the graphs y1=x2 and y2=2x on the same figure, we need,

>> y1=x.*x;

>> y2=2*x;

>> plot(x,y1)

>> hold on

>> plot(x,y2,’ro’)

Note that the hold on command tells MATLAB to retain the most recent graph so that a new
graph can be plotted. Note that axes are adjusted and the second curve is plotted with a red
circle. More options on the choice for the color and symbol can be found by typing,

>> help plot

Suppose we want to plot the graphs y1=x2 and y2=2x on the same figure but partitioned into
two subplots then we say,

>> subplot(2,1,1)

>> plot(x,y1)
>> subplot(2,1,2)

>> plot(x,y2)

One must now be able to employ the various plotting commands in various combinations to
get the desired figure.

Conditional Statements:

for Loops: This allows a group of commands to be repeated a fixed, predetermined number of
times. The general form of a for loop is:

for x = array

Commands …

End

For example,

>> for n=1:10

x(n)=sin(n*pi/10); end

yields the vector x given by,

>> x

x=

Columns 1 through 7

0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090

Columns 8 through 10

0.5878 0.3090 0.0000

Let us now use the for loop to generate the first 15 Fibonacci numbers 1,1,2,3,5,8,…

>> f=[1 1];


>> for k=1:15

f(k+2) = f(k+1) + f(k);

end

>> f

while Loops

This evaluates a group of commands an infinite number of times unlike the for loop that
evaluates a group of commands a fixed number of times. The general form for while loop is

while expression

Commands …

end

For example to generate all the Fibonacci numbers less than 1000, we can do the following:

>> f=[1 1];

>> k=1;

>> while f(k) < 1000

f(k+1) = f(k+1) + f(k);

k = k +1;

end

>> f

if-else-end Construct

There are times when a sequence of commands must be conditionally evaluated based on a
relational test. This is done by the if-else-end construct whose general form is,

if expression
Commands …

end

For example if we want to give 20% discount for larger purchases of oranges, we say,

>> oranges=10; % number of oranges

>> cost = oranges*25 % Cost of oranges

cost =

250

>> if oranges > 5

cost = (1-20/100)*cost;

end

>> cost

cost =

200

If there are more conditions to be evaluated then one uses the more general if-else-end construct
given by,

if expression

Commands evaluated if True

else

Commands evaluated if False

End

switch-case Construct
This is used when sequences of commands must be conditionally evaluated based on repeated
use of an equality test with one common argument. In general the form is,

switch expression

case test_expression1

Commands_1 … case test_expression2

Commands_2 …

…..

otherwise

Commands_n ….

end

Let us now consider the problem of converting entry in given units to centimeters.

% centimeter.m

% This program converts a given measument into the equivalent in cms

% It illustrates the use of SWITCH-CASE control flow

function y=centimeter(A,units)

switch units % convert A to cms

case {'inch','in'}

y = A*2.54;

case {'feet','ft'}

y = A*2.54*12;

case {'meter','m'}

y = A*100;
case {'centimeter','cm'}

y = A;

otherwise

disp(['Unknown units: ' units])

y = nan; %% stands for not a number

end

Character Strings:

In MATLAB, these are arrays of ASCII values that are displayed as their character string
representation. For example:

>> t = ‘Hello’

t=

Hello

>> size(t)

ans =

15

A character string is simply text surrounded by single quotes. Each character in a string is one
element in the array. To see the underlying ASCII representation of a character string, you can
type,

>> double(t)

ans =

104 101 108 108 111

The function char provides the reverse transformation:

>> char(t)
ans =

hello

Since strings are numerical arrays with special attributes, they can be manipulated just like
vectors or matrices. For example,

>> u=t(2:4)

u=

ell

>> u=t(5:-1:1)

u=

olleh

>> u=t(2:4)’

u=

One can also concatenate strings directly. For instance,

>> u=’My name is ’;

>> v=’Mr. MATLAB’;

>> w=[u v]

w=

My name is Mr. MATLAB


The function disp allows you to display a string without printing its variable name. For
example:

>> disp(w)

My name is Mr. MATLAB

In many situations, it is desirable to embed a numerical result within a string. The following
string conversion performs this task. >> radius=10; volume=(4/3)*pi*radius^3;

>> t=[‘A sphere of radius ‘ num2str(radius) ‘ has volume… of ‘ num2str(volume) ’.’];

>> disp(t)

Relational Operators:

These include the operators < <= > >= == ~=

These operators can be used to compare two arrays of the same size, or to compare an array to
a scalar. For example:

>> A=1:5, B=5-A

A=

12345

B=

43210

>> g=A>3

g=

00011

finds elements of A that are greater than 3. Zeros appear in the result where this condition is
not satisfied and ones appear where it is.

>> for n=2:6


if rem(n,2)~=0

end

end

n=3

n=5

Logical Operators:

The three main logical operators are: AND, OR, NOT which are represented by the symbols
&, |, ~ respectively in MATLAB. Often one can combine these operators with relational
expressions. For example:

>> g=(A>2) & (A<5)

g=00110

returns ones where A is greater than 2 AND less than 5.

>> for n=2:6

if (rem(n,2)~=0) & (rem(n,3)~=0)

end end

n=5

Finally, the above capabilities make it easy to generate arrays representing discontinuous
functions, which are very useful in understanding signals etc. The basic idea is to multiply
those values in an array that you wish to keep with ones, and multiply all other values with
zeros. For example,

>> x = -2:0.1:2; % Creates Data

>> y = ones(size(x));
>> y = (x>-1)&(x<1);

>> plot(x,y)

This should plot a function which resembles part of a square wave that is discontinuous at x=-
1 and x=1.
Exp. No:1 Date:

GENERATION OF BASIC SIGNALS AND SIGNAL MANIPULATION


AIM:
To represent the basic signals like impulse, unit step, unit ramp, sinusoidal, cosine, exponential
and random signal and to manipulate the given signals using MATLAB software.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later version
THEORY:
Real signals can be quite complicated. The study of signals therefore starts with the analysis
of basic and fundamental signals. For linear systems, a complicated signal and its behavior can
be studied by superposition of basic signals. Common basic signals are:
Discrete – Time signals:
1, for n = 0
• Unit impulse sequence, x (n) =  (n) = 
0, otherwise

1, for n  0
• Unit step sequence, x (n) = u(n) = 
0, otherwise

n, for n  0
• Unit ramp sequence, x (n) = r (n) = 
0, otherwise
• Sinusoidal sequence, x(n) = A sin(ωn +ϕ)
• Exponential sequence, x(n) = A𝑒 𝑎𝑛 , where A and a are constant.
Continuous – time signals:

1, for t = 0
• Unit impulse signal, x ( t ) =  ( t ) = 
 0, otherwise

1, for t  0
• Unit step signal, x (t ) = u ( t ) = 
0, otherwise

t , for t  0
• Unit ramp signal, x ( t ) = r ( t ) = 
0 , otherwise
• Sinusoidal signal, x(t) = A sin(ωt +ϕ)
• Exponential signal, x(t) = A 𝑒 𝑎𝑡 , where A and a are constant.
LIBRARY FUNCTIONS:
clc:
CLC Clear command window.
CLC clears the command window and homes the cursor.
clear all:
CLEAR Clear variables and functions from memory. CLEAR removes all
variables from the workspace. CLEAR VARIABLES does the same thing.
close all:
CLOSE Close figure. CLOSE, by itself, closes the current figure window.
CLOSE ALL closes all the open figure windows.
exp:
EXP Exponential.
EXP(X) is the exponential of the elements of X, e to the X.
input:
INPUT Prompt for user input.
R = INPUT('How many apples') gives the user the prompt in the text string and then
waits for input from the keyboard. The input can be any MATLAB expression, which
is evaluated, using the variables in the current workspace, and the result returned in R.
If the user presses the return key without entering anything, INPUT returns an empty
matrix.
linspace:
LINSPACE Linearly spaced vector.
LINSPACE(X1, X2) generates a row vector of 100 linearly equally spaced points
between X1 and X2.
rand:
The rand function generates arrays of random numbers whose elements are uniformly
distributed in the interval (0,1).
ones:
ONES(N) is an N-by-N matrix of ones.
ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.
zeros:
ZEROS(N) is an N-by-N matrix of Zeros.
ZEROS(M,N) or ZEROS([M,N]) is an M-by-N matrix of zeros
plot:
PLOT Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is
plotted versus the rows or columns of the matrix, whichever line up.
subplot:
SUBPLOT Create axes in tiled positions.
H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n
matrix of small axes, selects the p-th axes for the current plot, and returns the axis
handle. The axes are counted along the top row of the Figure window, then the second
row, etc.
stem:
STEM Discrete sequence or "stem" plot.
STEM(Y) plots the data sequence Y as stems from the x axis terminated with circles
for the data value.
STEM(X,Y) plots the data sequence Y at the values specified in X.
title:
TITLE Graph title.
TITLE('text') adds text at the top of the current axis.
xlabel:
XLABEL X-axis label.
XLABEL('text') adds text beside the X-axis on the current axis.
ylabel:
YLABEL Y-axis label.
YLABEL('text') adds text beside the Y-axis on the current axis.
ALGORITHM:
• Start the matlab software
• Assign the time and amplitude values
• Plot the graph
• Give the x label and y label and title it
• Save and run the program
PROGRAM: Generation of sequence (or) signal
%UNIT IMPULSE SIGNAL
n1=input('Enter the no of samples');
x1=[-n1:1:n1];
y1=[zeros(1,n1),ones(1,1),zeros(1,n1)];
subplot(2,3,1);
stem(x1,y1);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Impulse Signal');
%Unit Step Signal%
n2=input('Enter the no of samples');
x2=[0:1:n2];
y2=ones(1,n2+1);
subplot(2,3,2);
stem(x2,y2);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Step Signal');

%Unit Ramp Signal


n3=input('Enter the no of samples');
x3=[0:1:n3];
subplot(2,3,3);
stem(x3,x3);
xlabel('Time Period');
ylabel('Amplitude');
title('Unit Ramp Signal');
%Exponential Signal
n4=input('Enter the length of the signal');
a=input('Enter the value of a:');
x4=[0:1:n4];
y4=a*exp(x4);
subplot(2,3,4);
stem(x4,y4);
xlabel('Time Period');
ylabel('Amplitude');
title('Exponential Signal');
%Sinusoidal Signal
x5=[-pi:0.1:pi];
y5=sin(2*pi*x5);
subplot(2,3,5);
plot(x5,y5);
xlabel('Time Period');
ylabel('Amplitude');
title('Sinusoidal Signal');
%Cosine Signal
x6=[-pi:0.1:pi];
y6=cos(2*pi*x6);
subplot(2,3,6);
plot(x6,y6);
xlabel('Time Period');
ylabel('Amplitude');
title('Cosine Signal')
PROGRAM: Random signal/sequence
Random number generators are useful in signal processing for testing and evaluating various
signal processing algorithms. For example, in order to simulate a particular noise cancellation
algorithm (technique), we need to create some signals which is contaminated by noise and then
apply this signal to the algorithm and monitor its output. The input/ output spectrum may then
be used to examine and measure the performance of noise canceller algorithm. Random
numbers are generated to represent the samples of some noise signal which is then added to the
samples of some the wanted signal to create an overall noisy signal.
Matlab provides two commands, which may be applied to generate random numbers.
Normally Distributed Random Numbers.
randn(N)
Is an N-by-N matrix with random entries, chosen from a normal distribution with mean zero
and variance one.
randn(M,N), and randn([M,N]) are M-by-N matrices with random entries.
Uniformly Distributed Random Numbers.
rand(N) is an N-by-N matrix with random entries, chosen from a uniform distribution on the
interval (0.0,1.0).
rand(M,N) and rand([M,N]) are M-by-N matrices with random entries.
The following Matlab program generates random signals using each distribution.
% Generates Uniformly and Normally Distributed random signals
N=1024; % Define Number of samples
R1=randn(1,N); % Generate Normal Random Numbers
R2=rand(1,N); % Generate Uniformly Random Numbers
figure(1); % Select the figure
subplot(2,2,1); % Subdivide the figure into 4 quadrants
plot(R1); % Plot R1 in the first quadrant
hold on
plot (R2, ‘r’);
grid;
title('Normal [Gaussian] Distributed Random Signal');
xlabel('Sample Number');
ylabel('Amplitude');
% Generation of a uniform random sequence
n6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
stem(n6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');

Signal Manipulation

Some of the basic signal manipulation may be listed as follows:

Signal Shifting / Delay


Here 'D' is the number of samples which the input signal must be delayed. For example if
x(n)=[1, 2, 3, 4, 5], then x(n-3)=[0,0,0,1,2,3,4,5].

Signal Addition / Subtraction


When adding two signals together, signals must have the same number of samples. If one signal
has less than number of samples than the other, then this signal may be appended with zeros
in order to make it equal length to the second signal before adding them.
Signal Amplification / Attenuation
'a' is a numerical constant. If a>1, then the process is referred to as 'amplification' , if 0<a<1,
the process is referred to as 'attenuation'.
A Matlab program given below, provides an example of each of the above basic operations:
% Program demonstrating Basic Signal Manipulation
N=128;
f1=150;
f2=450;
f3=1500;
fs=8000;
n=0:N-1;
x1=sin(2*pi*(f1/fs)*n);
x2=(1/3)*sin(2*pi*(f2/fs)*n);
x3=sin(2*pi*(f3/fs)*n);
figure(1);
subplot(1,1,1);
subplot(2,3,1);
plot(n,x1);
grid;
title('Signal, x1(n)');
subplot(2,3,2);
plot(n,x2);
grid;
title('Signal, x2(n)');
subplot(2,3,3);
plot(n,x3);
grid;
title('Signal, x3(n)');
% Signal Delay
x1d=[zeros(1,20), x1(1:N-20)];
subplot(2,3,4);
plot(n,x1d);
grid;
title('Delayed x(n), [x1(n-20)]');
% Signal Addition
xadd=x1+x2;
subplot(2,3,5);
plot(n,xadd);
grid;
title('x1(n)+x2(n)');
% Signal Multiplication
xmult=x1.*x3;
subplot(2,3,6);
plot(xmult);
grid;
title('x1*x3');

RESULT:

Thus the basic signals were generated using MATLAB and the output signals were plotted.
Exp. No:2 Date:
AUTOCORRELATION AND CROSS CORRELATION
AIM:
To perform auto- correlation and cross-correlation of given sequences in MATLAB.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later version
THEORY:
Correlation:
Correlation is a mathematical operation that closely resembles convolution. Correlation is
basically used to compare two signals. Correlation is the measure of the degree to which two
signals are similar. The correlation of two signals is divided into two ways: (i) Cross-
correlation, (ii) Auto-correlation.
Cross-correlation:
Cross correlation is a measure of similarity between two waveforms as a function of time gap
or delay applied to one of them. The cross correlation between a pair of continuous time signals
f(t) and g(t) is given by

where --------- (1)


and it can be derived for discrete time signal f(n) and g(n) as

where k = 0, ±1, ±2, ..............


The index ‘τ’ and ‘k’ are the shift parameters for continuous time and discrete time signals
respectively. The order of subscripts 'fg' indicates that f(t) or f(n) are the reference sequence in
continuous-time and discrete-time respectively that remains unshifted in time whereas the
sequence g(t) or g(n) are shifted ‘τ' or 'k' units in time with respect to f(t) or f(n) respectively.
If we want to fix g(t) and to shift f(t), then the correlation of two sequences can be written as

-----------------------(2)
and for discrete time signals, the cross-correlation can be written as

Now comparing eqn. (1) and eqn. (2) we find that

and similarly for discrete time signal

Where for continuous time signals Ygf(-τ) is the folded version of Yfg(τ )about τ =0 and for
discrete time signal Ygf(-k) is the folded version of Yfg(k) about k=0.
Now we can rewrite the eqn. (1) as

-----------------(3)

and similarly for discrete time signal

From the above equation(3) we find that the correlation process is essentially the convolution
of two data sequence in which one of the sequence has been reversed.
Auto-correlation:
Auto correlation of a continuous time signal is the correlation of the signal with itself. The
auto correlation of a continuous time signal f(t) is defined as

for discrete time signal f(n) it is defined as


or equivalently we can write

and similarly for discrete time signal f(n) we can write

Relation to Signal energy and Signal power:


The auto-correlation function of a periodic signal is itself a periodic signal with a period the
same as that of the original signal.
If f(t) is an energy signal, its auto-correlation is

for continuous-time and discrete-time signals respectively.


After applying a zero shift it becomes

which is the total signal energy of the signal.


If f(t) or f[n] is a power signal, the auto-correlation at zero shift is

for continuous-time and discrete-time respectively which is the average signal power of the
signal.
Properties of Auto-correlation:
The auto-correlation depends on the choice of the amount of shift applied. we can say from
the observation that the value of the auto-correlation can never be bigger than it is at zero shift.
That is,

It will happen because at a zero shift, the correlation with itself is obviously as large as it can
get since the shifted and unshifted versions coincide.
Another property of auto-correlation function is that all auto-correlation functions are even
functions (but not all correlation functions).

If we make the change of variable

and

We can show that


It can be shown by a similar technique for discrete-time signal also

Another characteristic of auto-correlation function is that a time shift of a signal does not make
any change of its auto-correlation.
Let Yff(k) be the auto-correlation function of a discrete-time energy signal f[n]. Then

Now let y[n] = f [n-n0] . Then


Now we can make a change of variable q = n-n0 . Then

Another characteristic of auto-correlation function is that the auto-correlation of a sum of


sinusoids of different frequencies is the sum of auto-correlation of the individual sinusoids. To
demonstrate this idea let a continuous-time power signal f(t) be a sum of two sinusoids f1(t) and
f2(t), where

The auto-correlation of this signal is

Therefore,
Autocorrelation
ALGORITHM:
• Get the signal x(n) of length N in matrix form
• The correlated signal is denoted as y(n)
• y(n)is given by the formula 𝑦(𝑛) = ∑∞
𝑘=−∞ 𝑥 (𝑘)𝑥(𝑘 − 𝑛)

• Stop
PROGRAM FOR COMPUTING AUTO CORRELATION:
x= input('Enter the sequence, x = ');
lx =input('Starting time index of x, lx = ');
m=length(x);
subplot(3,2,1);
stem(lx:lx+m-1, x, 'fill', 'r');
xlabel('Time period');
ylabel('Amplitude');
title('Input sequence');
y=xcorr(x);
n=length(y);
subplot(3,2,2);
stem(lx:lx+n-1, y, 'fill', 'r');
xlabel('Time period');
ylabel('Amplitude');
title('Auto correlation');
Autocorrelation of a sinusoidal signal
N=1024; % Number of samples
f1=1; % Frequency of the sinewave
FS=200; % Sampling Frequency
n=0:N-1; % Sample index numbers
x=sin(2*pi*f1*n/FS); % Generate the signal, x(n)
%t=[1:N]*(1/FS); % Prepare a time axis
subplot(2,1,1); % Prepare the figure
plot(x); % Plot x(n)
title('Sinwave of frequency 1000Hz [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
Rxx=xcorr(x); % Estimate its autocorrelation
subplot(2,1,2); % Prepare the figure
plot(Rxx); % Plot the autocorrelation
grid;
title('Autocorrelation function of the sinewave');
xlabel('lags');
ylabel('Autocorrelation');
Cross correlation
ALGORITHM:
• Get two signals x(m)and h(p)in matrix form
• The correlated signal is denoted as y(n)
• y(n)is given by the formula 𝑦(𝑛) = ∑∞
𝑘=−∞ 𝑥 (𝑘)ℎ(𝑘 − 𝑛)

• Stop
PROGRAM:
x=input('Enter any sequence, x = ');
lx =input('Starting time index of x, lx = ');
subplot(3,2,1);
a = length(x);
stem(lx:lx+a-1,x, 'fill', 'b');
xlabel('Time period');
ylabel('Amplitude');
title('Input sequence');
h=input('Enter any sequence, h = ');
lh =input('Starting time index of h, lh = ');
subplot(3,2,2);
b = length(h);
stem(lh:lh+b-1, h, 'fill', 'b');
xlabel('Time period');
ylabel('Amplitude');
title('Impulse sequence');
y=xcorr(x,h);
subplot(3,2,3);
stem(lx+lh:length(y)+lx+lh-1, y);
xlabel('Time period');
ylabel('Amplitude');
title('Cross correlation');
Cross-Correlation of two different sinusoidal signals
N=1024; % Number of samples to generate
f=1; % Frequency of the sinewave
f1 = 4;
FS=200; % Sampling frequency
FS1 = 400;
n=0:N-1; % Sampling index
x=sin(2*pi*f*n/FS); % Generate x(n)
%y=x+10*randn(1,N); % Generate y(n)
y = sin(2*pi*f1*n/FS1);
subplot(3,1,1);
plot(x);
title('Pure Sinewave');
grid;
subplot(3,1,2);
plot(y);
title('y(n), Pure Sinewave + Noise');
grid;
Rxy=xcorr(x,y); % Estimate the cross correlation
subplot(3,1,3);
plot(Rxy);
title('Cross correlation Rxy');
grid;

RESULT:
Thus, the autocorrelation and cross-correlation of the two given signals are represented using
Matlab and verified with the theoretical results.
Exp. No:3 Date:
LINEAR AND CIRCULAR CONVOLUTION
AIM:
To perform linear and circular convolution between the two sequences using MATLAB
software.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later vesion
THEORY:
Convolution is a mathematical operation which can be performed on two signals 'f' and 'g' to
produce a third signal which is typically viewed as the modified version of one of the original
signals. A convolution is an integral that express the overlap of one signal 'g' as it is shifted
over another signal 'f'.
Convolution of two signals 'f' and 'g' over a finite range [0 → t] can be defined as

Here the symbol [f*g](t) denotes the convolution of 'f' and 'g'. Convolution is more often taken
over an infinite range like,

The convolution of two discrete time signals f(n) and g(n) over an infinite range can be defined
as

The convolution of two continuous time signals are shown in the Figure 1.
Fig.1 Convolution of two signals
Convolution properties:
There are some important properties of convolution that perform on continuous time signal
which we have listed below. The commutativity, associativity, distributivity properties are
given below.
Commutativity f(t) * g(t) = g(t) * f(t)
Associativity [f(t) * g(t)] * h(t) = f(t) * [g(t) * h(t)]
Distributivity f(t) * [g(t) + h(t)] = f(t) * g(t) + f(t) * h(t)
Linear Convolution
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. Linear Convolution is
quite often used as a method of implementing filters of various types. If the input f[n] has N1
samples and impulse response g[n] has N2 samples then the output sequence y[n] will be a finite
duration sequence consisting of (N1 + N2 - 1) samples. The convolution results in a non periodic
sequence called Aperiodic convolution.

Circular Convolution
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. Also note that circular
convolution could also be found by taking the DFT of the two input signals and finding the
product of the two frequency domain signals. The Inverse DFT of the product would give the
output of the signal in the time domain which is the circular convolution output. It can be
performed only if both the sequences consist of equal number of samples. If the sequences are
different in length then convert the smaller size sequence to that of larger size by appending
zeros. This process is called circular convolution.

Linear Convolution using inbuilt command and for loop


ALGORITHM :
• Start the program
• Enter the first input sequence x(n).
• Enter the second input sequence h(n)
• Plot both the sequences in discrete form using stem function
• Use the inbuilt command conv( ) function to perform the convolution operation
• Finally plot the convolution sequence and the input sequence in a single window
using subplot function.
• Stop the program
PROGRAM:
clc;
close all;
clear all;
x=input('enter the sequence, x(n)=');
h=input('enter the sequence, h(n)=');
m=length(x);
n=length(h);
subplot(2,2,1)
stem(1:m,x,'fill','r');
grid on;
title('input sequence, x(n)=');
xlabel('time n------>');
ylabel('amplitude----->');
subplot(2,2,2);
stem(1:n,h,'fill','r');
grid on;
title('impulse sequence, h(n)=');
xlabel('time n------>');
ylabel('amplitude----->');
%------linear convolution using inbuilt command------------------------%
v=conv(x,h);
l=m+n-1;
subplot(2,2,3);
stem(1:l,v,'fill','r');
grid on;
title('output sequence using inbuilt command, v(n)=');
xlabel('time n------>');
ylabel('amplitude----->');
%--------linear convolution using 'for' loop------------------------------%
X=zeros(1,l);
size(X);
H=zeros(1,l);
size(H);
X(1:m)=x;
H(1:n)=h;
for i=1:l
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
subplot(2,2,4);
stem(1:l,Y,'fill','r');
grid on;
title('output sequence using loop, Y(n)=');
xlabel('time n------>');
ylabel('amplitude----->');
Circular convolution using inbuilt command
ALGORITHM:
• Start the program
• Enter the first input sequence x(n).
• Enter the second input sequence h(n)
• Plot both the sequences in discrete form using stem function
• Use the inbuilt command cconv( ) function to perform the circular convolution
operation
• Finally plot the convolution sequence and the input sequence in a single window
using subplot function.
• Stop the program
PROGRAM:
clear all;
x = input ('Enter the first input sequence, x(n) = ');
sx = input('Starting point of input sequence,x(n) = ');
h = input ('Enter the second input sequence, h(n) = ');
sh = input('Starting point of input sequence,x(n) = ');
lx=length(x);
lh = length(h);
n = max(lx,lh);
y = cconv(x, h, n);
ly = length(y);
subplot(2,2,1);
stem(sx:sx+lx-1, x, 'fill', 'r');
title('Input sequence x(n)');
xlabel('Length of First Input Sequence');
ylabel('Input Value');
subplot(2,2,2);
stem(sh:sh+lh-1, h, 'fill', 'r');
title('Input sequence h(n)');
xlabel('Length of Second Input Sequence');
ylabel('Input Value');
subplot(2,2,3);
stem(sx+sh:ly+sx+sh-1, y, 'fill', 'r');
title('Circular convoluted sequence y(n)');
xlabel('Length of Output Sequence');
ylabel('Output Value');
Circular convolution using for loop
ALGORITHM:
• Start
• Read the first sequence
• Read the second sequence
• Find the length of first sequence
• Find the length of second sequence
• Perform circular convolution for both the sequences
• Plot the sequence
• Display the output sequence
• Stop
PROGRAM:
clc;
g=input('Enter the sequence 1:');
h=input('Enter the sequence 2:');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
disp('The resultant is');y
subplot(2,1,1);
stem(y);
xlabel('N->');
ylabel('Amplititude->');
Circular convolution using FFT
ALGORITHM:
• Start the program
• Enter the x(n) sequence.
• Enter the h(n) sequence.
• Perform circular convolution using FFT function.
• Plot the values.
• Stop the program
PROGRAM:
a=input('X1(n)');
b=input('X2(n)');
N=length(b);
M=length(a);
c=fft(a,N);
d=fft(b);
e=c.*d;
f=ifft(e);
disp('circular conv output');
disp(f);
subplot(1,3,1);
stem(a);
xlabel('time');
ylabel('amplitude');
title('X1(n)');
subplot(1,3,2);
stem(b);
xlabel('time');
ylabel('amplitude');
title('X2(n)');
subplot(1,3,3);
stem(f);
xlabel('time');
ylabel('amplitude');
title('output');
RESULT:
Thus, the linear and circular convolution of the two given signals are represented using
Matlab and verified with the theoretical results.
Exp. No:4 Date:
VERIFICATION OF SAMPLING THEOREM

AIM:
To verify sampling theorem using MATLAB software.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later version
THEORY:
Sampling: Is the process of converting a continuous time signal into a discrete time signal. It
is the first step in conversion from analog signal to digital signal.
Sampling theorem: Sampling theorem states that "Exact reconstruction of a continuous time
base-band signal from its samples is possible, if the signal is band-limited and the sampling
frequency is greater than twice the signal bandwidth", i.e. f s > 2W, where ‘W’ is the signal
bandwidth.
Nyquist Rate Sampling: The Nyquist rate is the minimum sampling rate required to avoid
aliasing, equal to the highest modulating frequency contained within the signal. In other words,
Nyquist rate is equal to two sided bandwidth of the signal (Upper and lower sidebands). To
avoid aliasing, the sampling rate must exceed the Nyquist rate.
ALGORITHM:
• Specify the time period of the given signal
• Using sine function plot the given waveform
• Sample the given signal greater than, exactly equal to and lesser than the Nyquist rate
• Using stem function, plot all the three sampled versions and observe the signal
PROGRAM :
clc;
%T=0.04; % Time period of 50 Hz signal
f = 50;
fs = 200;
N = 256;
n = 0:N-1;
%t=[1:N]*(1/fs);
xa_t=sin(2*pi*(f/fs)*n);
subplot(2,2,1);
%stem(t,xa_t);
plot(xa_t);
title('Verification of sampling theorem');
title('Continuous signal');
xlabel('t');
ylabel('x(t)');
fs1 = 600; %>niq rate
fs2 = 100;%=niq rate
fs3 = 50;%<niq rate
%t1 =[1:N]*(1/fs1);
%t2 =[1:N]*(1/fs2);
%t3 =[1:N]*(1/fs3);
x_ts1=sin(2*pi*(f/fs1)*n);
subplot(2,2,2);
%stem(t1,x_ts1);
plot(x_ts1);
title('greater than Nq');
xlabel('n');
ylabel('x(n)');
x_ts2=sin(2*pi*(f/fs2)*n);
subplot(2,2,3);
%stem(t2,x_ts2);
plot(x_ts2);
title('Equal to Nq');
xlabel('n');
ylabel('x(n)');
x_ts3=sin(2*pi*(f/fs3)*n);
subplot(2,2,4);
%stem(t3,x_ts3);
plot(x_ts3);
title('less than Nq');
xlabel('n');
ylabel('x(n)')
RESULT:

Thus, the sampling theorem has been proved.


Exp. No:5 Date:
SAMPLING AND EFFECT OF ALIASING

AIM:
To sample the signal at the given sampling rate and study its aliasing effect using MATLAB
software.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later vesion
ALGORITHM:
• Specify the sampling and frequency

Program
N=512;
f1=1000;
f2=1500;
f3=2000;
fs=6000;
n= 0 : N-1;
x1=cos(2*pi*(f1/fs)*n)+cos(2*pi*(f2/fs)*n)+cos(2*pi*(f3/fs)*n);
y = spectrum(x1,N); % using MATLAB command " spectrum "
specplot(y,fs);
xlabel('Frequency (Hz) ');
ylabel('Magnitude (dB) ' );
title(' Power Spectrum of x[n] ' );
grid;

Result

Thus the Sampling was performed and studied the aliasing effect using MATLAB.
Exp. No:6 Date:
SPECTRUM ANALYSIS USING DFT
AIM:
To write MATLAB program to analyze the spectrum of the given signal using DFT
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later vesion
ALGORITHM:

1) First get the number of samples


2) Assign the Sampling and corresponding signal frequency.
3) Generate the sinusoidal signal
4) Estimate the spectrum of this signal
5) Assign the frequency axis of the given signal
6) Plot the sinusoidal signal and its spectrum
PROGRAM:
%Discrete Fourier Transform DFT to estimate the spectrum of the sinusoidal signal
clf; %Clear all figures
clear all; %Clear all variables
close all; %Close all figures
N=256; %Total Number of Samples
fs=8000; %Define the sampling frequency
f=1000; %Define the signal's frequency
n=0:N-1; %Define the vector
%Now generate the sinusoidal signal
x=sin(2*pi*(f/fs)*n);
%Estimate its spectrum using fft command
X=fft(x);
magX=abs(X);
%Build up an appropriate frequency axis, first make a vector
%for f=0,1,2,...(N/2)-1
fx=0:(N/2)-1;
%Now scale it so that it represents frequencies in Hz
fx=(fx*fs)/N;
%Plot the sinusoidal signal and its spectrum
subplot(2,1,1);
plot(n,x);
title('Sinusoidal Signal x(n) with f=1KHz');
xlabel('Time Index n');
ylabel('Amplitude');
subplot(2,1,2);
plot(fx,20*log10(magX(1:N/2)));
grid;
title('Spectrum of a sinusoidal signal with f=1KHz');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
RESULT:
Thus, MATLAB program for Spectrum analysis using DFT is executed and verified the
results.
Exp.No:7 Date:
DESIGN OF IIR FILTER
AIM:
To write a program for designing the IIR filters using various specifications.
BUTTERWORTH ANALOG FILTERS
Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Plot the magnitude and phase responses.
PROGRAM:
clc;
clear all;
close all;
%% Butterworth low pass Filter
% Filter Specifications
k1=input('Enter the passband gain in db:');
k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');
%Find the order and Cutofrf frequency using the given specification of filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
% Low pass filtering
[b,a]=butter(n,Wc,'low','s');
%Plotting magnitude & phase response
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');

High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
PROGRAM:
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications
k1=input('Enter the passband gain in db:');
k2=input('Enter the stopband gain in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');
%Find the order and Cutoff frequency using the given specification of filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
% Low pass filtering
[b,a]=butter(n,Wc,'high','s');
%Plotting magnitude & phase response
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth HPF');

Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
PROGRAM
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%To find order of the filter
[N]=buttord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Band pass Filtering
[b,a]=butter(N,Wc,'bandpass','s');
%plotting magnitude and phase response
figure(1);
freqs(b,a);

Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
PROGRAM
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');

%To find order of the filter


[N]=buttord(Wp,Ws,Rp,Rs,'s')
%To find cut off frequency
Wc=[Wp Ws];
%Band stop Filtering
[b,a]=butter(N,Wc,'stop','s');
%plotting magnitude and phase response
figure(1);
freqs(b,a);

CHEBYSHEV TYPE-1 ANALOG FILTERS


Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequency
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
CHEBYSHEV TYPE-2 ANALOG FILTERS
Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter using
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
BUTTERWORTH DIGITAL IIR FILTERS
Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
CHEBYSHEV TYPE-1 DIGITAL FILTERS
Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
CHEBYSHEV TYPE-2 DIGITAL FILTERS
Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
Result:
Thus IIR filter using MATLAB is designed and output is verified.
Exp. No:8 Date :
DESIGN OF FIR FILTER
AIM:
To write a MATLAB program for designing the FIR Various specification.
Rectangular Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
PROGRAM:
Barlet Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
Black man window:
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
Hamming Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
PROGRAM
Hanning Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
PROGRAM:
Kaiser Window:
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter
5. Find the window coefficients
6. Draw the magnitude and phase responses.
RESULT:
Thus various specification are given to the input of program, observed the result and plots are
verified by manual calculation.

Exp.No.9 Date:
MULTIRATE FILTERS
AIM:
To write a matlab program to perform interpolation and decimation.
HARDWARE REQUIREMENTS:
Computer Desktop
SOFTWARE REQUIREMENTS:
Matlab 7 or later vesion
THEORY:
In multirate digital signal processing the sampling rate of a signal is changed in order to
increase the efficiency of various signal processing operations. Decimation, or down-sampling,
reduces the sampling rate, whereas expansion, or up-sampling, followed by interpolation
increases the sampling rate. Some applications of multirate signal processing are:
• Up-sampling, i.e., increasing the sampling frequency, before D/A conversion in order
to relax the requirements of the analoglowpass antialiasing filter. This technique is used
in audio CD, where the sampling frequency 44.1 kHz is increased fourfold to 176.4
kHz before D/A conversion.
• Various systems in digital audio signal processing often operate at different sampling
rates. The connection of such systems requires a conversion of sampling rate.
• Decomposition of a signal into M components containing various frequency bands. If
the original signal is sampled at the sampling frequency fs (with a frequency band of
𝑓
width 𝑠⁄𝑀or half the sampling frequency), every component then contains a frequency
𝑓 𝑓
band of width 1⁄2 𝑀𝑠 only, and can be represented using the sampling rate 𝑠⁄𝑀. This

allows for efficient parallel signal processing with processors operating at lower
sampling rates. The technique is also applied to data compression in subband coding,
for example in speech processing, where the various frequency band components are
represented with different word lengths.
• In the implementation of high-performance filtering operations, where a very narrow
transition band is required. The requirement of narrow transition bands leads to very high
filter orders. However, by decomposing the signal into a number of subbands containing
the passband, stopband and transition bands, each component can be processed at a lower
rate, and the transition band will be less narrow. Hence the required filter complexity may
be reduced significantly.
Basic Operations of multirate processing
Decimation
Decimation, or down-sampling, consists of reducing the sampling rate by a factor M as shown
in Figure 1.

Figure 1. Decimation by the factor M


i.e., it consists of every Mth element of the input signal. It is clear that the decimated signal ‘y’
does not in general contain all information about the original signal ‘x’. Therefore, decimation
is usually applied in filter banks and preceded by filters which extractthe relevant frequency
bands.
Expansion or Interpolation
Interpolation, or up-sampling, consists of increasing the sampling rate by a factor Las shown
in Figure 2.

Figure 2. Expansion by the factor L


In order to reconstruct the correct interpolating signal at the higher sampling rate, an
interpolating filter has to be introduced after the expansion. This is equivalent to the situation
in D/A conversion, where a low-pass filter is used after the hold function.
ALGORITHM:
1. Start the program
2. Generate the signal
3. Using decimate and interp function perform the interpolation and decimation by the given
factor
4. Plot the output and stop the program

PROGRAM:Upsampling and downsampling (Analog)


clc;
M = input('Down-sampling factor = ');
L = input('Up -sampling factor = ');
n = 0:99;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y = decimate(x,M,'fir');
y1 = interp(x,L);
subplot(3,1,1);
stem(n,x(1:100));
title('Input Sequence');
xlabel('Time index n');ylabel('Amplitude');
subplot(3,1,2);
l = 0:(L*100)-1;
stem(l,y1(1:L*100));
title('Output Sequence');
xlabel('Time index n');ylabel('Amplitude');
subplot(3,1,3);
m = 0:(100/M)-1;
stem(m,y(1:100/M));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
RESULT:
Thus, multirate filters were designed using MATLAB.

Exp.No.10 Date:
STUDY OF TMS320C6745 DIGITAL SIGNAL PROCESSOR
AIM:
To study the architecture of TMS320C6745 digital signal processor.
HARDWARE REQUIREMENTS
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS
Code Composer Studio Version 4
THEORY:
The C6745/6747 is a low power digital signal processor based on C674x DSP core. It consumes
significantly lower power than other members of theTMS320C6000™ Platform of DSP’s. The
C6745/6747 DSP core uses a two -level cache-based architecture. The Level 1 program cache
(L1P) is a 32KB direct mapped cache and the Level 1 data cache (L1D) is a 32KB 2-way set-
associative cache. The Level 2 program cache (L2P) consists of a 256KB memory space that
is shared between program and data space. L2 also has a 1024KB ROM
.The C67xx Evaluation Board is highly integrated, high-performance solution for demanding
control applications and is the first 32 -bit 150 MIPS DSP.
The peripheral set includes a 10/100 Mb/s Ethernet MAC (EMAC) with a Management Data
Input/Output (MDIO) module; two inter-integrated circuit (I2C) bus interfaces; 3 multichannel
audio serial ports (McASP) with 16/9 serializers and FIFO buffers; 2 64-bit general-purpose
timers each configurable (one configurable as watchdog); a configurable 16-bit host port
interface (HPI) [C6747 only]; upto 8 banks of 16 pins of general-purpose input/output (GPIO)
with programmable interrupt/event generation modes, multiplexed with other peripherals; 3
UART interfaces (one with RTS and CTS); 3 enhanced high- resolution pulse width modulator
(eHRPWM) peripherals; 3 32-bit enhanced capture (eCAP) module peripherals which can be
configured as 3 capture inputs or 3 auxiliary pulse width modulator (APWM) outputs; 2 32-bit
enhanced quadrature pulse (eQEP) peripherals; and 2 external memory interfaces: an
asynchronous and SDRAM external memory interface (EMIFA) for slower memories or
peripherals, and a higher speed memory interface (EMIFB) for SDRAM. The Ethernet Media
Access Controller (EMAC) provides an efficient interface between the C6745/6747 and the
network. The EMAC supports both 10Base-T and 100Base-TX, or 10 Mbits/second (Mbps)
and 100 Mbps in either half-or full-duplex mode. Additionally an Management Data
Input/Output (MDIO) interface is available for PHY configuration.

TMS 320C6745 Functional Block Diagram

DSP Subsystem:

The DSP subsystem includes the following features:-

• C674x DSP CPU


• 32KB L1 Program (L1P)/Cache (up to 32KB)
• 32KB L1 Data (L1D)/Cache (up to 32KB)
• 256KB Unified Mapped RAM/Cache (L2)
• Boot ROM (cannot be used for application code)
• Little endian
C674X DSP CPU Description

The C674x Central Processing Unit(CPU) consists of eight functional units, two register files,
and two datapaths as shown in Figure. The two general-purpose register files (AandB) each
contain 32 32-bit registers for a total of 64 registers.The general-purpose registers can be used
for data or can be data address pointers. The data types supported include packed 8-bitdata,
packed 16-bitdata, 32-bitdata, 40-bitdata, and 64-bitdata. Values larger than 32bits, such as
40-bit-long or 64-bit-long values are stored in register pairs, with the 32 LSBs of data placed
in an even register and the remaining 8 or 32 MSBs in the next upper register (which is always
an odd-numbered register).

The eight functional units (.M1,.L1,.D1,.S1,.M2,.L2,.D2,and.S2) are each capable of


executing one instruction every clock cycle. The .M functional units perform all multiply
operations. The .S and .L units perform a general set of arithmetic, logical, and branch
functions. The .D units primarily load data from memory to the register file and store results
from the register file into memory.

The C674x CPU combines the performance of the C64x+ core with the floating-point
capabilities of the C67x+core. Each C674x .M unit can perform one of the following each
clock cycle: one 32x32 bit multiply, one 16x32 bit multiply, two 16x16 bit multiplies, two
16x32 bit multiplies, two 16x16 bit multiplies with add/subtract capabilities, four 8x8 bit
multiplies, four 8x8 bit multiplies with add operations, and four 16x16 multiplies with
add/subtract capabilities (including a complex multiply). There is also support for Galois field
multiplication for 8-bit and 32-bit data. Many communications algorithms such as FFTs and
modems require complex multiplication. The complex multiply (CMPY) instruction takes
four 16-bit inputs and produces a 32-bit real and a 32-bit imaginary output. There are also
complex multiplies with rounding capability that produces one 32-bit packed output that
contain 16-bit real and 16-bit imaginary values. The 32x32 bit multiply instructions provide
the extended precision necessary for high-precision algorithms on a variety of signed and
unsigned 32-bit data types.
Result:

Thus the architecture of TMS320C6745 digital signal processor was studied.

Exp.No.11 Date:
LINEAR CONVOLUTION
AIM:
To perform the Linear Convolution of two given discrete sequence in DSP TMS320C6745
KIT.
HARDWARE REQUIREMENTS
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS
Code Composer Studio Version 4
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. If the input and impulse response of a system are x[n] and h[n] respectively, the
convolution is given by the expression,
x[n] * h[n] = ε x[k] h[n-k]
Where k ranges between -∞ and ∞. If, x(n) is a M-point sequence h(n) is a N –point sequence
then,y(n) is a (M+N-1) –point sequence.
In this equation, x(k), h(n-k) and y(n) represent the input to and output from the system at time
n. Here we could see that one of the inputs is shifted in time by a value every time it is
multiplied with the other input signal. Linear Convolution is quite often used as a method of
implementing filters of various types.
PROCEDURE:
1. Open Code Composer Studio v4.
2. In Workspace Launcher.
a. BROWSE
• Select the project location and make one new folder,MAKE NEW FOLDER
• Type the Workspace name, OK
• OK.
3.FILE
• NEW
• CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location.
• NEXT
c. Project type: C6000.
d. Tick Debug and Release.
• NEXT
• NEXT.
e. Output type: Executable.
f. Device Variant: generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Target content: none.
• FINISH
4. FILE
• NEW
• SOURCE FILE
Source file: Type your projectname.c (.c extension is must).
b. Type the program.
c. FILE
• SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder (contains library files)
6. Paste the Linker file in the project location.
7. PROJECT
• PROPERTIES
• C/C++ BUILD
• BASIC OPTION
a. Target processor version( -- silicon version, -mv) : 6400+
b. OK.
IN C/C++ BUILD,
• INCLUDE OPTIONS (Add dir to #include search path(--include_path, - I))
select this add icon and add the following three path by individually
• "${Diag}../../common/header"
• "${XDAIS_CG_ROOT}/packages/ti/xdais"
• "${C6000_CSL_CG_ROOT}/include"
8. FILE
• NEW
• TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745.
• SAVE
• TARGET CONFIGURATION
• C674X_0
• BROWSE, browse the workspace location, open the gel folder and select the
GEL file.
• OPEN
• SAVE
9. In C/C++ Project window, Right click the project
• REBUILD PROJECT.
10. Connections :
a. Connect the usb cable, PC to KIT.
b. Connect the 5v adapter.
c. Power on the kit.
11. TARGET
• DEBUG ACTIVE PROJECT.
12. VIEW
• MEMORY
13. In right side, memory window will open. Type the address and give the input at particular
location.
Give the input as follows:
x(n) h(n)
0xC0001000 - 0000001 0xC0001030 - 00000001
0xC0001004 – 00000001 0xC0001034 – 00000001
0xC0001008 – 00000001 0xC0001038 – 00000001
0xC000100C – 00000001 0xC000103C – 00000001
14. TARGET
• RUN.
15. TARGET
• HALT.
See the Output at Particular location:
Example :
0xC0001050 – 00000001
0xC0001054 – 00000002
0xC0001058 - 00000003
0xC000105C - 00000004
0xC0001060 - 00000003
0xC0001064 - 00000002
0xC0001068 – 00000001

PROGRAM
#include <stdio.h>
#define xn 4
#define hn 4
void
main()
{
int *x,*h,*y,i,n,k;
x = (int*) 0xc0001000;
h = (int*) 0xc0001030;
y = (int*) 0xc0001050;
for (i=0; i < (xn+hn-1); i++)
{ y[i]=0;
x[xn+i]=0;
h[hn+i]=0;
}
for (n=0; n<(xn+hn-1); n++)
{
for (k=0; k<=n; k++)
y[n] = (y[n]) + ((x[k]) * (h[n-k]));
}
while (1);
}
RESULT
Thus, the Linear Convolution of two given discrete sequence has performed and the result is
stored at memory location (0xC0001050).
Exp.No.12 Date:
a. FFT 8-POINT DIT USING TMS320C6745 DSP
AIM:
To perform the 8-point FFT using DIT process from a given discrete sequence in
TMS320C6745 DSP KIT.
HARDWARE REQUIREMENTS
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS
Code Composer Studio Version 4
THEORY:
A fast Fourier transform (FFT) is an efficient algorithm to compute the discrete Fourier
transform (DFT) and its inverse. There are many distinct FFT algorithms involving a wide
range of mathematics, from simple complex number arithmetic to group theory and number
theory. A DFT decomposes 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 a DFT of
N-points in the naive way, using the definition, takes O(N2) arithmetical operations, while an
FFT can compute the same result in only O(N log N) operations. The difference in speed can
be substantial, 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 many
DFT based algorithms 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 most well 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
−2𝜋𝑘⁄
on the fact that 𝑒 𝑁 is an Nth 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.
PROCEDURE:
1. Open Code Composer Studio v4.
2. In Workspace Launcher.
a. BROWSE
• Select the project location and make one new folder,MAKE NEW FOLDER
• Type the Workspace name, OK
• OK.
3.FILE
• NEW
• CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location.
• NEXT
c. Project type: C6000.
d. Tick Debug and Release.
• NEXT
• NEXT.
e. Output type: Executable.
f. Device Variant: generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Target content: none.
• FINISH
4. FILE
• NEW
• SOURCE FILE
Source file: Type your projectname.c (.c extension is must).
b. Type the program.
c. FILE
• SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder (contains library files)
6. Paste the Linker file in the project location.
7. PROJECT
• PROPERTIES
• C/C++ BUILD
• BASIC OPTION
c. Target processor version( -- silicon version, -mv) : 6400+
d. OK.
IN C/C++ BUILD,
• INCLUDE OPTIONS (Add dir to #include search path(--include_path, - I))
select this add icon and add the following three path by individually
• "${Diag}../../common/header"
• "${XDAIS_CG_ROOT}/packages/ti/xdais"
• "${C6000_CSL_CG_ROOT}/include"
8. FILE
• NEW
• TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745.
• SAVE
• TARGET CONFIGURATION
• C674X_0
• BROWSE, browse the workspace location, open the gel folder and select the
GEL file.
• OPEN
• SAVE
9. In C/C++ Project window, Right click the project
• REBUILD PROJECT.
10. Connections :
a. Connect the usb cable, PC to KIT.
b. Connect the 5v adapter.
c. Power on the kit.
11. TARGET
• DEBUG ACTIVE PROJECT.
12. VIEW
• MEMORY
13. In right side, memory window will open. Type the address and give the input at particular
location.
Give the input as follows:
Enter an Address Location: 0xC0001000 Enter (Input) X(n)
0xC0001000 – 00000001
0xC0001004 – 00000002
0xC0001008 – 00000003
0xC000100C – 00000004
0xC0001010 – 00000004
0xC0001014 – 00000003
0xC0001018 – 00000002
0xC000101C – 00000001
15.TARGET
• RUN
16.TARGET
• HALT
See the Output at Particular location:
a. Enter an Address Location : 0xC0001030 Enter(Real part output)
0xC0001030 – 00000014
0xC0001034 – FFFFFFFB
0xC0001038 – 00000000
0xC000103C – 00000000
0xC0001040 – 00000000
0xC0001044 – 00000000
0xC0001048 – 00000000
0xC000104C – FFFFFFFB
b. Enter an Address Location :0xC0001050 Enter (Imaginary part output)
0xC0001050 – 00000000
0xC0001054 – FFFFFFFFF
0xC0001058 – 0000000C
0xC000105C – 00000000
0xC0001060 – 00000000
0xC0001064 – 00000000
0xC0001068 – 00000000
0xC000106C – 00000002
PROGRAM
#include <math.h>
#define PI 3.14159
float x[8],t[8],s1[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8];
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0,j=0;
Input = (int *)0xC0001000;
Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;
for(i=0;i<8;i++)
{ t[i] = 0;
t[i] = *(Input + i);
}
// Bit reversal process
x[0] = t[0];
x[1] = t[4];
x[2] = t[2];
x[3] = t[6];
x[4] = t[1];
x[5] = t[5];
x[6] = t[3];
x[7] = t[7];
// stage one process
s1[0] = (int)(x[0] + (x[1] * W0r));
s1[1] = (int)(x[0] - (x[1] * W0r));
s1[2] = (int)(x[2] + (x[3] * W0r));
s1[3] = (int)(x[2] - (x[3] * W0r));
s1[4] = (int)(x[4] + (x[5] * W0r));
s1[5] = (int)(x[4] - (x[5] * W0r));
s1[6] = (int)(x[6] + (x[7] * W0r));
s1[7] = (int)(x[6] - (x[7] * W0r));
// stage two process
s2r[0] = (s1[0] + (s1[2] * W0r));
s2i[0] = 0;
s2r[1] = s1[1];
s2i[1] = (s1[3] * W2i);
s2r[2] = (s1[0] - (s1[2] * W0r));
s2i[2] = 0;
s2r[3] = s1[1];
s2i[3] = - (s1[3] * W2i);
s2r[4] = (s1[4] + (s1[6] * W0r));
s2i[4] = 0;
s2r[5] = s1[5];
s2i[5] = (s1[7] * W2i);
s2r[6] = (s1[4] - (s1[6] * W0r));
s2i[6] = 0;
s2r[7] = s1[5];
s2i[7] = -(s1[7] * W2i);
// output
// complex multiplication for B * Wn
Yr[0] = (s2r[4] * W0r) - (s2i[4] * W0i);
Yi[0] = (s2r[4] * W0i) + (s2i[4] * W0r);
Yr[1] = (s2r[5] * W1r) - (s2i[5] * W1i);
Yi[1] = (s2r[5] * W1i) + (s2i[5] * W1r);
Yr[2] = (s2r[6] * W2r) - (s2i[6] * W2i);
Yi[2] = (s2r[6] * W2i) + (s2i[6] * W2r);
Yr[3] = (s2r[7] * W3r) - (s2i[7] * W3i);
Yi[3] = (s2r[7] * W3i) + (s2i[7] * W3r);
Yr[4] = (s2r[4] * W0r) - (s2i[4] * W0i);
Yi[4] = (s2r[4] * W0i) + (s2i[4] * W0r);
Yr[5] = (s2r[5] * W1r) - (s2i[5] * W1i);
Yi[5] = (s2r[5] * W1i) + (s2i[5] * W1r);
Yr[6] = (s2r[6] * W2r) - (s2i[6] * W2i);
Yi[6] = (s2r[6] * W2i) + (s2i[6] * W2r);
Yr[7] = (s2r[7] * W3r) - (s2i[7] * W3i);
Yi[7] = (s2r[7] * W3i) + (s2i[7] * W3r);
// complex addition for A + BWn
j=0;
for(i=0;i<4;i++)
{
Xr[i] = s2r[j] + Yr[i];
Xi[i] = s2i[j] + Yi[i];
j++;
}
// complex subtraction for A - BWn
j=0;
for(i=4;i<8;i++)
{
Xr[i] = s2r[j] - Yr[i];
Xi[i] = s2i[j] - Yi[i];
j++;
}
// sending output array to memory location
for(i=0;i<8;i++)
{
*Real_out ++= Xr[i];
*Imag_out ++= Xi[i];
}
for(;;);
}

RESULT
Thus, the 8 point FFT of given discrete sequence has performed and the result is stored at
memory location (0xC0001030 and 0xC0001050).
b. FFT 8-POINT DIF USING TMS320C6745 DSP
AIM:
To perform the 8-point FFT using DIF process from a given discrete sequence in
TMS320C6745 DSP KIT.
HARDWARE REQUIREMENTS
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS
Code Composer Studio Version 4
PROCEDURE
Follow the same steps as described in the realization of 8-Point FFT using DIT process.
PROGRAM
#include <math.h>
#define PI 3.14159
float x[8],tr[8],ti[8],s1r[8],s1i[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8];
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0;
Input = (int *)0xC0001000;
Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;
for(i=0;i<8;i++)
{ x[i] = 0;
x[i] = *(Input + i);
}
// stage one process
s1r[0] = (int)(x[0] + x[4]);
s1i[0] = 0;
s1r[1] = (int)(x[1] + x[5]);
s1i[1] = 0;
s1r[2] = (int)(x[2] + x[6]);
s1i[2] = 0;
s1r[3] = (int)(x[3] + x[7]);
s1i[3] = 0;
s1r[4] = (int)(x[0] - x[4]) * W0r;
s1i[4] = 0;
s1r[5] = (int)(x[1] - x[5]) * W1r;
s1i[5] = (int)(x[1] - x[5]) * W1i;
s1r[6] = 0;
s1i[6] = (int)(x[2] - x[6]) * W2i;
s1r[7] = (int)(x[3] - x[7]) * W3r;
s1i[7] = (int)(x[3] - x[7]) * W3i;
// stage two process
s2r[0] = (s1r[0] + s1r[2]);
s2i[0] = (s1i[0] + s1i[2]);
s2r[1] = (s1r[1] + s1r[3]);
s2i[1] = (s1i[1] + s1i[3]);
s2r[2] = (s1r[0] - s1r[2]) * W0r;
s2i[2] = 0; // (s1i[0] - s1i[2]) * W0i;
s2r[3] = 0; // (s1r[1] - s1r[3]) * W2r;
s2i[3] = (s1r[1] - s1r[3]) * W2i;
s2r[4] = (s1r[4] + s1r[6]);
s2i[4] = (s1i[4] + s1i[6]);
s2r[5] = (s1r[5] + s1r[7]);
s2i[5] = (s1i[5] + s1i[7]);
s2r[6] = (s1r[4] - s1r[6]) * 1;
s2i[6] = (s1i[4] - s1i[6]) * 1;
s2r[7] = (s1i[7] – s1i[5]) * W2i;
s2i[7] = (s1r[5] – s1r[7]) * W2i;
// output
Xr[0] = (s2r[0] + s2r[1]);
Xi[0] = (s2i[0] + s2i[1]);
Xr[1] = (s2r[0] - s2r[1]);
Xi[1] = (s2i[0] - s2i[1]);
Xr[2] = (s2r[2] + s2r[3]);
Xi[2] = (s2i[2] + s2i[3]);
Xr[3] = (s2r[2] - s2r[3]);
Xi[3] = (s2i[2] - s2i[3]);
Xr[4] = (s2r[4] + s2r[5]);
Xi[4] = (s2i[4] + s2i[5]);
Xr[5] = (s2r[4] - s2r[5]);
Xi[5] = (s2i[4] - s2i[5]);
Xr[6] = (s2r[6] + s2r[7]);
Xi[6] = (s2i[6] + s2i[7]);
Xr[7] = (s2r[6] - s2r[7]);
Xi[7] = (s2i[6] - s2i[7]);
// bit reversal
tr[0] = Xr[0];
ti[0] = Xi[0];
tr[1] = Xr[4];
ti[1] = Xi[4];
tr[2] = Xr[2];
ti[2] = Xi[2];
tr[3] = Xr[6];
ti[3] = Xi[6];
tr[4] = Xr[1];
ti[4] = Xi[1];
tr[5] = Xr[5];
ti[5] = Xi[5];
tr[6] = Xr[3];
ti[6] = Xi[3];
tr[7] = Xr[7];
ti[7] = Xi[7];
// sending output array to memory location
for(i=0;i<8;i++)
{
*Real_out ++= tr[i];
*Imag_out ++= ti[i];
}
for(;;);
}

RESULT
Thus, the 8 point FFT of given discrete sequence has performed and the result is stored at
memory location (0xC0001030 and 0xC0001050).
Exp.No.13 Date:
WAVEFORM GENERATION
AIM:
To generate a sine waveform, square waveform, sawtooth waveform and triangular waveform
using TMS320C6745 DSP KIT.
HARDWARE REQUIREMENTS
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS
Code Composer Studio Version 4
THEORY:
Sine Wave:
The simplest method to generate Sine wave is to use Trignometric Sin function. The Sin
function will generate the samples from the given specific parameter like sampling frequency,
number of samples, input frequency. In this project, generating the correct sample is important.
The library function "sin()" does all of the work

Its most basic form as a function of time (t) is :


𝑦(𝑡) = sin (ωt + φ)
where: A, the amplitude, is the peak deviation of the function from its centre position.
ω, the angular frequency, specifies how many oscillations occur in a unit time
interval, in
radians per second
φ, the phase, specifies where in its cycle the oscillation begins at t = 0.
When the phase is non-zero, the entire waveform appears to be shifted in time by the amount
φ/ω seconds. A negative value represents a delay, and a positive value represents an advance.
Square Wave:
Square waves have an interesting mix of practice and theory. In practice, they are extremely
simple. In their simplest form, they consist of an alternating sequence of amplitudes; e.g.
high/low or 1's and 0's. The same high / low logic is implemented in this experiment. For
particular duration the high state is out, then low state is out. Finally square wave is generated
and plotted in code composer studio Graph.
Sawtooth Wave:
Saw tooth waves have an interesting mix of practice and theory. In practice, they are extremely
simple. In their simplest form, they consist of an alternating sequence of increasing the
amplitude and low state; e.g. increment voltage to reach peak and out the 0v. The same
increment/zero logic is implemented in this experiment.
For step by step duration the voltage is incremented, when it reached it peak, then 0v voltage
is out. Finally Sawtooth wave is generated and plotted in code composer studio Graph.
Triangular Wave:
Triangle waves have an interesting mix of practice and theory. In practice, they are extremely
simple. In their simplest form, they consist of an alternating sequence of increasing the
amplitude and decreasing the amplitude; e.g. increment voltage to reach peak and decrement
voltage to reach 0v. The same increment / decrement logic is implemented in this experiment.
For step by step duration the voltage is incremented , when it reached it peak, then decrement
of voltage is out.
Finally Triangle wave is generated and plotted in code composer studio Graph.
PROCEDURE:
1. Open Code Composer Studio v4.
2. In Workspace Launcher.
a. BROWSE
• Select the project location and make one new folder,MAKE NEW FOLDER
• Type the Workspace name, OK
• OK.
3.FILE
• NEW
• CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location.
• NEXT
c. Project type: C6000.
d. Tick Debug and Release.
• NEXT
• NEXT.
e. Output type: Executable.
f. Device Variant: generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Target content: none.
• FINISH
4. FILE
• NEW
• SOURCE FILE
Source file: Type your projectname.c (.c extension is must).
b. Type the program.
c. FILE
• SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder (contains library files)
6. Paste the Linker file in the project location.
7. PROJECT
• PROPERTIES
• C/C++ BUILD
• BASIC OPTION
e. Target processor version( -- silicon version, -mv) : 6400+
f. OK.
IN C/C++ BUILD,
• INCLUDE OPTIONS (Add dir to #include search path(--include_path, - I))
select this add icon and add the following three path by individually
• "${Diag}../../common/header"
• "${XDAIS_CG_ROOT}/packages/ti/xdais"
• "${C6000_CSL_CG_ROOT}/include"
8. FILE
• NEW
• TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745.
• SAVE
• TARGET CONFIGURATION
• C674X_0
• BROWSE, browse the workspace location, open the gel folder and select the
GEL file.
• OPEN
• SAVE
9. In C/C++ Project window, Right click the project
• REBUILD PROJECT.
10. Connections :
a. Connect the usb cable, PC to KIT.
b. Connect the 5v adapter.
c. Power on the kit.
11. TARGET
• DEBUG ACTIVE PROJECT.
12. TARGET
• RUN
13. TARGET
• HALT
14. TOOLS
• GRAPH
• SINGLE TIME
(For Sine Wave)
a. Acquisition buffer size : 256
b. Index increment :1
c. Data type : 16-bit signed int
c. Start address : 0xC0000000.
d. Display data size : 256
• Ok
. (For Square and Triangle Wave)
b. Acquisition buffer size : 500
b. Index increment :1
c. Data type : 32-bit signed int
c. Start address : 0xC0000000.
d. Display data size : 500
PROGRAM
Sine Wave
#include<stdio.h>
#include<math.h>
#define PI 3.14
void main()
{
const float sampf = 1024000.0;// Sampling frquency is fixed
const int inpf = 4000; // change the input frquency from 1khz to 8khz(1000 to 8000)
float sampt;
double teta;
short value,*sinout;
int i,count,nsamp,value1;
sinout = (short *)0xc0000000;
sampt = 1/sampf;
nsamp = sampf/inpf;
printf("\n Sampling Frequency is : %f",sampf);
printf("\n Sampling Time is :%f",sampt);
printf("\n Input Frequency is : %d",inpf);
printf("\n The number of Sample is : %d",nsamp);
for(i=0;i<400;i++)
*(sinout+i)=0;
for(count=0;count<nsamp;count++)
{ teta = (2 * PI * inpf * sampt * count);
printf("\nteta = %lf",teta);
value = sin(teta)*1024;
printf("\t sin %lf Value is : %d",teta,value);
value1 = value&0x0000FFFF;
*sinout++ = value1;
}

}
Square Wave
#include <stdio.h>
#include <math.h>
void main()
{
int *Square;
int i;
Square = (int *)0xC0000000;
while(1)
{ for(i=0;i<50;i++)
{ *Square++ = 0x0000FFFF;
}
for(i=0;i<50;i++)
{ *Square++ = 0x0;
}
}
}

Triangle Wave
#include <stdio.h>
#include <math.h>
void main()
{
int *Triangle;
int i=0,j=0;
Triangle = (int *)0xC0000000;
while(1)
{
for(i=0;i<50;i++)
{ j=j+1;
*Triangle++ = j;
}
for(i=50;i>0;i--)
{ j=j-1;
*Triangle++ = j;
}
}
}

RESULT
Thus, the Sine, square, triangle and sawtooth waveforms were generated and the corresponding
samples is stored at memory location(0xc0000000).
Exp.No.14 Date:
a. FIR LOW PASS FILTER DESIGN USING TMS320C6745
AIM:
To implement the FIR Low pass filter using TMS320C6745 DSP KIT.
HARDWARE REQUIREMENTS:
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS:
Code Composer Studio Version 4
THEORY:
Digital FIR filter fully involve with the signal, Applying FIR filter algorithm by doing some
mathematical operation on signals like an addition, convolution, shifting etc.., then it produces
an output signal in the form of digital so the digital to analog conversion is required at output
and an analog to digital conversion is required to provide the input to Digital signal processor,
this is called the basic elements of DSP.

1. FIR FILTER:
FIR (Finite Impulse Response) filter is a digital filter without a feedback, it is also known as
non-recursive digital filters, even though recursive algorithms can be used for FIR filter
realization. The output y(n) of a filter system is determined by convolving its input signal x
(n) with its impulse response h (n).
For a discrete-time FIR filter, the output is a weighted sum of the current and a finite number
of previous values of the input. The operation is described by the following equation and shown
in the figure1, which defines the output sequence y (n) in terms of its input sequence x (k) and
h (k):
The equation of the FIR filter is as follows:
y(n) = c0 x(n-1) + c1 x(n-2) + .............

Where,
x (n) is input signal
y (n) is output signals are related via the convolution operation.
h (k) is filter coefficients (ci) c0, c1, c2, etc..,
N is a filter order.
Coefficients h (n): always coefficients are fixed constants for a fixed cut off frequency; we may
change the coefficients at any time. Mostly use MATLAB fda tool to generate the coefficients.

Input data x (n): always read the new sample from ADC for every clock cycle and update the
filter system for all iteration. After the convolution process, read the new sample for x(n), one
time shifts all the old sample and omit the fifth sample for every clock cycle.

Example: Consider the above FIR filter system with N=5.


Let N = 5 represent the order of coefficients.
Let Coefficients h (n) is:

5th order 1 kHz cut off frequency coefficients Ci are {0.0202, 0.5069, 0.9806, 0.8125, and
0.9981}
Input data x (n):

x (n) represents new adc sample values.


The equation in this case is as follows:

Detailed description of the FIR filter algorithm is given below:


Here x(0) = 0; and x(n) = adc samples; n = 0, 1, 2…
2. Implementation of FIR filter algorithm on TMS320C6745 DSP Kit
• Receive the inputs via SPI ADC on TMS320C6745 DSP kit.
• Then, process the fir filter algorithm on Processor it is called Digital signal processing.
• Transmit the y (n) value to the SPI DAC on TMS320C6745 dsp kit.

3. FEATURES OF ADC 32022.7V DUAL CHANNEL 12-BIT A/D CONVERTER


WITH SPI SERIAL INTERFACE
Features Description
Figure 5.1 : Communication with the MCP3202 using MSB first format only
MPC 4921 12- Bit Voltage Output Digital-to-Analog Converter with SPI Interface
Write Command
PROGRAM:
#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"
#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0; //(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1; //(CS=High:Disable)
voidSPI_Write(unsigned short Data);
unsigned short i,j=0,High,Value=0;
signedintadc_value;
//Low Pass sampfr=6khz sbf=200 pbf=400
//Store the coefficients in program using an array, N=51
float h[51] = {
0.01060591545, 0.004117832519, 0.004079894163, 0.003353076056, 0.001853102469,
-0.0004065925605,-0.003321184311,-0.006660183426, -0.01010407601, -0.01322921738,
-0.01557052694, -0.01663137041, -0.01597031951, -0.01320868172,-0.008123514242,
-0.000646590197, 0.0090885479, 0.02072319016, 0.03375224397, 0.04746999219,
0.06107512116, 0.07372291386, 0.08458722383, 0.09293565154, 0.09818658978,
0.09997936338, 0.09818658978, 0.09293565154, 0.08458722383, 0.07372291386,
0.06107512116, 0.04746999219, 0.03375224397, 0.02072319016, 0.0090885479,
-0.000646590197,-0.008123514242, -0.01320868172, -0.01597031951, -0.01663137041,
-0.01557052694, -0.01322921738, -0.01010407601,-0.006660183426,-0.003321184311,
-0.0004065925605, 0.001853102469, 0.003353076056, 0.004079894163, 0.004117832519,
0.01060591545
};
void main( void )
{
Uint8 spiadcbuf[3];
inti,xval[120],k;
floattemp,sum;
// Initialize the TMS320C6745 kit, spiadc and spidac.
C6745_init();
spiadc_init();
spidac_init();
// For initial operation load a zero at input array locations.
for(i=0;i<52;i++)
{
xval[i]=0;
}
// Start the operation with conditional loop statements (for, if, while). Send
command to
SPI SLAVE ADC 3202 device and Read the adc value for x (n).
while(1)
{
spiadcbuf[0] = 0x01; // setup command (setting start bit)
spiadcbuf[1] = 0xBF; // setting second 8 bits (first four bits –
configuration of ADC last four bits – actual ADC data (B11 – B8)
SGL = 1 ODD = 0 MSBF = 1 Null Bit B11=1 B10= 1 B9 = 1 B8 = 1
(Single (Channel - MSB bit = 1
ended 0) first
mode) format
spiadcbuf[2] = 0x00; // sends the last 8 bits (B7 – B0)
spiadc_cycle(spiadcbuf, 3); // Execute spiadc read cycle(3 clock cycles
indicates the sampling time period for conversion)
adc_value = ((spiadcbuf[1]&0x0f)<<8)|spiadcbuf[2];
// This adc_value variable will contain the new sample x (n) for every clock cycle. Start the Fir
filter operation, by convoluting the input sample and coefficients it provides the output y (n).
The output is a weighted sum of the current and a finite number of previous values of the input.
// FIR Filter Function
xval[0] = adc_value;
sum = 0;
for(k=0;k<51;k++)
{
temp = (xval[k])*(h[k]);
sum = sum + temp;
}
// Check the analog output signal with the help of SPI DAC so transmit the “sum” variable.
SPI_Write(sum);
//Shift the values to the next level and omit the last sample, so that first place of array is waiting
for new adc sample values. For each iteration it updates the filter system input.
for(i=50;i>=0;i--)
{
xval[i+1] = xval[i];
}
}
}
/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
voidSPI_Write(unsigned short Data)
{
unsigned short receive;
// To write analog value Chip Select (CS) should be made low.
DAC_CS_LOW();
Data = ( 0x3000 | Data ); // DAC data register yields 16-bit data of which first 4 bits
from MSB indicates configuration and the remaining 12-bits represent the actual data.
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x20000000 ); // SPIBUF – 32-bit register
// SPI Transmit Buffer Register Format

Bit 31 – Receiver Empty = 0


Bit 29 – Transmitter Full = 1
/* Write 1 byte */
SPI0_SPIDAT0 = Data;
// SPI Receive Buffer Register Format

while((SPI0_SPIBUF & 0x80000000)==1);


/* Read 1 byte */
receive = SPI0_SPIBUF;
// Introduce time delay
for(i=0;i<10;i++);
// After DAC conversion is complete, make Chip Select signal high
DAC_CS_HIGH(); //
}

RESULT:
Thus, the FIR low pass filter was realized using TMS320C6745 for the given filter
specifications.
b. IIR LOW PASS FILTER DESIGN USING TMS320C6745
AIM:
To implement the IIR Low pass filter using TMS320C6745 DSP KIT.
HARDWARE REQUIREMENTS:
1. TMS320C6745 KIT
2. USB Cable
3. 5V Adapter
4. Computer Desktop
SOFTWARE REQUIREMENTS:
Code Composer Studio Version 4
THEORY:
Infinite impulse response (IIR) is a property of signal processing systems. Systems with this
property are known as IIR systems or, when dealing with filter systems, as IIR filters. IIR
systems have an impulse response function that is non-zero over an infinite length of time. This
is in contrast to finite impulse response (FIR) filters, which have fixed-duration impulse
responses. The simplest analog IIR filter is an RC filter made up of a single resistor (R) feeding
into a node shared with a single capacitor (C). This filter has an exponential impulse response
characterized by an RC time constant. Because the exponential function is asymptotic to a limit,
and thus never settles at a fixed value, the response is considered infinite. IIR filters may be
implemented as either analog or digital filters. In digital IIR filters, the output feedback is
immediately apparent in the equations defining the output. Example IIR filters include the
Chebyshev filter, Butterworth filter, and the Bessel filter.
Digital filters are often described and implemented in terms of the difference equation that
defines how the output signal is related to the input signal:

where:
P is the feedforward filter order
bi are the feedforward filter coefficients
Q is the feedback filter order
ai are the feedback filter coefficients
x[n] is the input signal
y[n] is the output signal.
After deriving the above equation, finally considering that in most IIR filter designs coefficient
a0
is 1, the IIR filter transfer function takes the more traditional form:

PROGRAM:
#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"
#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0; //(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1; //(CS=High:Disable)
void SPI_Write(unsigned short Data);
static float xv[3], yv[3];
int Chebyshev(int input);
//LP co-efficient samp fr=6khz passband fr=400hz
float a0=1,a1=-1.481033206,a2= 0.6363137364;
float b0=1,b1=2,b2=1;
#define GAIN 0.03882011771
void main( void )
{
static Uint8 spiadcbuf[3];
int adc_value,vout=0;
C6745_init();
spiadc_init();
spidac_init();
while(1)
{
spiadcbuf[0] = 0x01; // setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;
spiadc_cycle(spiadcbuf, 3); // Execute spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)| spiadcbuf[2];
vout = Chebyshev(adc_value);
SPI_Write(vout);
}
}
/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive,j;
DAC_CS_LOW();
Data = ( 0x3000 | Data );
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x10000000 );
/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);
/* Read 1 byte */
receive = SPI0_SPIBUF;
for(j=0;j<10;j++);
DAC_CS_HIGH();
}
int Chebyshev(int input)
{
int vout=0;
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = input;
yv[0] = yv[1];
yv[1] = yv[2];
//yv[2] = (xv[0] + xv[2]) + 2 * xv[1] + ( -0.6363137257 * yv[0]) + ( 1.4810332533 *
yv[1]);
yv[2] = (b0*xv[0] + b2*xv[2]) + b1 * xv[1] - ( a2 * yv[0]) - ( a1 * yv[1]);
vout = yv[2]*GAIN;
return vout;
}

RESULT:
Thus, the IIR low pass filter was realized using TMS320C6745 for the given filter
specifications.

You might also like