DSP Lab Manual 2016
DSP Lab Manual 2016
3. Convolution and Correlation (auto and cross correlation) of discrete sequences without using
built in functions for convolution and correlation operations.
4. DTFT of a given signal
5. N – point FFT algorithm
6. Design of FIR filter using windowing technique and verify the frequency response of the
filter.
7. Design of IIR filter using any of the available methods and verify the frequency response of
the filter.
8. Design of analog filters.
Equipment/Software Required:
1. Licensed MATLAB software with required tool boxes for 30 users.
2. DSP floating Processor Kits with Code Composure Studio (8 nos.)
3. Function generators
4. CROs
5. Regulated Power Supplies.
CONTENTS
List of experiments using MATLABPage No.
Introduction to MATLAB
MATLAB is a powerful high-level programming language for scientific computations.
Itis very easy to learn and use in solving numerically complex engineering problems.some basic
concepts of MATLAB are included here for a quick reviewto facilitateyour understanding of the
programs.The MATLAB name stands for MATrix LABoratory.
MATLAB consists of functions that are either built into the interpreter or available as M-
files,with each containing a sequence of program statements that execute a certain algorithm.A
completely new algorithm can be written as a program containing only a few of thesefunctions
and can be saved as another M-file.
2.Quitting MATLAB: To end your MATLAB session on Windows platforms, select File ---->
Exit in MATLAB window in the desktop(or) type quit in the Command Window.
1.Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt
2.Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow
3. Editor window: This is where you write edit, create and save your own programs in files
called M files.
To create or edit an M-file use File---> New (or) File ----> Open, or use the edit function.
In addition to the above three windows the following were appeared on MATLAB
Windows Desktop
(i) Command History: Statements entered in the Command Window are logged in the
Command History. From the Command History, previously run statements can be viewed,
copied and executed. M-file can be created from selected statements.
(ii) Current Directory Browser and Search Path: MATLAB file operations use the current
directory and the search path as reference points. Any file required to run must either be in the
current directory or on the search path.
(iii) Workspace Browser and Array Editor: The MATLAB workspace consists of the set of
variables (named arrays) built up during a MATLAB session and stored in memory. The
variables can be added to the workspace by using functions, running M-files, and loading saved
workspaces. To delete variables from the workspace, select the variables and select Edit >
Delete.
(iv) Array Editor: Double-click a variable in the Workspace browser, or use open var variable
name, to see it in the Array Editor. Use the Array Editor to view and edit a visual representation
of variables in the workspace.
Input-output:
MATLAB supports interactive computation taking the input from the screen and
flushing, the output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data –type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, charcter strings, structures and cells.There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required
for vectors or arrays .we can find the dimensions of an existing matrix or a vector with the size
and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in the
a)Command window
b) As an M file using Matlab editor
Note: Save all M files in the folder 'work' in the current directory. Otherwise you have to locate
the file during compiling.
For any clarification regarding plot etc, which are built in functions type help topic
i.e. help plot
The commands between the for and end statements are executed for all %values stored
in the array.
The for loops can be nested
H = zeros(5);
for k=1:5
for l=1:5
H(k,l) = 1/(k+l-1);
end
end
commands
case value2 (executes if expression evaluates to value2)
commands
...
otherwise
statements
end
.
5. Creating functions using m-files
Files that contain a computer code are called the m-files.
There are two kinds of m-files: the script files and the function files.
Script files do not take the input arguments or return the output arguments. The function files
may take input arguments or return output arguments.
To make the m-file click on File next select New and click on M-File
from the pull-down menu.
You will be presented with the MATLAB Editor/Debugger screen. Here you will type your code,
can make %changes, etc. Once you are done with typing, click on File, in the MATLAB
Editor/Debugger screen and select Save As… .
Chose a name for your file, e.g., firstgraph.m and click on Save. Make sure that your
file is saved in the directory that is in MATLAB's search path. If you %have at least two
files with duplicated names, then the one that occurs first in MATLAB's search path will
be executed.
To open the m-file from within the Command Window type edit firstgraph %and then
Press Enter or Return key.
6. Graphs in MATLAB
save the script file and the run it
Script file graph1.
interval (0,1)
randn Generates random numbers and matrices normally distributed with zero
mean and unity variance
real Determines the real part of a complex number or matrix
rem Determines the remainder of a matrix divided by another matrix of same
size
resample Changes the sampling rate of a sequence by a rational number
residue Determines the partial-fraction of a discrete-time transfer function
expressed as a ratio of polynomials in z
return Causes a return to the keyboard or to the invoking function
roots Determines the roots of a polynomial
save Saves workspace variables on a disk
sawtooth Generates a sawtooth wave with a period 2π
sign Implements the signum function
sin Determines the sine
sinc Computes the sinc function of a vector or array
size Returns the matrix dimensions
sqrt Computes the square root
square Generates a square wave with a period 2π
stairs Draws a stairstep graph
stem Plots the data sequence as stems from the x axis terminated with circles for
the data value
subplot Breaks figure window into multiple rectangular panes for the display of
multiple plots
sum Determines the sum of all elements in a vector
title Write specified text on the top of the current plot
what Provides directory listing of files
which Locates functions and files
while Repeats statements an indefinite number of times
who Lists the current variables in the memory
whos Lists the current variables in the memory, their sizes, and whether they
have non-zero imaginary parts
xlabel Write specified text below the x-axis of the current 2-D plot
ylabel Write specified text on the left side of the y-axis of the current 2-D plot
zeros Generates a vector or a matrix with element 0
Generation of signals
Aim:-To generate the following signals using MATLAB 6.5
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal
Program:
1. Unit impulse signal
clc;
clear all;
close all;
disp('UNIT IMPULSE SIGNAL');
N=input('Enter Number of Samples: ');
n=-N:1:N
x=[zeros(1,N) 1 zeros(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Impulse Response');
6. Cosine signal
clc;
clear all;
close all;
disp('COSINE SIGNAL');
N=input('Enter Number of Samples : ');
n=0:.1:N
x=cos(n)
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine ignal');
Output:-COSINE SIGNAL
Enter Number of Samples : 16
7. Sine signal
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Enter Number of Samples : ');
n=0:.1:N
x=sin(n)
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('sine Signal');
Output:-SINE SIGNAL
Enter Number of Samples : 16
Questions:
1. Define signal?
2. Define Ramp Signal?
3. Define Exponential Signal?
4. Define sine signal?
5. Define impulse signal?
6. Define pulse signal?
7. What are m-files?
8. What are various windows in matlab?
9. Define analog signal?
10. Definde Digital signal?
Result:-Thus the MATLAB program for generation of all basic signals was performed and the
output was verified.
INFERENCE:
Applications:
Regularity
Viva-Voce
Program:-
% sum of sinusoidal signals
clc;
clear all;
close all;
tic;
t=0:.01:pi;
Output:-
Questions:
1. Define signal?
2. Define sine signal?
3. How you can generate different sinusoidal signals?
4. Define Discrete-time signal?
5. Define continuous time signal?
6. Define sinusoidal sequences?
Result:-Thus the MATLAB program for sum of sinusoidal signals was performed and the output
was verified.
INFERENCE:
APPLICATIONS:
Observation
Regularity
Viva-Voce
Aim:- write a MATLAB program to the generation of random signal and plot the same as a
waveform showing all the specifications.
Program:
clc;
clearall;
closeall;
disp('Random SIGNAL');
n=1:N
k=randn(n,N)
stem(n,k);
xlabel('Time');
ylabel('Amplitude');
Output:
Questions:
1. Define random signal?
2. Define Deterministic signal?
3. Define syatem?
4. Define linear system?
5. Define LTI system?
Result:-Thus the MATLAB program for the generation of random signal was performed and the
output was verified.
INFERENCE:
APPLICATIONS:
Observation
Regularity
Viva-Voce
Aim: - To write a MATLAB program to find power and energy of a given signal
Program:
clc;
x=cos(2*pi*100*t)+cos(2*pi*200*t)+sin(2*pi*300*t);
energy=(norm(x)^2)
power = (norm(x)^2)/length(x)
psd1=spectrum(x,1024);
specplot(psd1,Fs);
output:
Questions:
1. Define Power signal?
2. Define Energy signal?
3. Find the energy of a power signal?
4. Find the power of aa energy signal?
5. Define causal system?
Result:-Thus the MATLAB program for calculating energy and power of a given signal was
performed and the output was verified.
INFERENCE:
APPLICATIONS:
Observation
Regularity
Viva-Voce
Aim :To write the Convolution and Correlation (auto and cross correlation) of discrete sequences without
using built in functions for convolution and correlation operations.
clc;
clear all;
close all;
m=length(x);
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
xlabel('---->n');
ylabel('---->h(n)');grid;
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
subplot(2,2,[3,4]),stem(y);
xlabel('---->n');
ylabel('---->y(n)');grid;
Output:
Result:
end
end
end
disp(y);
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');grid;
OUTPUT:-
Result:
Program:
%Auto Correlation%
x= input (‘Enter any sequence’);
subplot(3,2,1);
stem(x);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Input sequence’);
y=xcorr(x);
subplot(3,2,2);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Auto correlation’);
Program:
%Cross correlation%
x=input(‘Enter any sequence’);
subplot(3,2,1);
stem(x);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Input sequence’);
h=input(‘Enter any sequence’);
subplot(3,2,2);
stem(h);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Impulse sequence’);
y=xcorr(x,h);
subplot(3,2,3);
stem(y);
xlabel(‘Time period’);
ylabel(‘Amplitude’);
title(‘Cross correlation’);
QUESTIONS:
1. Define Convolution
2. Define Correlation
3. Give applications of convolution and correlation
4. Define auto-correlation?
5. Define cross-correlation?
6. Define linear convolution?
7. Define circular convolution?
8. Define circular convolution with zero padding?
9. Find the length of the linear convolution sequence?
10. Find the length of the circular convolution sequence
Result:
Thus, the auto- correlation and cross- correlation was performed using
MATLAB
INFERENCE:
APPLICATIONS:
Observation
Regularity
Viva-Voce
PROGRAM:
%Inverse DTFT
wn1=exp(j*2*pi/N);
nK1=n'*K;
wN1nK1=wn1.^nK1;
inversdf=(df*wN1nK1)/N;
subplot(3,1,3);
stem(x,abs(inversdf));
title('Inverse DTFT');
xlabel('N');
ylabel('Magnitude');
QUESTIONS:
1. Define DTFT?
2. Define IDTFT?
3. Discuss DTFT pair?
4. Write the symmetry property of DTFT?
5. What is ideal reconstruction filter?
6. What is reconstruction signal?
Result:
Thus, the DTFT Of a given signal was performed successfully by using
MATLAB software
N-Point FFT
EQUIPMENTS:
Constructor - Simulator
THEORY:
M nk
−j 2π
X ( k )=∑ x ( n) e n
; 0<k < N −1
k=0
The above equation is the mathematical representation of the DFT. As the
number of computations involved in transforming a N point time domain
signal into its corresponding frequency domain signal was found to be N2
complex multiplications, an alternative algorithm involving lesser
number of computations is opted.
When the sequence x(n) is divided into 2 sequences and the DFT performed
separately, the resulting number of computations would be N2/2
(i.e.)
N
2 N2
2−1 2−1
x ( k )=∑ x (2 n ) W 2Nnk + ∑ x ( 2 n+1 ) W (2
N
n+1 )k
n=0 n=0
Consider x(2n) be the even sample sequences and x(2n+1) be the odd
sample sequence derived form x(n).
N2
2−1
∑ x ( 2 n) W 2nk
N
n=0
would result
N2
2−1
∑ x (2 n+1) W (N2 n+1 )k
(N/2)2multiplication’s n=0
N2 N
2−1 2−1 k
x ( k )= ∑ x ( 2 n) W 2nk
N + ∑ x( 2 n+1 ) W (2 nk )
N W
n=0 n=0 N
(9)
N N
2−1 k 2−1
= ∑ x ( 2 n ) W 2Nnk +W ∑ x ( 2 n+1) W (N2 nk)
n=0 N n=0 (10)
Dividing the sequence x (2n) into further 2 odd and even sequences would reduce the
computations.
− j2 π
n
=e
nk
W =e
( n )
− j 2π
nk
N
W
( K+ )
N
2
=W W
( K+ )
N
2
N N N
(11)
− j2 π − j 2π n
k
n n 2
=e e
−j2π
k
=W kN e n
=W kN (cos π − j sin π )
=W
( K+ )
N
2
=W k (−1)=W
( K+ )
N
2
=W k
N N N N
N2 N
2−1 2−1
x ( k )= ∑ x ( 2 n) W 2nk
N + ∑ x( 2 n+1 ) W N
(2 nk )
N
2−1 K N
N
x ( k + )= ∑ x ( 2 n) W 2Nnk −W ∑ x ( 2 n+1 ) 2−1 W (N2 nk)
2 n=0 N (14)
The time burden created by this large number of computations limits the usefulness of
DFT in many applications. Tremendous efforts devoted to develop more efficient ways of computing
DFT resulted in the above explained Fast Fourier Transform algorithm. This mathematical shortcut
reduces the number of calculations the DFT requires drastically. The above mentioned radix-2
decimation in time FFT is employed for domain transformation.
Dividing the DFT into smaller DFTs is the basis of the FFT. A radix-2 FFT divides the DFT into two
smaller DFTs, each of which is divided into smaller DFTs and so on, resulting in a combination of
two-point DFTs. The Decimation -In-Time (DIT) FFT divides the input (time) sequence into two
groups, one of even samples and the other of odd samples. N/2 point DFT are performed on the
these sub-sequences and their outputs are combined to form the N point DFT.
FIG. 3A.1
The above shown mathematical representation forms the basis of N point FFT and is called theButterfly
Structure.
clc;
clear all;
close all;
tic;
%compute fft
X=fft(x,n)
subplot(1,2,1);stem(x);
title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
subplot(1,2,2);stem(X);
output:
QUESTIONS:
1. Define FFT?
2. Define DFT?
3. Discuss DITFFT?
4. Discuss DIFFFT?
5. What is radix-2 FFT?
6. What is radix-4 FFT?
7. What is radix-8 FFT?
8. What is radix-16 FFT?
Result:
Thus, the FFT Of a given signal was performed successfully by using
MATLAB software
Result:
FIR filters
AIM: Design the FIR filter using windowing technique and verify the frequency response of the
Filter by using MATLAB software.
EQUIPMENTS:
Constructor - Simulator
THEORY:
whose output is based on the weighted summation of a finite number of past inputs.
The coefficients are generated by using FDS (Filter Design Software or Digital filter design package).
FIR – filter is a finite impulse response filter. Order of the filter should be specified.
finite length does this. Types of windows available are Rectangular, Barlett,
Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter.
PROGRAM:
clc;
clear all;
close all;
fp=input('enter passbandfreq');
fs=input('enter stopbandfreq');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
if(c==1)
y=rectwin(n1);
end
if (c==2)
y=triang(n1);
end
if(c==3)
y=kaiser(n1);
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
%BPF
wn=[wpws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
OUTPUT:-
QUESTIONS:
1. Define FIR filter?
2. Define IIR filter?
3. Define Kaiser window?
4. Define Rectangular window?
5. Define Triangular window?
Result:
Thus, the FIR filters is verified and implemented successfully by using MATLAB software
IIR filters
AIM: . Design the IIR filter using any of the available methods and verify the frequency response
of the filters by using MATLAB software.
EQUIPMENTS:
Constructor - Simulator
THEORY:
The IIR filter can realize both the poles and zeroes of a system because it has arational transfer function, de
scribed by polynomials in z in both the numerator andthe denominator .These filter coefficients are genera
ted using FDS (Filter Design software or Digital Filter design package).
IIR filters can be expanded as infinite impulse response filters. In designing IIRfilters, cutoff frequencies of t
he filters should be mentioned. The order of the filter
can be estimated using butter worth polynomial. That’s why the filters are named as
butter worth filters. Filter coefficients can be found and the response can be plotted.
PROGRAM :
clc;
clear all;
close all;
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
if(c==1)
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
ylabel('Phase in radians-->');
Output:
QUESTIONS:
1. Define FIR filter?
2. Define IIR filter?
3. Define Butterworth filter?
4. Define Chebychev filter?
5.
Result:
Thus, the IIR filters is verified and implemented successfully by using MATLAB software
Program:
%LPF%
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=0:0.01/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);
plot((om/pi),m);
xlabel('time');
ylabel('amplitude');
title('magnitude plot of lpf');
subplot(2,2,2);
plot((om/pi),an);
xlabel('time');
ylabel('amplitude');
title('angle plot of lpf');
%HPF%
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
wp=input('enter the pass band frequency');
ws=input('enter the stop band frequency');
fs=input('enter the sampling frequency');
w1=2*(wp/fs);
w2=2*(ws/fs);
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0:0.01/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,2,1);
plot((om/pi),m);
xlabel('time');
ylabel('amplitude');
title('magnitude plot of hpf');
subplot(2,2,2);
plot((om/pi),an);
xlabel('time');
ylabel('amplitude');
Result:
Thus, the Chebyshev filter was designed using Mat Lab
AIM: To verify the frequency response of analog LPF/ HPF using MATLAB soft ware
EQUIPMENTS:
Constructor - Simulator
THEORY:
Analog Low pass filter & High pass filter are obtained by using butterworth or chebyshev filter with
coefficients are given. The frequency – magnitude plot gives the frequency response of the filter.
PROGRAM:
clc;
clear all;
close all;
warning off;
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
if(c==1)
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
ylabel('Phase in radians-->');
Output:
Result:
Thus The frequency response of analog LPF/ HPF is performed successfully by using MATLAB
software.
A signal can be defined as a function that conveys information, generally about the state
or behavior of a physical system. There are two basic types of signals viz Analog (continuous
time signals which are defined along a continuum of times) and Digital (discrete-time)..
Microprocessor or General Purpose Processor such as Intel xx86 or Motorola 680xx family
-No RAM
-No ROM
-No Timer
- RAM
- ROM
- I/O ports
- Timer &
- Interrupt circuitry
Some Micro Controllers also contain A/D, D/A and Flash Memory
DSP Processors such as Texas instruments and Analog Devices Contains - CPU
- RAM
-ROM
- I/O ports
- Timer
- Extended precision
- Circular buffering
Feature Use
Bus Structure
The C67xx DSP architecture is built around eight major 16-bit buses (four program/data buses
and four address buses):
1. The program bus (PB) carries the instruction code and immediate operands from program
memory.
2. Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,
data address generation logic, program address generation logic, on-chip peripherals, and data
memory.
3. The CB and DB carry the operands that are read from data memory.
5. Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for instruction
execution.
The C67xx DSP can generate up to two data-memory addresses per cycle
using the two auxiliary register arithmetic units (ARAU0 and ARAU1). The PB can carry data
operands stored in program space (for instance, a coefficient table) to the multiplier and adder for
multiply/accumulate operations or to a destination in data space for data move
instructions(MVPD and READA). This capability, in conjunction with the feature of dual-
operand read, supports the execution of single-cycle, 3-operand instructions such as the FIRS
instruction. The C67xx DSP also has an on-chip bidirectional bus for accessing on-chip
peripherals. This bus is connected to DB and EB through the bus exchanger in the CPU interface.
Accesses that use this bus can require two or more cycles for reads and writes, depending on the
peripheral’s structure.
The CPU is common to all C67xE devices. The C67x CPU contains:
Barrel shifter
17 × 17-bit multiplier
40-bit adder
Compare, select, and store unit (CSSU)
Data address generation unit
Program address generation unit
Arithmetic Logic Unit (ALU)
The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit (ALU)
and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean
operations. The ALU uses these inputs:
Accumulators
Accumulators A and B store the output from the ALU or the multiplier/adder block. They can
also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder.
Each accumulator is divided into three parts:
Instructions are provided for storing the guard bits, for storing the high- and the low-order
accumulator words in data memory, and for transferring 32-bit accumulator words in or out of
data memory. Also, either of the accumulators can be used as temporary storage for the other.
Barrel Shifter
The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data memory
(using CB or DB), and a 40-bit output connected to the ALU or to data memory (using EB). The
barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the input
data. The shift requirements are defined in the shift count field of the instruction, the shift count
field (ASM) of status register ST1, or in temporary register T (when it is designated as a shift
count register).The barrel shifter and the exponent encoder normalize the values in an
accumulator in a single cycle. The LSBs of the output are filled with 0s, and the MSBs can be
either zero filled or sign extended, depending on the state of the sign-extension mode bit (SXM)
in ST1. Additional shift capabilities enable the processor to perform numerical scaling, bit
extraction, extended arithmetic, and overflow prevention operations.
Multiplier/Adder Unit
implementing symmetrical and LMS filters, which are required for complex DSP algorithms.
These are the some of the important parts of the processor and you are instructed to go through
the detailed architecture once which helps you in developing the optimized code for the required
application.
Code composer studio is used to build and debug embedded real time
software applications. Code composer studio setup establishes the interface that allows code
composer studio to communicate with target board or simulator .all windows (except edit
windows) and all toolbars are dockable within the code composer studio environment. hence we
can move and align a window or toolbar t o any portion of code composer studio main window.
we can also move dockable windows and toolbars out of the code composer studio main window
and place them any where on the desktop. all code composer studio windows contain context
menus. to open a context menu right click with in the window. context menus provide a list of
options and/or commands that can be applied to that particular window.
When program is loaded on to the target r simulator ,the code composer studio
debugger automatically opens a dis-assembly window. the dis-assembly window displays
dis-assembly instructions & symbolic information needed for debugging .for each assembly
language instruction, the dis-assembly window displays dis-assembled instructions. the address
at which the instruction is located, and corresponding opcodes. in addition to this dis-assembled
instructions in dis-assembly window ,the code composer studio debugger enables us to view the
C source code interleaved with dis-assembly code..
We can edit the memory locations’ in any one of the following ways.
1.in the memory window ,double click on the data you which to edit.
Project Records:--
Code composer studio allows to collect execution statistics about the specific areas in the code
which is called profiting.
PROCEDURE:
2.in the setup code composer select functional little Indian,import,save and quit.
7.go to C drive
ti
my projects
name
8.go to project
10. go to C drive.
ti
C600
cgtolls
lib
rts 6700.lib
11.go to C drive
ti
tutorial
disk 6711
Hello.cmd
15.Go to file
Load program
Open the file.in the window displayed the 1 st column we have address of memory and in the 2 nd
column opcodes.
17. view
Graphs
Time/frequency
Convolution and Correlation (auto and cross correlation) of discrete sequences without using
built in functions for convolution and correlation operations.
AIM: To determine the Linear Convolution by writing ‘c’ program using DSP Kit with CCS software.
EQUIPMENT:
Constructor- Simulator
THEORY
In this equation, x1(k), x2 (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 input is shifted in time by a value everytime it is
multiplied with the other input signal. Linear Convolution is quite often used as a method of
implementing filters of various types.
PROCEDURE:-
The following are the steps for the Code Composer Studio:
1. Open Code Composer Studio and make sure DSP kit is Switched ON
2. To create the New Project
Project→ New (File Name. pjt, Eg: Vectors.pjt)
5. To Add run time support library file rts.lib file & linker command file Hello.cmd:
Project→ Add files to Project→ rts6700.lib
CMD file- Which is common for all non real time programs.
6. Compile
To Compile: Project→ Compile
Precautions:
1) Switch ON the computer only after connecting USB cable and make sure the DSP kit is ON.
PROGRAM:
#include<stdio.h>
intx[15],h[15],y[15];
main()
{
inti,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p: \n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for h(n): \n");
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}
Output:
1234
1234
Result:
Thus the Linear Convolution is determined successfully by writing ‘c’ program and using DSP Kit.
AIM: To determine the Circular Convolution by writing ‘c’ program using DSP Kit and using CCS software.
EQUIPMENTS:
Constructor - Simulator
THEORY
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. The
two input signals could have been of varying sample lengths. But we take the DFT of higher point, which ever
signals levels to. For eg. If one of the signal is of length 256 and the other spans 51 samples, then we could only
take 256 point DFT. So the output of IDFT would be containing 256 samples instead of 306 samples, which
follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output
which should have been 306 samples long is fitted into 256 samples. The 256 points end up being a distorted
version of the correct signal. This process is called circular convolution.
PROCEDURE:-
The following are the steps for the Code Composer Studio:
1. Open Code Composer Studio and make sure DSP kit is Switched ON
2. To create the New Project
Project→ New (File Name. pjt, Eg: Vectors.pjt)
5. To Add run time support library file rts.lib file & linker command file Hello.cmd:
Project→ Add files to Project→ rts6700.lib
CMD file- Which is common for all non real time programs.
6. Compile
To Compile: Project→ Compile
Precautions:
1) Switch ON the computer only after connecting USB cable and make sure the DSP kit is ON.
PROGRAM:
#include<stdio.h>
intm,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
OUTPUT:-
Result:
Thus the Circular Convolution is perfomed successfully by writing ‘c’ program and using DSP Kit.
Auto Correlation
Aim: To perform Auto Correlation on signals Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5
Program:
#include<stdio.h>
#include<math.h>
#define PI 3.14
void delay1();
float y[PTS];
void main()
int i,j;
y[i]=0.0;
y[i]=y[i]+x[j]*x[j+i-1];
z[i]=y[i]/(PTS);
//printf("\n%f",z[i]);
float m;
float n;
delay1();
delay1();
delay1();
delay1();
n = (m / fc1);
delay1();
delay1();
if(result == 0)
delay1();
x[no]= sin(n);
delay1();
delay1();
delay1();
void delay1()
int y=150;
while(y!=0)
y--;
To generate graph:
Result:
N-Point FFT
Aim: To perform N-Point FFT on Sequences Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5
Program:
#include<stdio.h>
//#include<conio.h>
#include<math.h>
#define PI 3.14
typedef struct
float real,imag;
}com;
void main()
com xx[8],x[8],temp[8],temp1[8],y[8],a[8],b[8],w[4];
// scanf("%d", &PTS);
printf("\nEnter values==");
for(i=0;i<8;i++)
scanf("%f",&xx[i].real);
scanf("%f",&xx[i].imag);
j=0;
for(i=0;i<8;i=i+2)
x[j].real=xx[i].real;
x[j].imag=xx[i].imag;
x[j+1].real=xx[i+4].real;
x[j+1].imag=xx[i+4].imag;
if(i==2)
i=-1;
j=j+2;
for(i=0;i<4;i++)
w[i].real=cos(2*PI*i/8);
w[i].imag=-sin(2*PI*i/8);
for(i=0;i<8;i=i+2)
temp[i].real=x[i].real+x[i+1].real;
temp[i].imag=x[i].imag+x[i+1].imag;
temp[i+1].real=x[i].real-x[i+1].real;
temp[i+1].imag=x[i].imag-x[i+1].imag;
for(i=2;i<8;i=3*i)
a[i].real=temp[i].real*w[0].real-temp[i].imag*w[0].imag;
a[i].imag=temp[i].real*w[0].imag+temp[i].imag*w[0].real;
a[i+1].real=temp[i+1].real*w[2].real-temp[i+1].imag*w[2].imag;
a[i+1].imag=temp[i+1].real*w[2].imag+temp[i+1].imag*w[2].real;
temp[i].real=a[i].real;
temp[i].imag=a[i].imag;
temp[i+1].real=a[i+1].real;
temp[i+1].imag=a[i+1].imag;
for(i=0;i<6;i++)
temp1[i].real=temp[i].real+temp[i+2].real;
temp1[i].imag=temp[i].imag+temp[i+2].imag;
temp1[i+2].real=temp[i].real-temp[i+2].real;
temp1[i+2].imag=temp[i].imag-temp[i+2].imag;
if(i==1)
i=3;
for(i=4;i<8;i++)
b[i].real=temp1[i].real*w[i-4].real-temp1[i].imag*w[i-4].imag;
b[i].imag=temp1[i].real*w[i-4].imag+temp1[i].imag*w[i-4].real;
temp1[i].real=b[i].real;
temp1[i].imag=b[i].imag;
for(i=0;i<4;i++)
y[i].real=temp1[i].real+temp1[i+4].real;
y[i].imag=temp1[i].imag+temp1[i+4].imag;
y[i+4].real=temp1[i].real-temp1[i+4].real;
y[i+4].imag=temp1[i].imag-temp1[i+4].imag;
printf("\nFFT values==\n");
for(i=0;i<8;i++)
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].imag);
Result:
Aim: To generate Sine wave Using TMS 320 Floating point DSP.
Program:
#include "VSK_6748.h"
#include <math.h>
#define PI 3.14;
int main(void)
int nSamp;
short *sin_out,val;
float tSamp;
double ang;
spi_regs_t *spi=SPIFLASH_SPI0;
spi_regs_t *spi1=SPIFLASH_SPI;
sin_out[count] = sin(ang) * 2048; // store the value in the array of the address of
sinout.
while(1)
Result:
N-Point DFT
Aim: To perform N-Point DFT on Sequences Using TMS 320 Floating point DSP.
Apparatus: PC with CCS V5
Program:
#include<stdio.h>
#include<math.h>
#define pi 3.14
typedef struct {
float real;
float img;
}com;
void main()
com x[50],y[50],temp[50];
int pofd=0,i,k,n;
float WN,c,s,WK;
y[i].real=0.0;
y[i].img=0.0;
scanf("%d",&pofd);
printf("\nEnter the function variables of f(n) to calculate DFT in the complex form (e.g. 3+j4
enter as a 3 4)");
for(i=0;i<pofd;i++)
//scanf("%f%f",&x[i].real,&x[i].img);
scanf("%f",&x[i].real);
scanf("%f",&x[i].img);
WN=(2*pi)/pofd;
for(k=0;k<pofd;k++)
temp[k].real=0.0;
temp[k].img=0.0;
WK=k*WN;
c=cos(WK*n);
s=sin(WK*n);
temp[k].real=temp[k].real+(x[n].real*c)+(x[n].img*s);
temp[k].img=temp[k].img+(x[n].img*c)-(x[n].real*s);
y[k].real=1/sqrt(pofd)*temp[k].real;
y[k].img=1/sqrt(pofd)*temp[k].img;
for(i=0;i<pofd;i++)
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].img);
Result:
FIR LPF
Function Generator
CRO
Program:
#include "VSK_6748.h"
#include <math.h>
int main(void)
spi_regs_t *spi=SPIFLASH_SPI0;
spi_regs_t *spi1=SPIFLASH_SPI;
int N = 40;
float Fc = Fcut/Fsamp;
int *AdcValue;
int *AdcStore;
short AdcOut;
int OutValue,Count,Inc;
float *Hd,*Hm;
float Val;
uint16_t val;
Hd = (float *)0x80010000;
Hm = (float *)0x80011000;
AdcStore[ Count ] = 0;
Hd[ Count ] = 0;
Hm[ Count ] = 0;
if(Count == 0)
Hd[Count] = 2 * Fc;
else
Inc=0;
Hm[Inc] = Hd[Count];
Inc++;
USTIMER_init();
Spi_inti();
while(1)
spi->SPIDAT1 = 0x0000;
val = (uint16_t)spi->SPIBUF;
*AdcStore = val;
val ^= 0x0800;
OutValue = 0;
Result: