DSP Lab Manual
DSP Lab Manual
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.
MATLAB understands the basic arithmetic operations: +, -, *, /. Powers are indicated with ^,
thus typing
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
>> 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.
>> who
tells about all the variables that are in the workspace of the current MATLAB session.
Vectors
>> 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,
>> 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:
>> d = b – a;
>> dd = d*d’;
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
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,
>> 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
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,
or
To save a certain part of the work in the MATLAB session, one can type,
>> ….
>> ….
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 is a 3 by 1 column matrix
D is a 2 by 3 matrix
To perform operations on matrices you use the symbols ( +, -, * ) from the number keypad or
above the numbers across the top of the keyboard.
Examples:
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
ax+by+cz=u
ex+fy+gz=v
px+qy+rz=w
>> A = [a b c; e f g; p q r];
>> M = [A b];
>> R = rref(M);
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 )
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:
>> rref(A) calculates the row reduced echelon form of the matrix A
>> format long displays all numbers with 15 digits instead of the usual 4 digits
sin, cos, tan, sec, csc, cot, asin, acos, atan, asec, acsc, acot
sinh, cosh, tanh, sech, csch, coth, asinh, acosh, atanh, asech, acsch, acoth
feval, fminbnd, fzero, quad, ode23, ode45, vectorize, inline, fplot, explot
>> 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:
>> 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,
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,
x(n)=sin(n*pi/10); end
>> x
x=
Columns 1 through 7
Columns 8 through 10
Let us now use the for loop to generate the first 15 Fibonacci numbers 1,1,2,3,5,8,…
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:
>> k=1;
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,
cost =
250
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
else
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_2 …
…..
otherwise
Commands_n ….
end
Let us now consider the problem of converting entry in given units to centimeters.
% centimeter.m
function y=centimeter(A,units)
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
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 =
>> 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=
>> w=[u v]
w=
>> disp(w)
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;
>> disp(t)
Relational 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=
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.
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=00110
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,
>> 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:
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');
Signal Manipulation
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
-----------------------(2)
and for discrete time signals, the cross-correlation can be written as
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)
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 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).
and
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
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.
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:
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:
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: ');
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.
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.
DSP Subsystem:
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 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:
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
}
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.
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):
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.