Documente Academic
Documente Profesional
Documente Cultură
USER MANUAL
Cranes Software International Limited
(TI-Solutions)
#5, Airport Road, Domlur Layout, Bangalore 560 071.
Phone: 080 51254131/ 2/ 3/ 4, Fax: 080 - 25356299.
tisales@cranessoftware.com
TI-Solutions
CONTENTS
! DSK FEATURES
! INSTALLATION PROCEDURE
! INTRODUCTON TO CODE COMPOSER STUDIO
! PROCEDURE TO WORK ON CCS
! EXPERIMENTS USING DSK
1. SOLUTION OF DIFFERENCE EQUATIONS
2. IMPULSE RESPONSE
3. TO VERIFY LINEAR CONVOLUTION
4. TO VERIFY CIRCULAR CONVOLUTION.
5. PROCEDURE TO WORK IN REALTIME.
6. TO DESIGN FIR(LOW PASS/HIGH PASS)USING WINDOWING
TECHNIQUE.
a) USING RECTANGULAR WINDOW
b) USING TRIANGULAR WINDOW
c) USING KAISER WINDOW
7. TO DESIGN IIR FILTER (LP/HP).
8. NOISE CANCELLATION USING ADAPTIVE FILTERS.
9. TO PLOT SPECTROGRAM OF A SIGNAL OR SPEECH.
10. TO FIND THE FFT OF GIVEN 1-D SIGNAL AND PLOT
11. TO COMPUTE POWER DENSITY SPECTRUM OF A SEQUENCE
12. 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
TI-Solutions
The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of
code with Code Composer Studio. The C6713 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 C6713 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
INSTALLATION
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
SOFTWARE INSTALLATION
You must install the hardware before you install the software on your system.
The requirements for the operating platform are;
10
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
11
TI-Solutions
Type the code (Save & give a name to file, Eg: sum.c).
12
TI-Solutions
13
TI-Solutions
5. To Compile:
Project $ Compile File
6. To build or Link:
Project $ build,
Which will create the final executable (.out) file.(Eg. sum.out).
7. Procedure to Load and Run program:
Load program to DSK:
File $ Load program $ sum. out
8. To execute project:
Debug $ Run.
14
TI-Solutions
sum.c
#include<stdio.h>
main()
{
int i=30,j=40,k;
k=i+j;
printf("%d",k);
}
15
TI-Solutions
DIFFERENCE EQUATION
An Nth order linear constant coefficient difference equation can be represented as
N
M
ak y(n-k) =
k=0
br x(n-r)
r=0
If we assume that the system is causal a linear difference equation provides an explicit
relationship between the input and output..this can be seen by rewriting above equation.
M
y(n) =
ak/a0 y y(n-k)
k=1
16
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 DIFF EQ1.c
to the project using Project$
$add 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.
17
TI-Solutions
Note: To verify the Diffence Equation , Observe the output for high
frequency and low frequency by changing variable FREQ
in the program.
18
TI-Solutions
IMPULSE RESPONSE
C Program to Implement Impulse response:
#include <stdio.h>
#define Order 2
#define Len
10
float y[Len]={0,0,0},sum;
main()
{
int j,k;
float a[Order+1]={0.1311, 0.2622, 0.1311};
float b[Order+1]={1, -0.7478, 0.2722};
for(j=0;j<Len;j++)
{
sum=0;
for(k=1;k<=Order;k++)
{
if((j-k)>=0)
sum=sum+(b[k]*y[j-k]);
}
if(j<=Order)
{
y[j]=a[j]-sum;
}
else
{
y[j]=-sum;
}
printf("Respose[%d] = %f\n",j,y[j]);
}
}
19
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]
Output:
x[1]h[3]
x[2]h[2] x[2]h[3]
x[3]h[1] x[3]h[2]
x[3]h[3]
20
TI-Solutions
int x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0};
int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0};
efficients*/
int y[LENGHT1+LENGHT2-1];
main()
{
int i=0,j;
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
printf("%d\n",y[i]);
}
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.c
" to the project using Project$add 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.
21
TI-Solutions
" 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.
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
7,B2
;POINTER TO X
;POINTER TO H
;POINTER TO Y
;R=M+N-1
.L1
A7
ZERO
.L1
A3
;I=0
LL2:
ZERO .L1 A2
ZERO .L1 A8
;J=0, for(i=0;i<m+n-1;i++)
LL1:
[B0]
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
STH
.D1
; for(j=0;j<=i;j++)
;
y[i]+=x[j]*h[i-j];
A2,*A5[A3]
22
ADD
[A2]
TI-Solutions
.L1 A3,1,A3
CMPLT .L1X A3,B2,A2
B
.S1 LL2
NOP 5
B
B3
NOP 5
23
TI-Solutions
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
Subfigure 3.2
Figure 3: Two discrete-time signals to be
convolved.
24
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
25
TI-Solutions
OUT PUT
x[4]={3, 2, 1,0}
h[4]={1, 1, 0,0}
y[4]={3, 5, 3,0}
26
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 Project$add 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.
27
TI-Solutions
28
TI-Solutions
29
TI-Solutions
codec.c
#include "xyzcfg.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);
}
30
TI-Solutions
II.
III.
IV.
31
TI-Solutions
32
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 -1500Hz
We need 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};
33
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};
34
TI-Solutions
35
TI-Solutions
36
TI-Solutions
37
TI-Solutions
Initialize Counter = 0
Initialize Output = 0 , i = 0
Output += coeff[N-i]*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.
38
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);
39
TI-Solutions
r_output=l_output;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x;
*/
for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer
*/
for(i=0;i<31;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.
Note: 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
" Observe the waveform that appears on the CRO screen.
" Vary the frequency on function generator to see the response of filter.
40
TI-Solutions
41
TI-Solutions
42
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 2nd 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.
43
TI-Solutions
Start
output = x[0]b0+x[-1]b1+
x[-2]b2 - y[-1]a1 - y[-2]a2
x[-1]=x[0]
P ll f
d bit
Write output to analog i/o.
Stop
F.1 : Flowchart for implementing IIR filter.
44
TI-Solutions
45
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
15
Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values.
46
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
15
Note: We have Multiplied Floating Point Values with 32767(2 ) 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
15
Note: We have Multiplied Floating Point Values with 32767(2 ) 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
15
Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values.
47
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 */
48
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)
*/
49
TI-Solutions
PROCEDURE :
" Switch on the DSP board.
" Open the Code Composer Studio.
" Create a new project
Project $ New (File Name. pjt , Eg: IIR.pjt)
" Initialize on board codec.
Note: 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
" Observe the waveform that appears on the CRO screen.
Vary the frequency on function generator to see the response of filter
50
TI-Solutions
51
TI-Solutions
Adaptive Filters
52
TI-Solutions
53
TI-Solutions
54
TI-Solutions
55
TI-Solutions
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input;
int 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 */
56
TI-Solutions
while (!DSK6713_AIC23_read(hCodec,&l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(short int)adaptive_filter(l_input,r_input);
r_output=l_output;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}
output=((short)E);
//output=((short)dplusn);//output (desired+noise)
//overall output result
return(output);
}
57
TI-Solutions
PROCEDURE :
" Switch on the DSP board.
" Open the Code Composer Studio.
" Create a new project
Project $ New (File Name. pjt , Eg: noisecancellation.pjt)
" Initialize on board codec.
Note: Kindly refer the Topic Configuration of 6713 Codec using BSL
" Add the above C source file to the current project (remove codec.c source file
from the project if you have already added).
" Desired Signal $ 400 Hz
Noise $ 3.0 KHz
Input a desired sinusoidal signal into the Left channel and Noise signal of 3KHz
into the Right channel
" Build the project.
" Load the generated object file(*.out) on to Target board.
" Run the program.
" Observe the waveform that appears on the CRO screen. Verify that the 3 KHz
noise signal is being cancelled gradually.
58
TI-Solutions
SPECTROGRAM
59
TI-Solutions
60
TI-Solutions
Spectrogram_rtdx_mtl.c
Time-Frequency
signals Using RTDX-MATLAB
analysis
#include "dsk6713_aic23.h"
file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;
#include <rtdx.h>
support file
#include <math.h>
#include "hamming.cof"
coefficients
#define PTS 256
FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);
float iobuffer[PTS],iobuffer1[PTS],a[PTS];
//input and output buffer
float x1[PTS];
short i;
purpose index variable
int j, k,l, curr_block = 0;
short buffercount = 0;
iobuffer
short flag = 0;
iobuffer full
COMPLEX w[PTS];
stored in w
COMPLEX samples[PTS];
RTDX_CreateOutputChannel(ochan);
C6x->PC
//codec-DSK support
main()
{
for (i = 0 ; i<PTS ; i++)
constants in w
{
w[i].real = cos(2*PI*i/512.0);
constants
w[i].imag =-sin(2*PI*i/512.0);
constants
}
comm_intr();
McBSP
while(!RTDX_isOutputEnabled(&ochan))
puts("\n\n Waiting . . . ");
for(l=0;l<256;l++)
a[l]=cos(2*3.14*1500*l/8000);
for(k=0;k<5000;k++)
//infinite loop
{
while (flag == 0) ;
flag = 0;
for (i = 0 ; i < PTS ; i++)
{ iobuffer1[i]=iobuffer[i]+a[i];
of
//Hamming
//#
window
of
points
for
//FFT prototype
//intermediate buffer
//general
//index variables
//number of new
//set
to
samples
by
//twiddle
ISR
in
when
constants
//set
up
twiddle
//Re
component
of
twiddle
//Im
component
of
twiddle
//init
DSK,
codec,
61
samples[i].real=h[i]*iobuffer1[i];
TI-Solutions
//multiply
by
Hamming
window
coeffs
iobuffer1[i] = x1[i];
//process frame to iobuffer
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0;
//imag components = 0
FFT(samples,PTS);
//call C-coded FFT function
for (i = 0 ; i < PTS ; i++)
//compute
square
of
FFT
magnitude
{
x1[i] = (samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/16; //FFT data scaling
}
RTDX_write(&ochan, x1, sizeof(x1)/2); //send 128 samples to PC
}
//end of infinite loop
}
//end of main
interrupt void c_int11()
//ISR
{
output_sample((short)(iobuffer[buffercount]));
//out from iobuffer
iobuffer[buffercount++]=(short)(input_sample()); //input to iobuffer
if (buffercount >= PTS)
iobuffer full
{
buffercount = 0;
//reinit buffercount
flag = 1;
//reset flag
}
}
FFT.c
//if
62
TI-Solutions
63
TI-Solutions
%board info
cc=ccsdsp('boardnum',0);
reset(cc);
%reset board
visible(cc,1);
enable(cc.rtdx);
%enable RTDX
if ~isenabled(cc.rtdx);
error('RTDX is not enabled')
end
cc.rtdx.set('timeout',50);
open(cc,'spectrogram1.pjt');
load(cc,'./debug/spectrogram1.out');
run(cc);
%run program
configure(cc.rtdx,2048,1);
open(cc.rtdx,'ochan','r');
pause(3)
enable(cc.rtdx,'ochan');
isenabled(cc.rtdx,'ochan');
M = 256;
%window size
N = round(M/2);
B = 128;
fs = 8000;
%sampling rate
t=(1:B)*(M/fs);
f=((0:(M-1)/2)/(M-1))*fs;
64
TI-Solutions
set(gcf,'DoubleBuffer','on');
y = ones(N,B);
column = 1;
set(gca,'NextPlot','add');
axes_handle = get(gcf,'CurrentAxes');
set(get(axes_handle,'XLabel'),'String','Time (s)');
set(get(axes_handle,'YLabel'),'String','Frequency (Hz)');
set(get(axes_handle,'Title'),'String','\fontname{times}\bf
Spectrogram');
Real-Time
set(gca,'XLim', [0 4.096]);
set(gca,'YLim', [0 4000]);
set(gca,'XLimMode','manual');
set(gca,'YLimMode','manual');
for i = 1:32768
w=readmsg(cc.rtdx,'ochan','single');
w=double(w(1:N));
y(:, column) = w';
imagesc(t,f,dB(y));
%plot spectrogram
column = mod(column, B) + 1;
end
halt(cc);
%halt processor
close(cc.rtdx,'ochan');
%close channel
clear cc
%clear object
65
TI-Solutions
Procedure:
15. Create a new project with name spectrogram.pjt.
16. Open spectrogram.cdb from given CD and save it in your new
project folder.
17. Copy the following files from the CD to your new project folder
1) c6713dskinit . c
2) FFT.c
3) spectrogram_rtdx_mtl.c
4) c6713dskinit . h
5) hamming.cof
6) spectrogram_RTDX.m
18. Add spectrogram.cdb, c6713dskinit.c and spectrogram_rtdx_mtl.c to the
current project.
19. Add the library file dsk6713bsl.lib to the current project
Path $ C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib
5. Set the following compiler options.
Select Project $ Build options.
Select the following for compiler option with Basic ( for category):
(1) c671x{mv6710} (for target version)
(2) Full symbolic debug (for Generate Debug info)
(3) Speed most critical(for Opt Speed vs. Size)
(4) None (for Opt Level and Program Level Opt)
Select The Preprocessor Category and Type for Define Symbols{d}:
CHIP_6713, and from Feedback category, select for Interlisting:
OPT / C and ASM{-s}
6. Open spectrogram.cdb, select Input/Output $RTDX , Right-click on properties
and change RTDX buffer size to 8200. Within CCS, select Tools $ RTDX $
configure to set the host buffer size to 2048 (from1024).
7. Build project.
7. Close CCS
8. Open MATLAB and Run spectrogram_RTDX.m . within MATLAB ,CCS will
enable RTDX and will load and run the COFF(.out) executable file. Then
MATLAB will plot the spectrogram of an input signal .
66
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.
67
TI-Solutions
68
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.
69
TI-Solutions
70
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
}
71
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++)
{
72
TI-Solutions
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;
}
73
TI-Solutions
Input:
Output:
74
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
Project$add 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.
75
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 ( ) = F T ( R ( )) = lim
R ( ) = F T
( S ( )) =
R ( ) e j
= N +1
1
2
S ( ) e
76
TI-Solutions
77
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
samples[i].real=0.0;
*************************/
x(Fs)=sin(2*pi*f*i/Fs);
78
TI-Solutions
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
79
TI-Solutions
80
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
Project$add 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:
81
TI-Solutions
82
TI-Solutions
MINI PROJECT
(DISCRETE COSINE TRANSFORM)
83
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 -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.
84
TI-Solutions
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 y + 1)v
2
( 2 x + 1)u
]
F (u , v ) = C (u )C (v ) f ( x, y ) cos[
] cos[
N
N
2
N
2
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.
85
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 211 (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.
86
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
Project$add 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.
87
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
void main()
{
int i,x;
/* Perform block by block processing */
for(i=0;i<IMAGE_SIZE;i+=BLOCK_SIZE)
{
/* Get the block from the input image */
for(x=0;x<BLOCK_SIZE;++x)
{
block[x] = (short) image_in[i+x];
}
/* Perform DCT on this block */
dct();
/* Perform IDCT on this block */
idct();
88
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)
{
89
TI-Solutions
block[j+(y*8)] = (short)(value[y]>>12);
}
}
/* Perform 1D DCT on the resulting rows */
for(i=0;i<64;i+=8)
{
for(y=0;y<8;++y)
{
value[y] = 0;
for(x=0;x<8;++x)
{
value[y] += (int)(coe[y][x]*block[i+x]);
}
}
for(y=0;y<8;++y)
{
block[i+y] = (short)(value[y]>>15);
}
}
}
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)
{
90
TI-Solutions
block[j+(y*8)] = (short)(value[y]>>12);
}
}
/* Perform 1D IDCT on the resulting rows */
for(i=0;i<64;i+=8)
{
for(y=0;y<8;++y)
{
value[y] = 0;
for(x=0;x<8;++x)
{
value[y] += (int)(coe[x][y]*block[i+x]);
}
}
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
91
TI-Solutions
image_in:
image_out:
92