Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DSK FEATURES
INSTALLATION PROCEDURE
INTRODUCTON TO CODE COMPOSER STUDIO
PROCEDURE TO WORK ON CCS
EXPERIMENTS USING DSK
1. TO VERIFY LINEAR CONVOLUTION
(ALP USING 6711 INSTRUCTIONS).
2. TO VERIFY CIRCULAR CONVOLUTION.
3. TO DESIGN FIR(LOW PASS/HIGH PASS)USING WINDOWING
TECHNIQUE.
a) USING RECTANGULAR WINDOW
b) USING TRIANGULAR WINDOW
c) USING KAISER WINDOW
4. TO DESIGN IIR FILTER (LP/HP).
5. TO FIND THE FFT OF GIVEN 1-D SIGNAL AND PLOT
6. TO COMPUTE POWER DENSITY SPECTRUM OF A SEQUENCE
7. MINI PROJECT
TI-Solutions
TMS320C6713 DSK
Package Contents
The C6713 DSK builds on TI's industry-leading line of low cost, easy-to-use DSP
Starter Kit (DSK) development boards. The high-performance board features the
TMS320C6713 floating-point DSP. Capable of performing 1350 million floating-point
operations per second (MFLOPS), the C6713 DSP makes the C6713 DSK the most
powerful DSK development board.
The DSK is USB port interfaced platform that allows to efficiently develop and test
applications for the C6713. The DSK consists of a C6713-based printed circuit board that
will serve as a hardware reference design for TIs customers products. With extensive
host PC and target DSP software support, including bundled TI tools, the DSK provides
ease-of-use and capabilities that are attractive to DSP engineers.
The following checklist details items that are shipped with the C6711 DSK kit.
TMS320C6713 DSK
Other hardware
CD-ROM
TI-Solutions
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C76713 DSK provides:
A USB Interface
SDRAM and ROM
An analog interface circuit for Data conversion (AIC)
An I/O port
Embedded JTAG emulation support
Connectors on the C6713 DSK provide DSP external memory interface (EMIF) and
peripheral signals that enable its functionality to be expanded with custom or third party
daughter boards.
The DSK provides a C6713 hardware reference design that can assist you in the
development of your own C6713-based products. In addition to providing a reference for
interfacing the DSP to various types of memories and peripherals, the design also
addresses power, clock, JTAG, and parallel peripheral interfaces.
The C6711 DSK includes a stereo codec. This analog interface circuit (AIC) has the
following characteristics:
High-Performance Stereo Codec
90-dB SNR Multibit Sigma-Delta ADC (A-weighted at 48 kHz)
100-dB SNR Multibit Sigma-Delta DAC (A-weighted at 48 kHz)
1.42 V 3.6 V Core Digital Supply: Compatible With TI C54x DSP Core
Voltages
2.7 V 3.6 V Buffer and Analog Supply: Compatible Both TI C54x DSP
Buffer Voltages
8-kHz 96-kHz Sampling-Frequency Support
Software Control Via TI McBSP-Compatible Multiprotocol Serial Port
I 2 C-Compatible and SPI-Compatible Serial-Port Protocols
Glueless Interface to TI McBSPs
TI-Solutions
TI-Solutions
TI-Solutions
TI-Solutions
NSTALLATION
SYSTEM REQUIREMENTS
Minimum
233MHz or Higher PentiumCompatible CPU
600MB of free hard disk space
128MB of RAM
SVGA (800 x 600 ) display
Internet Explorer (4.0 or later) or
Netscape Navigator (4.7 or later)
Local CD-ROM drive
Recommended
500MHz or Higher Pentium
Compatible CPU
128MB RAM
16bit Color
Windows 98
Windows NT 4.0 Service Pack 4 or higher
Windows 2000 Service Pack 1
Windows Me
Windows XP
TI-Solutions
Test the USB port by running DSK Port test from the start menu
TI-Solutions
TI-Solutions
IDE
Debug IDE
Advanced watch windows
Integrated editor
File I/O, Probe Points, and graphical algorithm scope probes
Advanced graphical signal analysis
Interactive profiling
Automated testing and customization via scripting
Visual project management system
Compile in the background while editing and debugging
Multi-processor debugging
Help on the target DSP
Note :
Documents for Reference:
spru509 Code Composer Studio getting started guide.
spru189 TMS320C6000 CPU & Instruction set guide
spru190 TMS320C6000 Peripherals guide
slws106d codec(TLV320AIC23) Data Manual.
spru402 Programmers Reference Guide.
sprs186j TMS320C6713 DSP
Soft Copy of Documents are available at : c:\ti\docs\pdf.
10
TI-Solutions
11
TI-Solutions
sum.c
# include<stdio.h>
main()
{
int i=0;
i++;
printf("%d",i);
}
To Perform Single Step Debugging:
1. Keep the cursor on the on to the line from where u want to start single step
debugging.(eg: set a break point on to first line int i=0; of your project.)
To set break point select
12
TI-Solutions
LINEAR CONVOLUTION
To Verify Linear Convolution:
Linear Convolution Involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:
x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}
r=
n= 0
1
2
3
0
1
2
x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
x[1]h[0] x[1]h[1] x[1]h[2]
x[2]h[0] x[2]h[1]
x[3]h[0]
x[1]h[3]
x[2]h[2] x[2]h[3]
x[3]h[1] x[3]h[2]
x[3]h[3]
13
Output:
TI-Solutions
conv.asm:
.global _main
X
H
.half 1,2,3,4,0,0,0,0
.half 1,2,3,4,0,0,0,0
.bss
Y,14,2
;input1, M=4
;input2, N=4
;OUTPUT, R=M+N-1
.S1
.S1
.S2
.S2
.S1
.S1
MVK
.S2
X,A4
X,A4
H,B4
H,B4
Y,A5
Y,A5
;POINTER TO X
;POINTER TO H
7,B2
;POINTER TO Y
;R=M+N-1
LL2:
ZERO
.L1
A7
ZERO
.L1
A3
ZERO .L1 A2
ZERO .L1 A8
;I=0
LL1:
[B0]
[A2]
;J=0, for(i=0;i<m+n-1;i++)
LDH
.D1 *A4[A8],A6
MV
.S2X A8,B5
SUB
.L2 A3,B5,B7
LDH
.D2 *B4[B7],B6
NOP 4
MPY
.M1X A6,B6,A7
ADD
.L1 A8,1,A8
ADD
.L1 A2,A7,A2
CMPLT .L2X B5,A3,B0
B
.S2
LL1
NOP 5
; for(j=0;j<=i;j++)
;
y[i]+=x[j]*h[i-j];
STH
.D1 A2,*A5[A3]
ADD
.L1 A3,1,A3
CMPLT .L1X A3,B2,A2
B
.S1 LL2
NOP 5
B
B3
NOP 5
14
TI-Solutions
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name lconv.pjt.
Add the source files conv.asm
to the project using Projectadd files to project pull down menu.
Add the linker command file hello.cmd .
(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.
To View output graphically
Select view graph time and frequency.
Configure the graphical window as shown below
15
TI-Solutions
INPUT
x[n] = {1, 2, 3, 4,0,0,0,0}
h[k] = {1, 2, 3, 4,0,0,0,0}
OUTPUT:
m=4;
/*Lenght of
n=4;
/*Lenght of
i=0,j;
x[10]={1,2,3,4,0,0,0,0};
h[10]={1,2,3,4,0,0,0,0};
16
TI-Solutions
Note:
1. To execute the above program follow procedure to work on code composer
studio
2. To view graphical output follow the above procedure.
Circular Convolution
Steps for Cyclic Convolution
Steps for cyclic convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel"
Steps for Cyclic Convolution
Step1: Plot f[m] and h[m]
Subfigure 1.1
Subfigure 1.2
Step 2: "Spin" h[m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]
(i.e. Simply rotate the sequence, h[n], clockwise by n steps)
Figure 2: Step 2
Step 3: Pointwise multiply the f[m] wheel and the h[nm] wheel. sum=y[n]
Step 4: Repeat for all 0nN1
Example 1: Convolve (n = 4)
Subfigure 3.1
Copyright 2005 CSIL
Subfigure 3.2
17
TI-Solutions
h[m] =
Figure 4
Multiply f[m] and sum to yield: y[0] =3
h[1m]
Figure 5
Multiply f[m] and sum to yield: y[1] =5
h[2m]
Figure 6
Multiply f[m] and sum to yield: y[2] =3
h[3m]
Figure 7
Multiply f[m] and sum to yield: y[3] =1
18
TI-Solutions
OUT PUT
Eg:
x[4]={3, 2, 1,0}
h[4]={1, 1, 0,0}
y[4]={3, 5, 3,0}
19
TI-Solutions
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name cir conv.pjt.
Add the source files Circular Convolution.C
to the project using Projectadd files to project pull down menu.
Add the linker command file hello.cmd .
(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.
20
TI-Solutions
21
TI-Solutions
12. You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec
configuration.
13. You can also pass an audio input and hear the output signal through the speakers.
14. You can also vary the sampling frequency using the DSK6713_AIC23_setFreq
Function in the codec.c file and repeat the above steps.
5.0 Conclusion:
The codec TLV320AIC23 successfully configured using the board support library
and verified.
22
TI-Solutions
codec.c
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */
\
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */
\
0x0043, /* 7 DSK6713_AIC23_DIGIF
Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */
\
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/* main() - Main code routine, initializes BSL and generates tone */
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
/*set codec sampling frequency*/
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
/* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_input));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, l_input));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
23
TI-Solutions
II.
III.
IV.
24
TI-Solutions
25
TI-Solutions
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:
Cutoff -500Hz
float b_kai1[31]={-0.000019,-0.000170,-0.000609,-0.001451,-0.002593,-0.003511,0.003150,0.000000,0.007551,0.020655,0.039383,0.062306,0.086494,0.108031,0.122944,
0.128279,0.122944,0.108031,0.086494,0.062306,0.039383,0.020655,0.007551,0.000000,
-0.003150,-0.003511,-0.002593,-0.001451,-0.000609,-0.000170,-0.000019};
Cutoff -1000Hz
float b_kai2[31]={-0.000035,-0.000234,-0.000454,0.000000,0.001933,0.004838,0.005671,
-0.000000,-0.013596,-0.028462,-0.029370,0.000000,0.064504,0.148863,0.221349,0.249983,
IMPLEMENTATION
OF AN FIR FILTER :
0.221349,0.148863,0.064504,0.000000,-0.029370,-0.028462,-0.013596,-0.000000,0.005671,
0.004838,0.001933,0.000000,-0.000454,-0.000234,
-0.000035};
ALGORITHM
TO IMPLEMENT :
Cutoff
We
need-1500Hz
to realize an advance FIR filter by implementing its difference equation as per
float
b_kai3[31]={-0.000046,-0.000166,0.000246,0.001414,0.001046,-0.003421,-0.007410,
the
specifications.
A direct form I implementation approach is taken. (The filter coefficients
0.000000,0.017764,0.020126,-0.015895,-0.060710,-0.034909,0.105263,0.289209,0.374978,
are
taken as ai as generated by the Matlab program.)
0.289209,0.105263,-0.034909,-0.060710,-0.015895,0.020126,0.017764,0.000000,-0.007410,
-0.003421,0.001046,0.001414,0.000246,-0.000166, -0.000046};
26
TI-Solutions
T.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter
Cutoff -500Hz
float b_tri1[31]={0.000000,-0.001185,-0.003336,-0.005868,-0.007885,-0.008298,-0.005988,
0.000000,0.010265,0.024895,0.043368,0.064545,0.086737,0.107877,0.125747,0.138255,
0.125747,0.107877,0.086737,0.064545,0.043368,0.024895,0.010265,0.000000,-0.005988,
-0.008298,-0.007885,-0.005868,-0.003336,-0.001185,0.000000};
Cutoff -1000Hz
float b_tri2[31]={0.000000,-0.001591,-0.002423,0.000000,0.005728,0.011139,0.010502,
-0.000000,-0.018003,-0.033416,-0.031505,0.000000,0.063010,0.144802,0.220534,0.262448,
0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,-0.018003,-0.000000,0.010502,
0.011139,0.005728,0.000000,-0.002423,-0.001591,0.000000};
Cutoff -1500Hz
float b_tri3[31]={0.000000,-0.001104,0.001287,0.005467,0.003043,-0.007731,-0.013469,
0.000000,0.023089,0.023194,-0.016737,-0.060136,-0.033474,0.100508,0.282844,0.386435,
0.282844,0.100508,-0.033474,-0.060136,-0.016737,0.023194,0.023089,0.000000,-0.013469,
-0.007731,0.003043,0.005467,0.001287,-0.001104,0.000000};
27
TI-Solutions
28
TI-Solutions
29
TI-Solutions
30
TI-Solutions
Initialize Counter = 0
Initialize Output = 0 , i =
0
Output += coeff[Ni]*val[i]
Shift the input value by
one
No
Is the loop
Cnt =
order
Poll the ready bit, when
asserted proceed.
Yes
Output += coeff[0]*data
Put the data in val
array.
31
TI-Solutions
fir.c
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,
0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.000000,
0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,
-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,
0.000000,-0.002423,-0.001591,0.000000 };
static short in_buffer[100];
DSK6713_AIC23_Config config = {\
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume */\
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume*/\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */\
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */\
0x0011, /* 4 DSK6713_AIC23_ANAPATH
Analog audio path control */\
0x0000, /* 5 DSK6713_AIC23_DIGPATH
Digital audio path control */\
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */\
0x0043, /* 7 DSK6713_AIC23_DIGIF
Digital audio interface format */\
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */\
0x0001
/* 9 DSK6713_AIC23_DIGACT
Digital interface activation */
\
};
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{
/* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;
32
TI-Solutions
*/
for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer
*/
for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
PROCEDURE :
Switch on the DSP board.
Open the Code Composer Studio.
Create a new project
Project New (File Name. pjt , Eg: FIR.pjt)
Initialize on board codec.
Kindly refer the Topic Configuration of 6713 Codec using BSL
Add the given above C source file to the current project (remove codec.c source
file from the project if you have already added).
Connect the speaker jack to the input of the CRO.
Build the program.
Load the generated object file(*.out) on to Target board.
Run the program using F5.
Observe the waveform that appears on the CRO screen.
33
TI-Solutions
34
TI-Solutions
35
TI-Solutions
EQUIPMENTS NEEDED:
ALGORITHM TO IMPLEMENT:
We need to realize the Butter worth band pass IIR filter by implementing the difference
equation y[n] = b0x[n] + b1x[n-1]+b2x[n-2]-a1y[n-1]-a2y[n-2] where b0 b2, a0-a2 are feed
forward and feedback word coefficients respectively [Assume 2 nd order of filter].These
coefficients are calculated using MATLAB.A direct form I implementation approach is
taken.
Step 1 - Initialize the McBSP, the DSP board and the on board codec.
Kindly refer the Topic Configuration of 6713Codec using BSL
Step 2 - Initialize the discrete time system , that is , specify the initial conditions.
Generally zero initial conditions are assumed.
Step 3 - Take sampled data from codec while input is fed to DSP kit from the signal
generator. Since Codec is stereo , take average of input data read from left and right
channel . Store sampled data at a memory location.
Step 4 - Perform filter operation using above said difference equation and store
filter Output at a memory location .
Step 5 - Output the value to codec (left channel and right channel) and view the
output at Oscilloscope.
Step 6 - Go to step 3.
36
TI-Solutions
Start
Initialize the DSP Board.
output = x[0]b0+x[-1]b1+
x[-2]b2 - y[-1]a1 - y[-2]a2
x[-1]=x[0]
Poll for ready bit
Write output to analog i/o.
Stop
F.1 : Flowchart for implementing IIR filter.
37
TI-Solutions
38
TI-Solutions
fclose(fid);
winopen('IIR_LP_CHEB Type1.txt');
%%%%%%%%%%%%%%%%%%
figure(1);
[h,w]=freqz(num_bw1,den_bw1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb1,den_cb1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response of Low pass IIR filters (Fc=2500Hz)');
figure(2);
[h,w]=freqz(num_bw2,den_bw2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb2,den_cb2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1 (Ripple: 3dB)');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response in the passband');
axis([0 12000 -20 20]);
Fc=2500Hz
Floating Point
Values
0.044408
0.088815
0.044408
1.000000
-1.412427
0.663336
Fixed Point
Values(Q15)
1455
1455[B1/2]
1455
32767
-23140[A1/2]
21735
Fc=800Hz
Floating Point
Values
0.005147
0.010295
0.005147
1.000000
-1.844881
0.873965
Fixed Point
Values(Q15)
168
168[B1/2]
168
32767
-30225[A1/2]
28637
Fc=8000Hz
Floating Point
Values
0.354544
0.709088
0.354544
1.000000
0.530009
0.473218
Fixed Point
Values(Q15)
11617
11617[B1/2]
11617
32767
8683[A1/2]
15506
Note: We have Multiplied Floating Point Values with 32767(2 15) to get Fixed Point Values.
39
TI-Solutions
Fc=2500Hz
Floating Point
Values
0.072231
0.144462
0.072231
1.000000
-1.109229
0.398152
Fixed Point
Values(Q15)
2366
2366[B1/2]
2366
32767
-18179[A1/2]
13046
Fc=800Hz
Floating Point
Values
0.009526
0.019052
0.009526
1.000000
-1.705552,
0.743655
Fixed Point
Values(Q15)
312
312[B1/2]
312
32767
-27943[A1/2]
24367
Fc=8000Hz
Floating Point
Values
0.465153
0.930306
0.465153
1.000000
0.620204
0.240408
Fixed Point
Values(Q15)
15241
15241[B1/2]
15241
32767
10161[A1/2]
7877
Note: We have Multiplied Floating Point Values with 32767(2 15) to get Fixed Point Values.
Fc=2500Hz
Floating Point
Values
0.388513
-0.777027
0.388513
1.000000
-1.118450
0.645091
Fixed Point
Values(Q15)
12730
-12730[B1/2]
12730
32767
-18324[A1/2]
21137
Fc=4000Hz
Floating Point
Values
0.282850
-0.565700
0.282850
1.000000
-0.451410
0.560534
Fixed Point
Values(Q15)
9268
-9268[B1/2]
9268
32767
-7395[A1/2]
18367
Fc=7000Hz
Floating Point
Values
0.117279
-0.234557
0.117279
1.000000
0.754476
0.588691
Fixed Point
Values(Q15)
3842
-3842[B1/2]
3842
32767
12360[A1/2]
19289
Note: We have Multiplied Floating Point Values with 32767(2 15) to get Fixed Point Values.
Fc=2500Hz
Floating Point
Values
0.626845
-1.253691
0.626845
1.000000
-1.109229
0.398152
Fixed Point
Values(Q15)
20539
-20539[B1/2]
20539
32767
-18173[A1/2]
13046
Fc=4000Hz
Floating Point
Values
0.465153
-0.930306
0.465153
1.000000
-0.620204
0.240408
Fixed Point
Values(Q15)
15241
-15241[B1/2]
15241
32767
-10161[A1/2]
7877
Fc=7000Hz
Floating Point
Values
0.220195
-0.440389
0.220195
1.000000
0.307566
0.188345
Fixed Point
Values(Q15)
7215
-7215[B1/2]
7215
32767
5039[A1/2}
6171
Note: We have Multiplied Floating Point Values with 32767(2 15) to get Fixed Point Values.
40
TI-Solutions
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input, l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
/* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;
/* Send a sample to the left channel */
41
TI-Solutions
( (int)h[0] * x[0]) ;
/* B0 * x(n)
*/
/* B1/2 * x(n-1) */
/* B1/2 * x(n-1) */
/* B2 * x(n-2) */
/* A1/2 * y(n-1) */
/* A1/2 * y(n-1) */
/* A2 * y(n-2) */
/* y(n-2) = y(n-1) */
/* y(n-1) = y(n)
*/
x[2] = x[1];
x[1] = x[0];
/* x(n-2) = x(n-1) */
/* x(n-1) = x(n)
*/
return (temp<<2);
42
TI-Solutions
PROCEDURE :
Switch on the DSP board.
Open the Code Composer Studio.
Create a new project
Project New (File Name. pjt , Eg: FIR.pjt)
Initialize on board codec.
Kindly refer the Topic Configuration of 6713 Codec using BSL
Add the given above C source file to the current project (remove codec.c source
file from the project if you have already added).
Connect the speaker jack to the input of the CRO.
Build the program.
Load the generated object file(*.out) on to Target board.
Run the program using F5.
Observe the waveform that appears on the CRO screen.
43
TI-Solutions
44
TI-Solutions
Twiddle Factor
In the Definition of the DFT, there is a factor called the Twiddle Factor
where N = number of samples.
If we take an 8 bit sample sequence we can represent the twiddle factor as a vector in the
unit circle. e.g.
Note that
1. It is periodic. (i.e. it goes round and round the circle !!)
2. That the vectors are symmetric
3. The vectors are equally spaced around the circle.
45
TI-Solutions
46
TI-Solutions
Shuffled Inputs
The process of decimating the signal in the time domain has caused the INPUT samples
to be re-ordered. For an 8 point signal the original order of the samples is
0, 1, 2, 3, 4, 5, 6, 7
But after decimation the order is
0, 4, 2, 6, 1, 5, 3, 7
At first it may look as if there is no order to this new sequence, BUT if the numbers are
represented as binary a patter soon becomes apparent.
47
TI-Solutions
What has happened is that the bit patterns representing the sample number has been
reversed. This new sequence is the order that the samples enter the FFT.
48
TI-Solutions
//FFT prototype
//as input and output buffer
//intermediate buffer
//general purpose index variable
//number of new samples in
//set to 1 by ISR when iobuffer
//twiddle constants stored in w
//primary working buffer
main()
{
for (i = 0 ; i<PTS ; i++)
// set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle
constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle
constants
}
for (i = 0 ; i < PTS ; i++)
//swap buffers
{
iobuffer[i] = sin(2*PI*10*i/64.0);/*10- > freq,
64 -> sampling freq*/
samples[i].real=0.0;
samples[i].imag=0.0;
}
49
TI-Solutions
FFT(samples,PTS);
//end of main
fft.c:
#define PTS 64
//# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS];
//twiddle constants stored in w
void FFT(COMPLEX *Y, int N)
//input sample array, # of points
{
COMPLEX temp1,temp2;
//temporary storage variables
int i,j,k;
//loop counter variables
int upper_leg, lower_leg;
//index of upper/lower butterfly leg
int leg_diff;
//difference between upper/lower leg
int num_stages = 0;
//number of FFT stages (iterations)
int index, step;
//index/step through twiddle
constant
i = 1;
//log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
//difference between upper&lower legs
step = (PTS*2)/N;
//step between values in twiddle.h
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
Copyright 2005 CSIL
50
TI-Solutions
51
TI-Solutions
Input:
Output:
52
TI-Solutions
HOW TO PROCEED
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name FFT.pjt.
Add the source files FFT256.c and FFT.C in the project using
Projectadd files to project pull down menu.
Add the linker command file hello.cmd
Add the rts file rts6700.lib
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program
pull down menu.
Run the program and observe output using graph utility.
53
TI-Solutions
POWER SPECTRUM
The total or the average power in a signal is often not of as great an interest. We are most
often interested in the PSD or the Power Spectrum. We often want to see is how the
input power has been redistributed by the channel and in this frequency-based
redistribution of power is where most of the interesting information lies. The total area
under the Power Spectrum or PSD is equal to the total avg. power of the signal. The PSD
is an even function of frequency or in other words
To compute PSD:
The value of the auto-correlation function at zero-time equals the total power in the signal.
To compute PSD We compute the auto-correlation of the signal and then take its FFT.
The auto-correlation function and PSD are a Fourier transform pair. (Another estimation
method called period gram uses sampled FFT to compute the PSD.)
E.g.: For a process x(n) correlation is defined as:
R ( ) E{x (n ) x (n )}
lim
1
N
x ( n) x ( n )
n 1
S ( ) FT ( R ( )) lim
R ( ) FT 1 ( S ( ))
N 1
1
2
R ( )e j
N 1
S ( )e
54
TI-Solutions
55
TI-Solutions
PSD.c:
/*************************************************************
* FILENAME
* Non_real_time_PSD.c
* DESCRIPTION
* Program to Compute Non real time PSD
* using the TMS320C6711 DSK.
***************************************************************
* DESCRIPTION
*
Number of points for FFT (PTS)
*
x --> Sine Wave Co-Efficients
*
iobuffer --> Out put of Auto Correlation.
*
x1 --> use in graph window to view PSD
/*===========================================================*/
#include <math.h>
#define PTS 128
#define PI 3.14159265358979
//FFT prototype
//as input and output buffer
//intermediate buffer
//general purpose index variable
//number of new samples in iobuffer
//set to 1 by ISR when iobuffer full
//twiddle constants stored in w
//primary working buffer
main()
{
float j,sum=0.0 ;
int n,k,i,a;
for (i = 0 ; i<PTS ; i++)
// set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0));
/*Re component of twiddle constants*/
w[i].imag =-sin(2*PI*i/(PTS*2.0));
/*Im component of twiddle constants*/
}
/****************Input Signal X(n)
for(i=0,j=0;i<PTS;i++)
{ x[i] = sin(2*PI*5*i/PTS);
// Signal
*************************/
x(Fs)=sin(2*pi*f*i/Fs);
56
TI-Solutions
samples[i].real=0.0;
samples[i].imag=0.0;
}
/********************Auto Correlation of X(n)=R(t) ***********/
for(n=0;n<PTS;n++)
sum=0;
for(k=0;k<PTS-n;k++)
{
sum=sum+(x[k]*x[n+k]);
}
iobuffer[n] = sum;
}
/********************** FFT of R(t) ***********************/
for (i = 0 ; i < PTS ; i++)
//swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0;
//imag components = 0
FFT(samples,PTS);
//end of main
FFT.c:
#define PTS 128
57
TI-Solutions
int num_stages = 0;
//number of FFT stages (iterations)
int index, step;
//index/step through twiddle constant
i = 1;
//log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
//difference between upper&lower legs
step = (PTS*2)/N;
//step between values in twiddle.h// 512
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++)
//bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
58
TI-Solutions
HOW TO PROCEED
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name PSD.pjt.
Add the source files PSD.c and FFT.c in the project using
Projectadd files to project pull down menu.
Add the linker command file hello.cmd .
Add the rts file rts6700.lib
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program
pull down menu.
Run the program and observe output using graph utility.
OUT PUT:
59
TI-Solutions
60
TI-Solutions
MINI PROJECT
(DISCRETE COSINE TRANSFORM)
Copyright 2005 CSIL
61
TI-Solutions
The input image is N2 pixels wide by N1 pixels high; A(i,j) is the intensity of the pixel in
row i and column j; B(k1,k2) is the DCT coefficient in row k1 and column k2 of the DCT
matrix. All DCT multiplications are real. This lowers the number of required multiplications,
as compared to the discrete Fourier transform. The DCT input is an 8 by 8 array of
integers. This array contains each pixel's gray scale level; 8 bit pixels have levels from 0
to 255. The output array of DCT coefficients contains integers; these can range from
Copyright 2005 CSIL
62
TI-Solutions
-1024 to 1023. For most images, much of the signal energy lies at low frequencies; these
appear in the upper left corner of the DCT. The lower right values represent higher
frequencies, and are often small - small enough to be neglected with little visible
distortion.
IMPLEMENTATION OF DCT
DCT-based codecs use a two-dimensional version of the transform.
The 2-D DCT and its inverse (IDCT) of an N x N block are shown below:
2-D DCT:
N 1 N 1
2
(2 x 1)u
(2 y 1)v
F (u , v) C (u )C (v) f ( x, y ) cos[
] cos[
]
N
2
N
2
N
y 0 x 0
2-D IDCT:
2
f ( x, y )
N
N 1 N 1
(2 x 1)u
(2 y 1)v
] cos[
]
2N
2N
One of the properties of the 2-D DCT is that it is separable meaning that it can be
separated into a pair of 1-D DCTs. To obtain the 2-D DCT of a block a 1-D DCT is
first performed on the rows of the block then a 1-D DCT is performed on the
columns of the resulting block.
The same applies to the IDCT.
This process is illustrated below.
63
TI-Solutions
64
TI-Solutions
Note that the values in the decimal format does not include the factor
[Sqrt(2/n)=>sqrt(2/8)=>1/2]. The reason for this is that dividing the coefficients by 2 before
converting to Q12 may result in some loss in precision. More precision can be obtained
by ignoring this division and then multiplying by 2 11 (instead of 212 ) to convert to Q12. The
reason for using Q12 instead of Q15 (as one would expect) is as follows. Referring to
Equation [3], we notice that the DCT calculation involves a summation of N terms.
Looking at the DCT coefficients in Figure 1, we observe that the terms entering in the
summation may be close to 1. Thus, such summation may cause overflows. To avoid this,
each term must be scaled down by 1/N. For N=8, this can be achieved by working in Q12
format instead of Q15 format.
65
TI-Solutions
HOW TO PROCEED:
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name image.pjt.
From the File Menu new DSP/BIOS Configuration select dsk6713.cdb
and save it as image1.cdb and add it to the project.
Add the source files main.c ,dct.c and idct.c in the project using
Projectadd files to project pull down menu.
Add the linker command file MY_LNK_CMD.cmd to your project
Copy the header files scenary.h and dct.h and paste it in your project folder.
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program
pull down menu.
Run the program and observe output using image utility.
66
TI-Solutions
Main.c:
#include
#include
#include
#include
array */
<stdio.h>
<stdlib.h>
"dct.h"
"scenary.h"
coefficient x 2^12 ) */
4096,
1130,
-5352,
-3218,
4096,
4816,
-2217,
-5681,
4096,
-1130,
-5352,
3218,
4096,
-4816,
-2217,
5681,
4096,
-3218,
-2217,
5681,
-4096,
-1130,
5352,
-4816,
4096,
-4816,
2217,
1130,
-4096,
5681,
-5352,
3218,
4096,
-5681,
5352,
-4816,
4096,
-3218,
2217,
-1130
67
TI-Solutions
Quick
/* Wait */
dct.c:
/*********************************************************************/
/* dct.c Function to perform a 8 point 2D DCT
*/
/* DCT is performed using direct matrix multiplication
*/
/*********************************************************************/
#include "dct.h"
extern
extern
extern
extern
void dct(void)
{
int i,j,x,y;
int value[8];
/* Perform 1D DCT on the columns */
for(j=0;j<8;j++)
{
for(y=0;y<8;++y)
{
value[y]=0;
for(x=0;x<8;++x)
{
value[y] += (int)(coe[y][x]*block[j+(x*8)]);
}
}
for(y=0;y<8;++y)
{
block[j+(y*8)] = (short)(value[y]>>12);
}
}
68
TI-Solutions
idct.c:
/*********************************************************************/
/* idct.c performs a 8 point 2D Inverse DCT function
*/
/*********************************************************************/
#include "dct.h"
extern
extern
extern
extern
void idct(void)
{
int i,j,x,y;
int value[8];
/* Perform 1D IDCT on the columns */
for(j=0;j<8;j++)
{
for(y=0;y<8;++y)
{
value[y] = 0;
for(x=0;x<8;++x)
{
value[y] += (int)(coe[x][y]*block[j+(x*8)]);
}
}
for(y=0;y<8;++y)
{
block[j+(y*8)] = (short)(value[y]>>12);
}
}
69
TI-Solutions
for(y=0;y<8;++y)
{
block[i+y] = (short)(value[y]>>15);
}
MY_LNK_CMD.cmd:
-l imagecfg.cmd
SECTIONS
{
mydata
mycode
ext_sdram
>
>
>
SDRAM
SDRAM
SDRAM
70
TI-Solutions
image_in:
image_out:
71