You are on page 1of 96

ĐẠI HỌC BÁCH KHOA HÀ NỘI

TRƯỜNG ĐIỆN - ĐIỆN TỬ


TRUNG TÂM ĐÀO TẠO THỰC HÀNH ĐIỆN – ĐIỆN TỬ

TÀI LIỆU BÁO CÁO KẾT QUẢ THÍ NGHIỆM


XỬ LÝ TÍN HIỆU SỐ – ET4020

Họ và tên

MSSV

Lớp - khóa

Mã lớp thí nghiệm

Tên lớp thí nghiệm


Hà Nội, 2022

MỤC LỤC
BÀI 1: UNIT 1 - DSP TRAINER FAMILIARIZATION...........................................................3
1.1. EX1: DSP Trainer Familiarization................................................................................................................... 3
1.2. EX2: Overview of the DSP Circuit Board........................................................................................................ 3
1.2.1. Discussion: Overview of the DSP Circuit Board..............................................................................................3
1.2.2. Procedure: Overview of the DSP Circuit Board..............................................................................................3
1.2.3. Review Questions..........................................................................................................................................6
1.3. EX3: Integrated Development Environment (IDE) and Project Structure........................................................7
1.3.1. Integrated Development Environment (IDE) and Project Structure: Discussion............................................7
1.3.2. Procedure: Integrated Development Environment (IDE) and Project Structure............................................7
Editing Memory and Registers.....................................................................................................................12
1.3.3. Review Questions........................................................................................................................................13
1.4. Unit Test..................................................................................................................................................... 14

BÀI 2: UNIT 2 - ARCHITECTURE..........................................................................................17


2.1. Architecture: Fundamentals........................................................................................................................ 17
2.2. EX01: Processor Arithmetic......................................................................................................................... 17
2.2.1. Discussion: Processor Arithmetic.................................................................................................................17
2.2.2. Procedure: Processor Arithmetic.................................................................................................................17
Converting a Signed Fractional Number to Q14-Format..............................................................................17
Converting a Binary Number to a Decimal Value.........................................................................................18
Comparing the Multiplication of Integers to the Multiplication of Floats on a Fixed-point DSP..................22
2.2.3. Review Questions........................................................................................................................................23
2.3. EX02: Data Computation Unit..................................................................................................................... 24
2.3.1. Discussion: Data Computation Unit.............................................................................................................24
2.3.2. Procedure: Data Computation Unit.............................................................................................................24
Set Up of the DSP Board...............................................................................................................................24
Overflow, Saturation Mode and Carry Bit....................................................................................................27
2.3.3. Review Questions........................................................................................................................................30
2.4. EX03: Memory............................................................................................................................................ 31
2.4.1. Discussion: Memory.....................................................................................................................................31
2.4.2. Procedure: Memory.....................................................................................................................................31
Set Up and Connections of the DSP Board...................................................................................................31
Testing the Program.....................................................................................................................................32
2.4.3. Review Questions........................................................................................................................................37
2.5. EX04: Addressing........................................................................................................................................ 38
2.5.1. Discussion: Addressing.................................................................................................................................38
2.5.2. Procedure: Addressing.................................................................................................................................38
Set Up and Connections of the DSP Board...................................................................................................39
2.5.3. Review Questions........................................................................................................................................44
2.6. Unit Test..................................................................................................................................................... 45

1
BÀI 3: I/O AND PERIPHERALS..............................................................................................48
3.1. I/O and Peripherals: Fundamentals............................................................................................................. 48
3.2. EX01: An Application Using I/Os and Peripherals.........................................................................................48
3.2.1. Discussion: An Application Using I/Os and Peripherals................................................................................48
3.2.2. Procedure: An Application Using I/Os and Peripherals................................................................................48
Set Up and Connections of the DSP Board...................................................................................................48
Peripheral Registers.....................................................................................................................................49
3.2.3. Review Questions........................................................................................................................................50
3.3. Unit Test..................................................................................................................................................... 51

BÀI 4: DSP REAL-TIME PROCESSING................................................................................54


4.1. DSP Real-time Processing: Fundamentals.................................................................................................... 54
4.2. EX01: Sampling and Analog-to-Digital/Digital-to-Analog Conversion...........................................................54
4.2.1. Discussion: Sampling and Analog-to-Digital/Digital-to-Analog Conversion..................................................54
4.2.2. Procedure: Sampling and Analog-to-Digital/Digital-to-Analog Conversion..................................................54
The Sampling Application Used in This Exercise...........................................................................................54
4.2.3. Review Questions........................................................................................................................................63
4.3. EX02: The FFT and Optimizing DSP Applications..........................................................................................64
4.3.1. Discussion: The FFT and Optimizing DSP Applications.................................................................................64
4.3.2. Procedure: The FFT and Optimizing DSP Applications.................................................................................65
The FFT Application Used in the Exercise.....................................................................................................65
4.3.3. Review Questions........................................................................................................................................76
4.4. Unit Test..................................................................................................................................................... 78

BÀI 5:............................................................................................................................................79
5.1. Signal Processing Applications: Fundamentals............................................................................................. 79
5.2. EX01: Applications - FIR and IIR Filters......................................................................................................... 79
5.2.1. Discussion: Applications - FIR and IIR Filters................................................................................................79
5.2.2. Procedure: Applications - FIR and IIR Filters................................................................................................79
5.2.3. Review Questions........................................................................................................................................79
5.3. Unit Test..................................................................................................................................................... 79

GIỚI THIỆU
Tài liệu này ghi nhận các kết quả thí nghiệm của sinh viên dựa trên quá trình làm
việc thực tế với bo mạch và các thiết bị thí nghiệm.

2
BÀI 1: UNIT 1 - DSP Trainer Familiarization
1.1. EX1: DSP Trainer Familiarization
o DSP Trainer Familiarization: Introduction
o Types of Microprocessors
o Peculiarities of DSPs
o Program Execution

1.2. EX2: Overview of the DSP Circuit Board

1.2.1. Discussion: Overview of the DSP Circuit Board


o Discussion
o The Accessories Section
o The DSP and its Peripherals Section

1.2.2. Procedure: Overview of the DSP Circuit Board


In this section, you will begin to familiarize yourself with some of the components
and circuit blocks found on the digital signal processor circuit board.
 1. Locate, on the digital signal processor circuit board, all the common terminals.
With the power OFF and using an ohmmeter, verify if the common terminals are
connected together. Are all the common terminals connected together?:
a..................................................................................................................yes
b..................................................................................................................no
Choose Answer:A

 2. Turn the power supply ON to power the circuit board.


 3. Using a dc voltmeter, measure the voltage range at the output of the dc source
circuit block. To do so, vary the potentiometer of the dc source from its smallest to
its largest values. What is the minimum voltage and maximum voiltage:
Vmin(V)= -0.8

Vmax(V)=0.9

 4. Connect a microphone to the input of the microphone pre-amplifier and connect


the output of the pre-amplifier to the input of the audio amplifier. Note: “You can
also use earphones if you are in an area where an audio output from the speaker is
not desirable.
3
 5. While talking into the microphone, familiarize yourself with the use of the
potentiometers of the microphone pre-amplifier and of the audio amplifier blocks.
 6. Remove all the connections (leads) present on the circuit board

Familiarization with the Circuit Board Using a DSP Program


In this section, you will familiarize yourself with the development environment
and you will load and run a program on the DSP.
 7. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 8. Make exercise_1_1 the active project simply by clicking on that project in the
Project Explorer window. Launch the Debug mode by clicking the icon to load
the program into the DSP. Next, press the icon in the menu where the debug
icon was in order to run the program. At this point, you should see the following
information on the LCD of the DSP circuit board: LabVolt 91031 Ex1-1 Echo
Generator.
 9. Perform the connections shown.
 10. Adjust the DIP switch of the I/O interface so that every bit is in the 0 position.
Press the interrupt button so that the LCD displays an Echo Delay 0ms.
 11. Using the microphone, input a signal (your voice) into the DSP. Adjust the GAIN
potentiometers of the pre-amplifier and of the audio amplifier to obtain a good
quality of sound at the output. Experiment with the potentiometers. Note that a
series of black rectangles light up on the last line of the LCD as you talk into the
microphone. The length of that line corresponds to the magnitude of the input
signal from the microphone pre-amplifier. The program you downloaded into the
DSP takes the input from the CODEC (which you connected to the microphone
pre-amplifier), displays its amplitude on the LCD, and processes the signal which
is then sent to the output of the CODEC (connected to the speaker/headphones).
 12. Adjust the DIP switch such that the 8-bit number sent to the DSP corresponds to
15 (or 0000 1111<sub>b</sub>, that is, 0000 111 in binary). Set the switches
corresponding to a one (1) to the I position. Press the interrupt button so that
the LCD displays an Echo Delay 15ms. Notice the effect of the signal processing
on the sound of your voice.
 13. Repeat the last step with the following DIP switch values:
031 (0001 1111)
063 (0011 1111)
127 (0111 1111)

4
255 (1111 1111)
The echo effect should be quite obvious. The echo delay corresponds to the time
(in milliseconds) between consecutive echoes.
What is the minimal time required for your brain to perceive distinct repetitions?
a..................................................................................................................Ty
pically 5 to 15 ms
b..................................................................................................................Ty
pically 20 to 80 ms
c..................................................................................................................Ty
pically 100 to 160 ms
d..................................................................................................................Ty
pically 180 to 300 ms
Choose Answer:B

 14. Click on the icon (next to the Run icon) to terminate the execution of the
program.

Using a second application


In this section, you will experiment with a different program using the same
connections.
 15. Make exercise_1_1b the active project simply by clicking on that project in the
Project Explorer window. Launch the Debug mode by clicking the icon to load
the program into the DSP. Next, press the to run the program. At this point, you
should see the following information on the LCD of the DSP circuit board:
LabVolt 91031 Ex1-1b Echo/Flanger Generator.
 16. Experiment with this application. Press the and interrupt buttons and
modify the value of the DIP switch. Speak in the microphone or use a sound
signal. What is the function of pressing the interrupt button in this
application?
a..................................................................................................................To
select Voice mode
b..................................................................................................................To
select Echo mode
c..................................................................................................................To
select Flanger mode
d..................................................................................................................All
of the above

5
Choose Answer: D

What is the function of pressing the interrupt button in this application?


a. To change the mode
b..................................................................................................................To
update the variable (value read from the DIP switch)
c..................................................................................................................To
reset the DIP switch
d..................................................................................................................All
of the above
Choose Answer:B

 17. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

1.2.3. Review Questions


1. Before the DSP circuit board can be used, a few steps must first be taken. Which steps
must be completed before using the board?
a. Make certain that the DIP switches of the I/O interface are all in the
OFF position
b. Make certain that a USB connection between the board and the
computer is present
c. Make certain that the power source of the board is turned ON
d. Both b. and c
Choose Answer: D

2. What is the range of the dc voltage source of the DSP board?


a. -3.3 V to 3.6 V
b. -3.5 v to 3.5 V
c. -0.8 V to 0.9 V
d. -4.4 V to 7.3 V
Choose Answer: C

3. What does the TMS320C5535 chip found on the DSP circuit board use to set the
frequency of its master clock?
a. The DSP uses its 100 MHz internal oscillator.

6
b. The DSP uses a 32.768 kHz external oscillator and a phase-locked loop.
c. The DSP uses the 33.3 MHz oscillator of the CODEC.
d. The DSP uses the clock of the computer through the USB connection.
Choose Answer:B

4. Which of the following components is usually found in a CODEC?


a. An anti-aliasing filter
b. An analog-to-digital converter
c. A digital-to-analog converter
d. All of the above
Choose Answer: D

5. Increasing the echo delay has which effect on the signal at the output of the DSP?
a. It increases the echo effect.
b. It increases the time between consecutive echoes.
c. The sound seems more remote.
d. All of the above
Choose Answer:D

1.3. EX3: Integrated Development Environment (IDE) and Project


Structure

1.3.1. Integrated Development Environment (IDE) and Project Structure:


Discussion
o The Code Composer Studio Software
o The Code Development Perspective
o Project Structure
o C Code
o Assembly Code
o Configuration File
o The Debug Perspective
o Breakpoints
o Registers, Expressions, and Variables Windows

7
1.3.2. Procedure: Integrated Development Environment (IDE) and Project
Structure
 1. Connect the output of the DC source to the analog input of the CODEC and the
analog output of the CODEC to the audio amplifier as shown. Also, connect one
channel of your oscilloscope to the analog output of the CODEC.
 2. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C.
Launch Code Composer on your computer.
 3. Make exercise_1_2 the active project simply by clicking on that project in the
Project Explorer window.
 4. Launch the Debug mode by clicking the icon to load the program into the DSP.
Do not run the program yet.
 5. Where is the memory address identified at which the main function starts?
a..................................................................................................................In
the Project Explorer window
b..................................................................................................................In
the Debug window at the end of the main() function string
c..................................................................................................................In
the Disassembly window at the start of the debug session
d..................................................................................................................Bot
h b and c
Choose Answer:D

 6. Go to the Registers tab and look for the Program Counter (PC) register. This
register is in the Core Registers list. Is the value of the PC register the same as the
main function starting address?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer: A

Press the assembly step into button to go to the next assembly instruction. What
is the value of the PC register now?
a. The next sequential address in the program
b..................................................................................................................Th
e main function starting address
8
c..................................................................................................................Th
e function ending address
d..................................................................................................................No
ne of the above
Choose Answer: A

What does this number correspond to?


a. The address where the main function started
b..................................................................................................................Th
e address of the current assembly instruction
c..................................................................................................................Th
e total number of program lines
d..................................................................................................................Th
e address of the last assembly instruction
Choose Answer:B

What is the use of the Program Counter register?


a. To keep track of the total number of instruction addresses in the memory.
b..................................................................................................................To
keep track of the total number of programs in the memory.
c..................................................................................................................To
keep track of the address of the current instruction in the memory.
d..................................................................................................................All
of the above
Choose Answer:C

 7. While keeping an eye on the main.c, Disassembly and Variables tabs, experiment
with the different debugger step arrows to observe what happens with the debugger
and the different variables.
 8. Press the run button to run the program on the board. Adjust the GAIN
potentiometer of the audio amplifier to obtain a sound output of the appropriate
volume. At this point, you should see the following information on the LCD of the
DSP circuit board: LabVolt 91031 Ex1-2 - Sin Generator freq = x Hz (where x is
a number).
 9. It should be quite obvious by the name on the LCD and by playing with the dc
source knob that this application generates a sinusoidal waveform which is heard
from the loudspeaker (or earphones). Adjust the potentiometer of the dc source and
observe the result on the signal:

9
a..................................................................................................................Th
e frequency of the signal displayed is modified as the potentiometer is adjusted.
b..................................................................................................................Th
e value of the frequency is also modified accordingly on the LCD.</li>
c..................................................................................................................As
the frequency changes the audio signal also changes.</li>
d..................................................................................................................All
of the above
Choose Answer:D

 10. Use an oscilloscope to observe the signal at the analog output of the CODEC.
Does the amplitude of the signal change as you change the frequency?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:B

What is the obtainable range of frequency?


a. The frequency can go from about 1 Hz to 500 Hz ± 5%.
b..................................................................................................................Th
e frequency can go from about 50 Hz to 50 kHz ± 5%.
c..................................................................................................................Th
e frequency can go from about 10 Hz to 5027 Hz ± 5%.
Choose Answer:C

 11. Click on the icon to halt the execution of code.


 12. A crucial part of debugging is to be able to know the value of a given variable at a
given moment in the process. This can be done in most cases using the
Expressions or Variables tabs. Here is a case where this method is not as
convenient:
In the main.c file of Exercise 1-2, a table is declared on line 22 like this:
Int16 sintbl[2048];
This means that sintbl is a table containing 2048 elements which are all 16-bit
integers.
On lines 47 to 51 of the main.c file, a loop calculates a value for each of the
elements of the sintbl variable:

// fill sin table</code><br>

10
for (i=0; i&lt;2048;i++) {
sintbl[i]=sin (i/2048.0 * 2.0 *3.14159265) * 32767;
}

Open the Expressions tab and type sintbl in the <new> field to obtain the values of
the sintbl table of integers. It is necessary to expand the display to see an element of
interest. Note the address of the sintbl variable:

0x001862

 13. Another method is to open a Memory window to visualize the data table. Go to the
View menu of Code Composer and choose Memory Browser to open a new
window.
sintbl variable = <recall>recall(hex1)</recall></p>
Search for the address of the sintbl variable in the Memory window. Specify that
the looked-after variable is in the DATA part of the memory and that its type is 16-bit
signed integer.
The content of the memory can thus be observed in a table such as this:
This is an improvement, but due to the sheer size of the sintbl integer table, a
different method should be used.
 14. Another method to visualize a large array of data is to use the graphics display
tool.
 15. In the Tools menu, choose Graph, then Single Time. In the dialog box, set the
parameters as shown and click OK. The Start Address is the location in memory
where the table begins. The sintbl variable contains that address.
Which of the following best represents the resulting graph of the contents of the
sintbl table?
a..................................................................................................................

b..................................................................................................................

Choose Answer: B

11
 16. The use of breakpoints is very important to any debug process. With the debug
process halted, insert a breakpoint in the main function below the comment
identified as “ //Breakpoint #01 ” in the code. Do so by double clicking to the left
of the line number below the Breakpoint #01 identifier in the code.
In the expressions tab, keep an eye on the value of the freq variable.
Press the run button to run the program. The execution of the program should
halt pretty quickly at the appropriate line in the main function. Note the value of the freq
variable:

2531

Adjust the dc source potentiometer in any direction and press the run button
again. The process should run briefly until it halts again at the same line of code.
Observed freq variable = <recall>recall(fib1)</recall>
Is the current value of the freq variable the same or close to the same as observed
in the previous step?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer: A

Press the yellow step into arrow to execute the current line.
What is the value of the freq variable now?
a. The value remained the same
b..................................................................................................................Th
e value updated corresponding to the new position of the dc source potentiometer
c..................................................................................................................Th
e value has dropped to zero
d..................................................................................................................No
ne of the above
Choose Answer: B

 17. It is possible to go deeper in the code by placing a breakpoint in the assembly code
directly.
The breakpoint which was placed below the “ //Breakpoint #01 ” identifier in the C
code corresponds to a breakpoint automatically placed in the disassembly code at address
0x023059.
Add a breakpoint in the Disassembly window at address 0x023086.

12
This adds a corresponding breakpoint in the main.c file at which line?

2434

Breakpoint line = <recall>recall(fib2)</recall>


Remove the breakpoint at address 0x023086, then add a breakpoint in the main.c
file at the line you just wrote down.
At which address in the Disassembly window is a breakpoint added?
a..................................................................................................................0x
023086
b..................................................................................................................0x
023049
c..................................................................................................................0x
023059
d..................................................................................................................0x
02307C
Choose Answer: D

Was the instruction at address 0x023046 the beginning of the corresponding


instruction in C?
a. Yes
b..................................................................................................................No
Choose Answer: B

Why?
a. Instruction 0x023086 was an intermediate step of the command, not its
beginning (0x02307C).
b..................................................................................................................Th
e instruction at address 0x023046 was an include statement.
c..................................................................................................................Th
e instruction at address 0x023046 was a comment only.
Choose Answer: A

Remove all breakpoints inserted so far

Editing Memory and Registers


 18. Open the interrupt.c program file. Place a breakpoint after the “ //Breakpoint #02 “
identifier. Observe that the index variable is modified by this line of code.
13
Open the Expressions tab and add the index variable to the list of variables of
interest.
It is possible to edit the value of the index variable from the Expressions tab. Click
on the Value field and change the value of the variable.
 19. It is also possible to edit the registers of the DSP. Open the Registers tab and
locate the XAR1 register in the Core Registers. Click on the value field and edit
the value of the register (in hexadecimal).
Remove the breakpoint and run the debugger again by pressing the run button .
The program should be running properly.
 20. Halt the program again ( ) and edit the PC register in the Registers tab (Core
Registers) to this value: 0x023129.
Run the program again ( ) Does it perform as intended?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer: A

 21. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer.
 22. Turn OFF the power supply and remove the connections (leads) you made on the
circuit board.

1.3.3. Review Questions


1. Which is the correct syntax for an assembly source statement?
a. mnemonic [operand list] [Label + :] [; + comment]
b. [Label + :] [operand list] mnemonic [; + comment]
c. [Label + :] mnemonic [; + comment] [operand list]
d. [Label + :] mnemonic [operand list] [; + comment]
Choose Answer:D

2. What step(s) must you perform to execute a program from within the Code Composer
Studio software?
a. Turn the power on to the DSP circuit board and connect it to your
computer.
b. Launch Code Composer and start the debug mode for your program.
c. Execute the Run command from the Debug toolbar.
d. All of the above
14
Choose Answer:D

3. Which of these features of Code Composer is false? Code Composer Studio allows a
developer:
a. to run and halt a program and execute single instructions.
b. to automatically generate C code for any application.
c. to place breakpoints at source statements.
d. to edit, build, debug, and manage DSP projects.
Choose Answer:B

4. Which of the following sentences is correct?


a. The breakpoints disappear when a program is executed in debug mode.
b. Breakpoints are not used by serious programmers.
c. The program is automatically halted when an execution line reaches a
breakpoint.
d. All of the above
Choose Answer:C

5. What are the best ways to visualize a large table of data?


a. The Expressions tab
b. The Graph tool
c. The Memory window
d. b. or c., depending on the type of data
Choose Answer:D

1.4. Unit Test

1. What characterizes a digital signal processor?


a. Specialized internal structures that make them execute commands
rapidly and efficiently
b. Fast multiply instructions
c. Reduced set of instructions, making the programming of DSP simpler
d. All of the above
Choose Answer:

15
2. Which of the following is not displayed in one of the columns of the Disassembly
window in Code Composer Studio?
a. The CPU register
b. The machine code instruction
c. The instruction mnemonic
d. The instruction operand(s)
Choose Answer:

3. Which of the following is written in machine code?


a. if(freq > 300) then (freq = freq*2)
b. 0x022F25 ADD #4369 &lt;&lt; #3,AC0,AC0
c. 1011 1110 0001 0011
d. OMEGA: MPY #031h.
Choose Answer:

4. Which of the following statements about digital signal processors is not true?
a. They allow for more complex processing of signals than is possible
with analog circuitry.
b. They are less common than before in high-tech devices.
c. They provide repeatable performance.
d. Digital processing code can be easily modified, making design updates
or changes more flexible.
Choose Answer:

5. What files are generated by Code Composer when a program is compiled and built?
a. .obj files
b. .asm files
c. .out files
d. Both a. and c.
Choose Answer:

6. Which of the following circuit blocks can be used to interact with a DSP program?
a. interrupts
b. Microphone pre-amplifier
c. Auxiliary power input
d. Audio amplifier
16
Choose Answer:

7. What is the role of the CODEC?


a. It detects code problems.
b. It encodes the data from the DSP into a string of ones.
c. It transforms an input analog signal into a digital one and transforms the
output digital signal into an analog one.
d. It produces machine code for the DSP.
Choose Answer:

8. The output of the dc source is adjusted with:


a. a setting in Code Composer.
b. a potentiometer.
c. a lever.
d. It cannot be adjusted.
Choose Answer:

9. The auxiliary power input is used to:


a. generate power for the DSP board.
b. adjust the level of the input signal of the microphone.
c. receive power from an external source and distribute it to the DSP
board.
d. All of the aboveabove
Choose Answer:

10. Code in C is:


a. written in a high-level language.
b. is device dependent.
c. is device independent or portable.
d. Both a. and c.
Choose Answer:

17
BÀI 2: UNIT 2 - Architecture
2.1. Architecture: Fundamentals
o Architecture: Introduction
o The Von Neumann Architecture
o The Harvard Architecture
o The Architecture of the TMS320C5535

2.2. EX01: Processor Arithmetic

2.2.1. Discussion: Processor Arithmetic


o Fixed-Point and Floating-Point DSPs
o Binary and Hexadecimal Numbers
 Introduction
 Decimal to Binary Conversion
 Binary to Decimal Conversion
 Hexadecimal Numbers
Enter decimal number:

Binary

Hexadecimal:

 Decimal to Hexadecimal Conversion


 Hexadecimal to Decimal Conversion
 Binary to Hexadecimal and Hexadecimal to Binary Conversion
o Two’s Complement Representation (2s-format)
o Fractional Numbers – Q-Format
o Fractional Numbers – Floating-Point Format

2.2.2. Procedure: Processor Arithmetic


Converting a Signed Fractional Number to Q14-Format
 1. Convert -0.984375, a decimal signed fractional number to a binary Q14-format. To
do so, open the Microsoft® Calculator tool or an equivalent one able to perform
base conversions. A pocket calculator with base conversion features works well
too.
 2. With your calculator, multiply -0.984375 by 2^14. This scales the fractional

18
decimal value to an integral decimal value and makes it easy to convert this
number to a binary number (in 2s-format). What is the integral decimal value
obtained?
-16128

 3. Use the decimal to binary conversion tool of your calculator to obtain a one Word
(16 bits) binary value. You might have to specify that you want a Word result by
clicking a checkbox.
What is the binary result obtained?

1100 0001 0000 0000

What does it corresponds to in 2sformat?

-16128

In Q14-format?

-0.984375

binary result obtained = <recall>recall(fib2)</recall>


 4. Verify that the binary number you just obtained is equal to the decimal value -
0.984375. Use the Q14-format weights to calculate the decimal value.
-0.984375

Converting a Binary Number to a Decimal Value


Convert the following number to a decimal value in the following cases:
B093h = 1011 0000 1001 0011b
 5. The hexadecimal number represents an unsigned integer. Identify the bit weights
associated to this representation:
a..................................................................................................................

b..................................................................................................................

Choose Answer:b

Calculate the resulting decimal value and select the correct result.

Choose Answer:a

19
B093h = 1011 0000 1001 0011b
 6. The hexadecimal number represents an unsigned integer. Identify the bit weights
associated to this representation:

Choose Answer:a

Calculate the resulting decimal value and select the correct result.

Choose Answer:c

B093h = 1011 0000 1001 0011b


 7. The hexadecimal number is written with the Q15-format. Identify the bit weights
associated to this representation:

Choose Answer:a

Calculate the resulting decimal value and select the correct result:

Choose Answer:b

B093h = 1011 0000 1001 0011b


 8. The hexadecimal number is written with the 16-bit floating-point format. Over the
next few pages you will determine the bit weights associated to this representation
and calculate the resulting decimal value.
Remembering to include the implied bit what is the value of the mantissa?
a..................................................................................................................1
0100 1111 0110
b..................................................................................................................1
1011 0000 1001
c..................................................................................................................10
11 0000 1001 1
Choose Answer:b

20
Identify the bit weights associated with the mantissa:

B093h = 1011 0000 1001 0011b


Identify the bit weights associated with the exponent:

Choose Answer:b

What is the Decimal value of the mantissa?

Choose Answer:b

B093h = 1011 0000 1001 0011b


Identify the bit weights associated with the exponent:
What is the Decimal value of the exponent?

Choose Answer:a

What is the decimal value of the number in 16-bit floating point format?

Choose Answer:c

 9. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 10. Make exercise_2_1 the active project simply by clicking on that project in the
Project Explorer window. Launch the Debug mode by clicking the
 11. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board: LabVolt
91031 Ex2-1 and some number conversion information. Click on the icon to
halt the execution of code.
 12. Open the Expressions tab and type “ var1 ” in the <new> field to see the value of
21
this variable.
Right-click on the current value and select Q-values > Select Q-Value.
Then specify you want to use the Q14-format to display the value, using the select
Q-value option in the Q-Values submenu
Type in -0.984375 as the value of the variable.
Now, right-click on the value and select the decimal format in the Number Format.
Does this value coincide with the one obtained in step 2? submenu
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 13. Right-click on the “ var1” variable and select the binary format. Does this value
coincide with the one obtained in step 3?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 14. Now, choose the hexadecimal (Hex) format for “ var1 ” and type 0xB093 to edit
its value. What is the decimal value of this number? Change the format of “var1”
to decimal in order to obtain this result.
a..................................................................................................................-
16128
b..................................................................................................................-
20333
c..................................................................................................................-
20477
Choose Answer:B

Does this value coincide with the one obtained in step 6?


a. Yes
b..................................................................................................................No
Choose Answer:a

 15. What is the Q15 value of this number? Change the format of “var1” to Q15 in
order to obtain this result.
a..................................................................................................................-
22
16128
b..................................................................................................................-
20333
c..................................................................................................................-
0.620514
Choose Answer:c

Does this value coincide with the one obtained in step 7?


a. Yes
b..................................................................................................................No
Choose Answer:a

 16. Cast “var1” into a float by selecting the Cast To Type command. Enter “float” in
the cast to type window and press OK. Does this value coincide with the one
obtained in step 8?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:b

What is the original size of “var1”:


a. The “var1” variable is of the integer type (32 bits).
b..................................................................................................................Th
e “var1” variable is of the integer type (16 bits).
Choose Answer:b

A variable, such as “var3”, which is of the float type, uses the (32-bit) floating
point representation.
A variable declared as a float cannot be displayed as a Q-format number. In the
same way, a variable declared as an integer cannot make use of the floating-point
representation.
Add “var3” to the expressions list to verify this for yourself.
 17. Recast “var1” into an int. Notice how “var1” cannot be used as an unsigned integer
to obtain the result of step 5. This is because this variable is declared as a 16-bit
signed integer. Add variable “varUnsigned” to the Expressions tab. Edit its value
to 0xB093 and display the result in Decimal notation.
Does this value coincide with the one obtained in step 5?
a..................................................................................................................Ye
23
s
b..................................................................................................................No
Choose Answer:a

What is the type of “varUnsigned”:


a. signed
b..................................................................................................................uns
igned long
c..................................................................................................................uns
igned short
Choose Answer:b

Comparing the Multiplication of Integers to the Multiplication of Floats on a Fixed-point


DSP
In the main.c file, place a breakpoint below identifier “//Breakpoint #01” and
another below identifier “//Breakpoint #02”
 18. Press the run button to run the program until it stops at the first breakpoint. The
line below “//Breakpoint #01” commands the multiplication of “var3” a float, with
itself. Step into the instruction using the arrow.
Observe the instructions in the Disassembly window and click on the arrow a
few times. Observe that many assembly instructions (a bit more than a hundred) are
required to execute this seemingly simple line of code.
 19. Press the run button to run the program again until it stops on the line below
“//Breakpoint #02”. This line commands the multiplication of “var1”, an integer,
with itself.
Step into the instruction using the arrow. Observe the instructions in the
Disassembly window and click on the arrow a few times. Observe that only a few
(four) assembly instructions are required to execute this line in the main.c file.
This illustrates how complex and processor intensive it is to emulate the
multiplication of floats on a DSP designed to use a fixed-point representation.
Remove all breakpoints inserted so far.
 20. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

2.2.3. Review Questions

24
1. What is the range of decimal values that a 2s-format 16-bit binary number can
represent?
a. -65536 to 65535
b. 0 to 65536
c. -32768 to 32767
d. 0 to 16
Choose Answer:c

2. Which statement about floating-point DSPs is true?


a. They typically have a narrower dynamic range than fixed-point DSPs.
b. They typically have a wider dynamic range than fixed-point DSPs.
c. A typical 24-bit floating-point processor stores coefficients and data.
d. The implied bit takes up space in memory.
Choose Answer:b

3. Convert 0xAB12 into a binary string


a. 1010101100010010
b. 1111111000010011
c. 1010101101010111
d. 0010000110111010
Choose Answer:A

4. What is the proportionality constant between the 2s-format and the Q13- format, for a
16-bit binary number?
a. 13
b. 215
c. 8192
d. -3.0518 x 10-5
Choose Answer:c

5. What is the decimal value of 0xAB12


a. 24
b. 214
c. -21742
d. -1.32703

25
Choose Answer:

2.3. EX02: Data Computation Unit

2.3.1. Discussion: Data Computation Unit


o Data Computation Unit: Introduction
 Introduction
 Accumulators and Operand Registers
 Multiply-and-Accumulate Units (MACs)
 Arithmetic Logic Unit (ALU)
 Barrel Shifter
o Basic Instructions
o Sign-extension Mode
o The MAC: Basic Operations
o Operations: Overflow, Underflow, and Saturation Mode
o Status Bits
o Parallelism

2.3.2. Procedure: Data Computation Unit


Set Up of the DSP Board
 1. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C.
Launch Code Composer on your computer.
 2. Make exercise_2_2 the active project simply by clicking on that project in the
Project Explorer window. Open both the main.c and LVex2_2.asm files of this
exercise. Launch the Debug mode by clicking the icon to load the program into
the DSP.
 3. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board:
LabVolt 91031 Ex2-2</code> and some number conversion information.
 4. Adjust the DIP switch of the I/O interface to values of your choice. Observe the
result on the LCD. ou should note that the last two digits of AC0 are related to the
position of the DIP switches. Click on the icon to halt the execution of code.
In the LVex2_2.asm file, locate the MARKER1 identifier.
Observe that the content of the AC0 accumulator relates to the value of the DIP
26
switch to which a value is added. This value is the number 8111h shifted to the left by 15
bits.
What would be the value shown on the LCD if the assembly instruction:
add #8111h<<#15,AC0
were to be changed to
add #8111h<<#8,AC0
and for a DIP switch value of 1111 0111b
The value shown would be:
a..................................................................................................................0x
00811B3
b..................................................................................................................0x
00811FF
c..................................................................................................................0x
00811F7
Choose Answer:c

 5. With the execution of the code halted, insert a breakpoint in the LVex2_2.asm file,
just below the Operations identifier. Notice, above the breakpoint you inserted, the
instruction which deactivates the sign-extension mode:
;bclr SXMD ;no sign extension
Also, the following values are used (in 2s-format):
 6. Open the Registers window and locate the AC0HL, T0, and ST0 registers among
the Core registers dropdown. Press the run button to restart the program on the
board.
Observe the instructions in the LVex2_2.asm file and click on the arrow to
execute the different instructions as you observe the value of the different registers and
the results of the ADD, SUB, AND, OR, NOT, MACM, MPYM instructions.
Note the results (value of AC0) below:

ADD (x, y): 0x00000000D1

SUB (x, y): 0x0000000097


0x0000000014
AND (x, y): 0x0000000014

OR: (x, y): 0x00000000BD

27
NOT (x): 0xFFFFFFFFE2

MACM (AC0 z + x * y) 0x0000001465

MPYM (AC0 = x * y) 0x0000001464

MACM (AC0 = AC00 + x * -y) 0x0000000000

ADD (17, w) 0x0000010000

MPYM (z = mul1 * mul2) 0xFFFFFFDE11

 7. Go back to your breakpoint and to the instruction which deactivates the sign
extension mode. Deactivate this instruction (transform it into a comment) by
placing a semicolon (;) in front of it like this:
;bclr SXMD ;no sign extension

Click on the icon to terminate the execution of the program in debug mode, then
re-launch the debug mode by icon. This will rebuild the output file and reload the
program into DSP – this time, with the sign extension activated.
Press the run button to run the program on the board. The program will stop at
your breakpoint.
 8. Re-execute the different instructions (with the arrow) and note the results of the
second-to-last instruction.
ADD (17, w): 0x0000000000

How is “w” entered in the AC0 register (on the line before the addition)?

W= 0xFFFFFFFFEF

Step 8. ADD (17, w): <recall>recall(fib11)</recall>


Step 6. ADD (17, w): <recall>recall(fib9)</recall>
Compare the result of the ADD (17, w) instruction with the result obtained before
in step 6. Is sign extension relevant?
a..................................................................................................................Sig
n extension makes the result coherent in this case (negative numbers are not
mistaken for positive numbers) and is very relevant.
b..................................................................................................................Th
28
ere is no impact on the value by including the sign extension.
Choose Answer:a

 9. Remove the breakpoint you inserted in the LVex2_2.asm file, next to the
Operations identifier

Overflow, Saturation Mode and Carry Bit


 10. If necessary, halt the program using the button. Go to the MARKER3 identifier
in the LVex2_2.asm file and insert a breakpoint next to the MOV #0,AC0
instruction and another one next to the first bclr CARRY instruction (just after the
MAC instruction).
Observe that the saturation mode is not enabled (the bset SATD instruction is
presently a comment).
Observe that the code asks to multiply the number _bigV (the largest word
possible = 7FFFh) by itself and to accumulate the result in AC0. The RPT #257
instruction repeats this operation 257 times, resulting in a very large result in the
accumulator.
 11. Press the run button to run the program. The program will stop at your first
breakpoint. Execute the different instructions (with the arrow) and observe how
the value of the AC0 accumulator increases with each MAC operation.
Press the run button again to run the program. The program will complete the
multiple repetitions of the MAC instruction and stop at your second breakpoint.
Note the following values:

AC0: 0x80FDFC0204

ACOV0: 1

Did the MAC instructions make the accumulator overflow?


a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 12. Execute the bclr CARRY and bclr ACOV0 instructions (with the arrow) to
clear (value equal to 0) both the CARRY bit flag and the overflow bit of AC0 in
the ST0 status register.Next, execute the different instructions one by one and note
the value of the CARRY bit after the following instructions:

29
SUB #1001h,AC0 CARRY = 0

ADD #1001h,AC0 CARRY = 1

SUB #1001h,AC0 CARRY = 1

ADD #1001h,AC0 CARRY = 0

Is the CARRY bit behaving as you expected?


a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 13. With the execution of the code halted, insert a breakpoint in the LVex2_2.asm file,
just below the Operations identifier. Notice, above the breakpoint you inserted, the
instruction which deactivates the sign-extension mode:
;bset SATD ;Saturation mode bit for the D-Unit
Click on the icon to terminate the execution of the program, then relaunch the
debug mode by clicking the icon. This will rebuild the output file and load the
program into DSP – this time, with the overflow saturation mode activated.
Press the run button to run the program. The program will stop at your first
breakpoint.
 14. Press the run button a second time. The program will complete the multiple
repetitions of the MAC instruction and stop at your second breakpoint. Note the
following values:
AC0: 0x7FFFFFFFFF

ACOV0: 0

Did the MAC instructions make the accumulator overflow?


a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:b

 15. Click on the icon to terminate the execution of the program. Delete all

30
breakpoints and put the semi-colon (;) back in front of the bset SATD instruction
to turn it back into a comment. Remove the semi-colon in front of the bclr SXMD
instruction, just before the Operations identifier
 16. Make exercise_2_2b the active project simply by clicking on that project in the
Project Explorer window. Open both the main.c and LVex2_2b.asm files of
exercise_2_2b.
 17. Observe the contents of the LVex2_2b.asm file. In this routine, two algorithms
calculate the output of a filter for some data. This is typical of a DSP calculation.
The first algorithm does not use parallelism. It uses MAC instructions which are
repeated many times in a loop.
The duration of this algorithm is measured by “delta1”, a variable defined in the
main.c file.
The value of this variable is the difference between two decrementing counters
(timeCnt1 and timeCnt2).
The second algorithm does the same thing as the first, but uses parallelism.
This can be seen by the pairs of MAC instructions separated by the double colon (::).
The duration of this algorithm is measured by “delta2”, a variable defined in the
main.c file.
The value of this variable is the difference between two decrementing counters
(timeCnt3 and timeCnt4).
 18. In the Expressions window, add the following two variables: “delta1” and “delta2”
Note that a counter in this program is decremented by one after two clock cycles.
Consequently, the number of clock cycles required to perform each algorithm is
equal to delta * 2
 19. Launch the Debug mode by clicking the icon to load the program into the DSP.
Insert a breakpoint in the main.c file at the line below the “//Breakpoint #01”
identifier. This will allow to halt the program just after the execution of the ex2_2b
routine.
 20. LPress the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board:
L.V. 91031 Ex2-2b / Memory & Profiling
 21. The ex2_2b routine has now been executed. Press the step-into arrow ( arrow)
twice to execute the two instructions which calculate the values of “delta1” and
“delta2”.
Note the results below:

detal1: 196 which is equivalent to 392 clock cycles

31
detal2: 113 which is equivalent to 226 clock cycles

Does parallelism increase the data processing capacity of the DSP?


a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:b

 22. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

2.3.3. Review Questions


1. What is the difference between using the DSP with sign-extension enabled versus
disabled?
a. When enabled, all data values in the DSP are sign extended
b. When enabled, an accumulator saturates instead of overflowing.
c. When enabled, the MAC outputs are sign extended
d. When enabled, the D Unit outputs are sign extended
Choose Answer:a

2. Which of the following is not a way of avoiding accumulator overflows?


a. Guard bits
b. Shifter
c. Sign-extension mode
d. Overflow saturation mode
Choose Answer:b

3. Why is the overflow saturation mode used?


a. To obtain more precise results
b. To make results more likely to contain many bits set to 1
c. To avoid obtaining results of the wrong sign when an overflow occurs
d. To make results more likely to contain many bits reset to 0
Choose Answer:a

32
4. What is the result of this bitwise operation: 0101 OR 1100?
a. 0100
b. 1101
c. 10001
d. 111100
Choose Answer:c

5. What is the result of the sign extension to 8 bits of the 4 bit word: 1010?
a. 1111 1010
b. 0000 1010
c. 1010 1111
d. 1010 0000
Choose Answer:d

2.4. EX03: Memory

2.4.1. Discussion: Memory


o Introduction
o Unified Memory
o Linker Command File
o Multiply-and-Accumulate Units (MACs)

2.4.2. Procedure: Memory


Set Up and Connections of the DSP Board
 1. Perform the connections shown in our Figure. You can also connect the input of
the microphone pre-amplifier to the audio output jack of your computer if you
prefer to use an audio signal from your computer.
 2. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 3. Make exercise_2_3 the active project simply by clicking on that project in the
Project Explorer window. Open both the main.c and interrupt.c files of this
exercise Launch the Debug mode by clicking the icon to load the program into
the DSP.

33
 4. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board: LabVolt
91031 Ex2-3 - Playback/Recorder.

Testing the Program


This program allows the DSP to record an audio signal using different sampling
methods. To do this, a mode of operation must be selected using the DIP switch of the I/O
interface. Setting the 3 least significant bits of the DIP switch to form a number from 0 to
4 allows you to access the following modes:

0 (000b) 16-bit sampling

1 (001b) 8-bit sampling using a μ-law compression process

2 (010b) 8-bit sampling which truncates the samples

3 (011b) 16-bit sampling, using the flash memory

4 (100b) Mode used to erase the flash memory

Two pushbuttons are also used.


To start recording the audio signal or to erase the flash memory (in mode 4)
To play back the audio signal recorded
 5. Adjust the DIP switch of the I/O interface to a value of 0 (all bits to 0).
 6. Press the button to activate the recording mode.
Using the microphone, input a signal (your voice) into the DSP. Alternatively, you
can connect the pre-amplifier to the audio output of your computer as an audio file is
being played (the output level must then also be adjusted fairly low).
Adjust the GAIN potentiometer of the pre-amplifier to avoid saturation (exceeding
a certain level).
Note that a series of black rectangles light up on the last line of the LCD as you
talk into the microphone. The length of that line corresponds to the magnitude of the input
signal from the microphone pre-amplifier. A constantly full line should be avoided and
the potentiometer should be adjusted at a fairly low level.
 7. Next, press the button to play back the recorded signal. Adjust the GAIN
potentiometer of the audio amplifier to obtain an adequate volume of sound at the
output (loudspeaker or headphones)
 8. Adjust the DIP switch of the I/O interface to a value of 0 to activate the 16-bit
mode
 9. Record an audio signal (press the button). What is the longest duration of
signal you can record?
a..................................................................................................................Ap

34
proximately 1 second
b..................................................................................................................Ap
proximately 2 seconds
c..................................................................................................................Ap
proximately 4 seconds
Choose Answer:c

 10. Play back the audio signal (press the button). How would you describe the
quality of the recording?
a..................................................................................................................Thi
s depends a lot on the original audio signal and the settings of the system.
b..................................................................................................................Th
e quality should be good compared to the 8-bit modes.
c..................................................................................................................So
unds good to me!
d..................................................................................................................All
of the above
Choose Answer:d

 11. The signal is sampled and stored in a table called recBuff. Click on the icon to
halt the execution of the code. Open the Expressions window and add the recBuff
table to the list. What is the number of samples stored in the table?
a..................................................................................................................10
000
b..................................................................................................................32
768
c..................................................................................................................Un
known
Choose Answer:b

What is the size (in bits) of each sample?


d. 16 bits (2 bytes)
e..................................................................................................................32
bits (4 bytes)
f..................................................................................................................64
bits (8 bytes)
Choose Answer:a

What is the total size of the recording in KB?


35
g. 16 KB or 16384
h..................................................................................................................32
KB or 32768
i...................................................................................................................64
KB, or 65536 bytes
Choose Answer:c

What is the address of the first element of recBuff?


j. 0x0103E8@DATA
k..................................................................................................................0x
010000@DATA
l...................................................................................................................0x
017F58@DATA
Choose Answer:b

In which type of memory is this address located? The <look>lnkx.cmd</look> file


might be useful to answer this question
m. In the SARAM
n..................................................................................................................In
the DARAM
o..................................................................................................................In
the ROM
Choose Answer:a

 12. Produce a graph of the first 8000 samples of the recorded signal. In the Tools
menu, choose Graph, then Single Time. In the dialog box, set the parameters as
shown in the Figure and click OK. The Start Address is the location in memory
where the table begins. The recBuff variable contains the required address. Print
the resulting graph. Your graph of the contents of the recBuff table will look
similar to our sample.
 13. Adjust the DIP switch of the I/O interface to a value of 1 to activate the 8-bit mode
with μ-law compression.Press the run button to run the program on the board.
 14. Record an audio signal (press the button). What is the longest duration of
signal you can record?
a..................................................................................................................Ap
proximately 2 seconds
b..................................................................................................................Ap
proximately 4 seconds
c..................................................................................................................Ap
36
proximately 8 seconds
Choose Answer:c

 15. Play back the audio signal (press the button). How would you describe the
quality of the recording?
a..................................................................................................................Bet
ter than the 16-bit recording
b..................................................................................................................Sli
ghtly worse than the 16-bit recording
c..................................................................................................................Ext
remely bad
Choose Answer:b

 16. The μ-law compression scheme tries to optimize the quantization noise of the
signal, especially for small values of the signal. Adjust the DIP switch of the I/O
interface to a value of 2 to activate the 8-bit mode without the μ-law compression
scheme and press the button again to play the recorded audio in this new
mode. How is the sound now?
a..................................................................................................................Bet
ter than the 16-bit recording
b..................................................................................................................Sli
ghtly worse than the 16-bit recording
c..................................................................................................................Ext
remely bad
Choose Answer:c

 17. Click on the icon to halt the execution of the code. The signal is still sampled
and stored in a table called recBuff. However, each element of the table (16 bits =
2 bytes) contains two samples (1 byte per sample). There are consequently twice as
many samples compared to the 16-bit case. What is the total size of the audio
recording in 8-bit mode?
a..................................................................................................................16
KB or 16384
b..................................................................................................................32
KB or 32768
c..................................................................................................................64
KB, or 65536 bytes
Choose Answer:c

37
Is this consistent with the time recording capacity of this mode?
d. Yes
e..................................................................................................................No
Choose Answer:a

 18. Adjust the DIP switch of the I/O interface to a value of 2 to activate the 8-bit
mode. This mode does not attempt to minimize errors caused by the signal
quantization. Press the run button to run the program on the board.
 19. Record an audio signal (press the button). What is the longest duration of
signal you can record?
a..................................................................................................................Ap
proximately 2 seconds
b..................................................................................................................Ap
proximately 4 seconds
c..................................................................................................................Ap
proximately 8 seconds
Choose Answer:c

 20. Play back the audio signal (press the button). How would you describe the
quality of the recording?
a..................................................................................................................Sli
ghtly worse than the 8-bit recording with μ-law compression
b..................................................................................................................Bet
ter than the 16-bit recording
c..................................................................................................................Ext
remely bad
Choose Answer:a

 21. What would happen if an audio recording done in 8-bit mode were to be played in
16-bit mode? Adjust the DIP switch of the I/O interface to a value of 0 to activate
the 16-bit mode. Press the button again to play the recorded audio in this
new mode. How is the sound now?
a..................................................................................................................Cle
ar
b..................................................................................................................Dis
torted
Choose Answer:b

 22. Note that the data is recorded in the same data table (at the same address as
38
before). You can halt the process if you wish and observe the graph of the audio
recording (specify that the data is 8-bit long).
 23. Adjust the DIP switch of the I/O interface to a value of 4 to activate the flash
memory erase mode. Make sure the program is running (Press the run button to
run the program on the board, if required). Press the button to delete the
contents of the flash memory.
 24. Adjust the DIP switch of the I/O interface to a value of 3 to activate the 16-bit
flash memory mode. Calculate the longest duration of signal you can record on the
flash memory, knowing it has a capacity of 8 MB (or 8192 KB). Use the size and
duration of the file previously obtained in steps 9 and 11 for the 16-bit mode.
a..................................................................................................................8.5
seconds
b..................................................................................................................8.5
minutes
c..................................................................................................................8.5
hours
Choose Answer:b

 25. Record an audio signal (press the button).


 26. Play back the audio signal (press the button).
 27. How would you describe the quality of the recording?
a..................................................................................................................Mu
ch better than the 16-bit recordings
b..................................................................................................................Eq
ual to the original 16-bit recordings (mode 0)
c..................................................................................................................Ext
remely bad
Choose Answer:b

 28. Click on the icon to halt the execution of the code. The flash memory is
external to the DSP and must be accessed via a peripheral. Consequently, there is
no simple way to observe the contents of that memory or to obtain the graph.
 29. Go to the View menu of Code Composer and choose Memory Browser to open a
new window. Search for address 0x010000 in the Memory window. Specify that
the looked-after variable is in the DATA part of the memory and that its type is 16-
bit hexadecimal. What is the content of that memory word?
16-bit hex value = 0x20000

 30. As explained in the theory part of this exercise, if the same memory content were

39
to be accessed with the program bus, it would be necessary to adjust the addressing
and to access bytes instead of words. Search for address 0x020000 in the Memory
window. Specify that the looked-after variable is in the PROGRAM part of the
memory and that its type is 8-bit hexadecimal. What is the content of that memory
byte?
8-bit hex value = 4E

What is the content of the next byte in memory (address 0x020001)?


8-bit hex value = FD

 31. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

2.4.3. Review Questions


1. Which type of memory is still intact after a restart of the DSP?
a. SARAM
b. Flash memory
c. DARAM
d. The MMR
Choose Answer:b

2. The linker command file is used to:


a. supply directives to the linker regarding the linking process of the
executable file.
b. specify the address ranges of different blocks of memory.
c. specify in which memory blocks the different types of data can be
allocate
d. All of the above
Choose Answer:a

3. What can be said about the data in the DARAM block?


a. Data can be initialized in the DARAM block.
b. Data can be written in the DARAM block.
c. Data can be read from the DARAM block and the size of the block is
256 bytes.
d. All of the above

40
Choose Answer:c

4. A byte is accessed by the program bus at address 0x001011. At which address can the
word containing this byte be accessed by the data bus?
a. 0x000808
b. 0x001022
c. 0x001020
d. It cannot be accesse
Choose Answer:b

5. A word in memory is 8A3F and is accessed at address 0x000100 by the data bus. What
is the content of the memory block accessed by the program bus at address 0x000201?
a. 8A3F
b. 8A
c. 3F
d. It cannot be accessed
Choose Answer:a

2.5. EX04: Addressing

2.5.1. Discussion: Addressing


o Addressing: Introduction
o Absolute Addressing
o Direct Addressing
o Indirect Addressing
 Indirect Addressing
 Circular Buffering
o Borderline Cases
 Implied Addressing
 Immediate Addressing

2.5.2. Procedure: Addressing


Set Up and Connections of the DSP Board
 1. Perform the connections shown in our Figure. You can also connect the input of
the microphone pre-amplifier to the audio output jack of your computer if you
41
prefer to use an audio signal from your computer.
 2. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer.Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 3. Make exercise_2_4 the active project simply by clicking on that project in the
Project Explorer window.Open both the main.c and LVex2_4.asm files of this
exercise. Launch the Debug mode by clicking the icon to load the program into
the DSP.
 4. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board: LabVolt
91031 Ex2-4 / Signal Averaging. This program allows the DSP to record an
analog signal in a circular buffer containing sixteen samples. The average of the
samples is calculated and the result is sent out as the analog output of the DSP.
 5. Speak in the microphone (or play a sound file on your computer) as you listen to
the resulting sound out of the DSP on the loudspeaker or headphones. How is the
output signal affected by the DSP algorithm?
a..................................................................................................................Th
e sound is not as sharp as the original signal.
b..................................................................................................................Hi
gher frequencies (high register notes) are dampened.
c..................................................................................................................Th
e averaging process acts as a sort of low-pass filter for the signal.
d..................................................................................................................All
of the above
Choose Answer:d

 6. Click on the icon to halt the execution of the code. In the LVex2_4.asm file,
observe the _initCB section of code. This part is used to initialize the circular
buffer. The number of elements is set to 16, the DSP is configured to operate with
circular buffers, and the index is set to 0.
 7. Go to the _initDone part of the file and locate the mov mmap(@BK03), AC0
instruction. Insert a breakpoint at this line (below identifier Breakpoint #01) and
press the icon to execute the program up to that point. Which type of addressing
is used with regards to BK03?
a..................................................................................................................Ind
irect addressing
b..................................................................................................................Dir
ect addressing

42
c..................................................................................................................Im
plied addressing
Choose Answer:b

In the Disassembly window, observe the opcode associated to the instruction.


What is the code?
d. a032_98
e..................................................................................................................a06
4_98
f..................................................................................................................c09
6_98
Choose Answer:a

 8. Go to the amov #000000h, XAR1 instruction. Insert a breakpoint at this line


(below identifier Breakpoint #02) and press the icon to execute the program up to
that point. Which type of addressing is used?
a..................................................................................................................Dir
ect addressing
b..................................................................................................................Ind
irect addressing
c..................................................................................................................Im
mediate addressing
Choose Answer:c

In the Disassembly window, observe the opcode associated to the instruction.


What is the code?
d. a931001977
e..................................................................................................................ec3
19e000000
f..................................................................................................................ea3
10c00194b
Choose Answer:b

What happens to the 000000 constant?


g. The constant (000000) is directly contained in the opcode.
h..................................................................................................................Th
e constant (000000) has been replaced with a value.
i...................................................................................................................Th

43
e constant (000000) has been unlinked from the machine code.
Choose Answer:

 9. Go to the mov AC1,*AR1+ instruction. Insert a breakpoint at this line (below


identifier Breakpoint #03) and press the icon to execute the program up to that
point. Which type of addressing is used?
a..................................................................................................................Dir
ect addressing
b..................................................................................................................Ind
irect addressing
c..................................................................................................................Im
mediate addressing
Choose Answer:b

In the Disassembly window, observe the opcode associated to the instruction.


What is the code?
d. c123
e..................................................................................................................3c0
0
f..................................................................................................................4c0
f
Choose Answer:a

 10. Add the following two variables to the Expressions window: average and recBuff.
The average variable contains the result of the sum of the samples divided by 16,
that is, the average of the samples. The recBuff variable is a table containing
sixteen different samples from the signal used in the circular buffer.
 11. Edit the different elements of recBuff to values of your choice from the
Expressions window. What is the number of samples stored in the table?
a..................................................................................................................15
b..................................................................................................................16
c..................................................................................................................19
3A
Choose Answer:b

What is the size (in bits) of each sample?


d. 32-bits
e..................................................................................................................8-
bits
44
f..................................................................................................................16-
bits
Choose Answer:c

 12. Go to the instruction. Insert a breakpoint


at this line (below identifier Breakpoint #04) and press the icon to execute the
program up to that point. Press the assembly step into button to execute the
current line. What is the result of the average of the different samples?
a..................................................................................................................Th
e average of the samples entered in the recBuff table, rounded down.
b..................................................................................................................Th
e sum of the samples entered in the recBuff table.
c..................................................................................................................Th
e sum of the samples entered in the recBuff table divided by 15.
Choose Answer:a

Does it correspond to the average of the numbers you entered in recBuff?


d. Yes
e..................................................................................................................No
Choose Answer:a

 13. Remove all breakpoints inserted so far.


 14. Modify the setup and perform the connections shown below.
 15. Use a signal generator to produce a sinusoidal waveform with an amplitude of 0.4
V and a frequency of 100 Hz. Observe both the input signal (Channel 1) and the
DSP output signal (Channel 2) on an oscilloscope. What does the signal look like?
a..................................................................................................................Th
e signal is a square waveform
b..................................................................................................................Th
e signal is a sinusoidal waveform
c..................................................................................................................Th
e signal is a saw tooth waveform
Choose Answer:b

Is the output signal in sync with the input signal?


d. Yes, the two signals are in syn
e..................................................................................................................No,
the signal is slightly delayed.

45
Choose Answer:b

What is the amplitude of the output signal?


f. The amplitude is about 1.1 V.
g..................................................................................................................Th
e amplitude is about 11.0 V.
h..................................................................................................................Th
e amplitude is about 0.11 V.
Choose Answer:a

How is the quality of the output signal?


i. The output signal is very pure.
j...................................................................................................................Th
e output signal is slightly fuzzier than the original one.
k..................................................................................................................Th
e two signals are the exactly the same.
Choose Answer:b

 16. Increase the frequency of the signal to 800 Hz. Observe both the input signal
(Channel 1) and the DSP output signal (Channel 2) on an oscilloscope. Is the
output signal in sync with the input signal?
a..................................................................................................................Ye
s, the two signals are in syn
b..................................................................................................................No,
the signal is slightly delayed.
Choose Answer:b

What is the amplitude of the output signal?


c. The amplitude is about 1.1 V.
d..................................................................................................................Th
e amplitude is about 0.25 V.
e..................................................................................................................Th
e amplitude is about 4.0 V.
Choose Answer:a

How is the quality of the output signal?


f. The output signal is fuzzier than the original one.
g..................................................................................................................Th
46
e two signals are the exactly the same.
h..................................................................................................................Th
e output signal is much cleaner that the original signal.
Choose Answer:a

 17. Change the frequency of the signal to 450 Hz. Observe both the input signal
(Channel 1) and the DSP output signal (Channel 2) on an oscilloscope. Is the
output signal in sync with the input signal?
a..................................................................................................................No,
the output signal is almost inverted with respect to the original signal.
b..................................................................................................................Ye
s, the two signals are in syn
Choose Answer:a

What is the amplitude of the output signal?


c. The amplitude is about 0.125 V.
d..................................................................................................................Th
e amplitude is about 1.25 V.
e..................................................................................................................Th
e amplitude is about 12.5 V.
Choose Answer:a

How is the quality of the output signal?


f. The output signal is fuzzier than the original one.
g..................................................................................................................Th
e two signals are the exactly the same.
h..................................................................................................................Th
e output signal is much cleaner that the original signal.
Choose Answer:d

 18. Use a signal generator to produce a triangle waveform with an amplitude of 0.4 V
and a frequency of 100 Hz. Observe both the input signal (Channel 1) and the DSP
output signal (Channel 2) on an oscilloscope. What does the signal look like?
a..................................................................................................................Th
e signal is close to being a sinusoidal waveform.
b..................................................................................................................Th
e averaging algorithm smoothes the original signal.
c..................................................................................................................Th
ere is a delay between the two.
47
d..................................................................................................................All
of the above.
Choose Answer:d

 19. Use a signal generator to produce a square waveform with an amplitude of 0.4 V
and a frequency of 180 Hz. Observe both the input signal (Channel 1) and the DSP
output signal (Channel 2) on an oscilloscope. What does the signal look like?
a..................................................................................................................Th
e signal looks like a triangular waveform.
b..................................................................................................................Th
e signal saturates (crops the triangle tips), as the average of a plateau cannot be
higher than the plateau itself.
c..................................................................................................................Th
ere is a delay between the two signals.
d..................................................................................................................All
of the above.
Choose Answer:d

 20. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

2.5.3. Review Questions


1. What are addressing modes?
a. The addresses in a set that occur the most frequently.
b. Possible configurations of a postal service sorting facility.
c. Different methods to access information in memory, either to read it or
write over it.
d. Techniques to speak at an assembly in an informal way
Choose Answer:c

2. Pointers are associated to:


a. Absolute addressing
b. Direct addressing
c. Indirect addressing
d. Implied addressing
Choose Answer:c

48
3. Which mode is associated to a constant address explicitly specified in the instruction?
a. Absolute addressing
b. Direct addressing
c. Indirect addressing
d. Implied addressing
Choose Answer:a

4. Which mode is associated with the @ operator to specify a call of the address of a
variable in the instruction?
a. Absolute addressing
b. Direct addressing
c. Indirect addressing
d. Implied addressing
Choose Answer:b

5. A circular buffer requires:


a. A circular memory chip
b. A data pointer
c. A buffer size register
d. Both b. and c.
Choose Answer:d

2.6. Unit Test

1. What is the basic processor memory architecture most often implemented in digital
signal processors?
a. The Von Neumann architecture
b. The Harvard architecture
c. The modified Von Neumann architecture
d. The ATARI architecture
Choose Answer:b

2. Which of the following elements is not necessarily part of a DSP chip?


a. The CODEC
b. Central Processing Unit (CPU)
c. Bus structure

49
d. SARAM
Choose Answer:a

3. In which of the following situations does an instruction require the use of an


addressing mode?
a. When the instruction needs to read an operand from memory
b. When the instruction needs to write an operand to memory
c. When the instruction needs to fetch the value held within an
accumulator
d. All of the above
Choose Answer:d

4. Which of the following choices is true? A dually addressed program/data memory


block can:
a. hold operands only and is accessed by the program bus.
b. hold instructions and operands accessed by the program bus and data
bus.
c. only hold instructions accessed by a data bus.
d. hold operands only and is accessed by the CODEC
Choose Answer:a

5. Convert 93AF into a binary string:


a. 1011 0011 1011 1111
b. 1000 0011 1000 1000
c. 1001 0011 1010 1111
d. 1001 0101 1001 1010
Choose Answer:a

6. What is the decimal value of 8800<sub>h</sub> in Q13-format?


a. -3.75
b. 8.25
c. 0.00215401
d. 34816
Choose Answer:d

50
7. What is the result of this bitwise operation: 0101 AND 1100?
a. 1101
b. 1001
c. 1011
d. 0100
Choose Answer:d

8. What is the result of the sign extension to 8 bits of the 4-bit word: 0110?
a. 0000 0111
b. 0000 0110
c. 1111 0110
d. 1111 0111
Choose Answer:c

9. A byte is accessed by the program bus at address 0x004021. At which address can the
word containing this byte be accessed by the data bus?
a. 0x002010
b. 0x004020
c. 0x008042
d. It cannot be accessed.
Choose Answer:b

10. A pointer variable is designed to:


a. be a constant.
b. contain the address of another variable.
c. contain data.
d. randomly increment its contents.
Choose Answer:a

51
BÀI 3: I/O and Peripherals
3.1. I/O and Peripherals: Fundamentals
o Peripherals, Inputs and Outputs (I/O)
o Codec

3.2. EX01: An Application Using I/Os and Peripherals

3.2.1. Discussion: An Application Using I/Os and Peripherals


o Peripherals, Inputs and Outputs (I/O)
o Excerpts of the Code of the Application

3.2.2. Procedure: An Application Using I/Os and Peripherals


Set Up and Connections of the DSP Board
 1. Perform the connections shown in the figure below. You can also connect the input
of the microphone pre-amplifier to the audio output jack of your computer if you
prefer to use an audio signal from your computer.
 2. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 3. Make exercise_3_1 the active project simply by clicking on that project in the
Project Explorer window. Open the main.c file of this exercise. Launch the Debug
mode by clicking the icon to load the program into the DSP.
 4. Observe the main.c file. Which of the following initialization functions are called
in the main routine?
a..................................................................................................................int
errupt_init();// Initialize interrupt
b..................................................................................................................EZ
DSP5535_init();// Enable clocks to all peripherals
c..................................................................................................................init
Display();
d..................................................................................................................Iai
c3204_init();// Initialize CODEC
e..................................................................................................................All
of the above

52
Choose Answer:e

 5. Locate the I2S_initForDMA() function call in the main.c file. Hover the mouse
pointer over the call and perform the Open Declaration command (Ctrl + F3 or use
a right-click and select the command from the menu). Observe that this function
creates a variable, hwConfig, which is of type I2S_Config. This variable is a
structure made of several other variables. Many of these are initialized in the
I2S_initForDMA function. For instance, the variable dataType is set so as to
enable stereo recordings.Go back to the main function.
 6. Locate the start_acq() function call in the main function. Hover the mouse pointer
over the call and perform the Open Declaration command (Ctrl + F3 or use a right-
click and select the command from the menu). Code Composer takes you to the
code of the start_acq() function. Among others, a large number of parameters are
set for DMA channels 4 and 5. Find the following command line for channel 5
(I2S write):
This line specifies the address
where the data from the CODEC will be written in the DSP memory as it is transferred.
Hover the mouse pointer over the I2S2TXRT0 definition and perform the Open
Definition Declaration command. This action takes you to the place in the code where
this address is defined and shows that the destination address is 0x2A0C.

Peripheral Registers
 7. Halt the program using the button. Open the Registers window and locate the
different registers related to the peripherals. You should see a long list, starting
with DMA0 and going on for the different peripherals. Explore the sub-menus to
see the extent of parameters available for the peripherals.
 8. Have a look at the TIMER0 register menu. Observe that there is an enable bit to
activate the timer. (TIMER0 ▶ TCR ▶ TIMEN). Enable the timer by setting this
bit to 1. Set the PSCDIV register to 0x9. Start the timer by setting the START bit
to 1.
Press the arrow a few times and observe the result on the TIMCNT1 and
TIMCNT2 registers. TIMCNT2 should decrease steadily with every click on the arrow
as the timer decreases its counter.
 9. Locate the I2S2 register menu and expand it. Expand the I2SSCTRL menu and
locate the ENABLE bit. This bit should be set to 1. Clear the ENABLE bit to 0.
This will deactivate the I2S peripheral used in this application.
 10. Press the run button to run the program.Press the button to play back the
recorded signal. What do you obtain?
a..................................................................................................................No
Audio playback
53
b..................................................................................................................Au
dio playback
Choose Answer:a

Press the button to activate the recording mode and record a new signal.
 11. Halt the program using the button and set the ENABLE bit to 1 (I2S2 ▶
I2SSCTRL ▶ ENABLE) to reactivate the I2S peripheral.
 12. Press the run button to run the program. Press the button to play back the
recorded signal. What do you obtain?
a..................................................................................................................Ne
wly recorded Audio playback
b..................................................................................................................Pre
viously recorded Audio playback
Choose Answer:b

 13. Halt the program using the button. In the Registers window, edit the DMA1 ▶
DMACH1DSAL parameter to 0x2A0D. This changes the destination address for
data transiting through DMA channel 5 towards the CODEC.
 14. Press the run button to run the program. Press the button to play back the
recorded signal. What do you obtain?
a..................................................................................................................Au
dio playback
b..................................................................................................................No
Audio playback
Choose Answer:b

Press the button to play back the recorded signal.


 15. Halt the program using the button. In the Registers window, edit the DMA1 ▶
DMACH1DSAL parameter to 0x2A0C. This corrects the destination address for
data transiting through DMA channel 5 towards the CODEC.
 16. Press the run button to run the program. Press the button to play back the
recorded signal. What do you obtain?
a..................................................................................................................Au
dio playback
b..................................................................................................................No
Audio playback
Choose Answer:a

54
Changing the destination address of DMA channel 5 made the transfer of data
from the DSP to the CODEC impossible, but the data could still go from the CODEC to
the DSP via channel 4.
 17. Click on the icon to terminate the execution of the program. Return to the
projects tab and quit Code Composer. Turn OFF the power supply and remove the
connections (leads) you made on the circuit board.

3.2.3. Review Questions


1. Which component processes the audio signals?
a. I<sup>2</sup>C
b. CODEC
c. I<sup>2</sup>S
d. DMA Controller
Choose Answer:b

2. The I2C of the DSP communicates with the CODEC to transfer:


a. sound data.
b. configuration data.
c. interrupts.
d. All of the above
Choose Answer:b

3. The GPIO peripheral makes possible the use of:


a. the DIP switch.
b. the LCD.
c. Both a. and b.
d. c. and flash memory
Choose Answer:c

4. Initialization functions are used to:


a. the DIP switch.
b. the LCD.
c. Both a. and b.
d. c. and flash memory
Choose Answer:b

55
5. DMA channels 4 and 5 are used to:
a. set different parameters.
b. set registers related to peripherals.
c. make the use of peripherals possible.
d. All of the above
Choose Answer:d

3.3. Unit Test

1. Which peripheral is used to move data between the different parts of memory and the
other peripherals?
a. I²C
b. DMA
c. RTC
d. Timer
Choose Answer:a

2. Which peripheral is used as an interface between the DSP and other devices connected
by a two-wire bus?
a. I²C
b. DMA
c. RTC
d. Timer
Choose Answer:a

3. Which peripheral contains general-purpose 32-bit timers used to schedule periodic or


delayed DSP tasks?
a. I²C
b. I²S
c. RTC
d. Timer
Choose Answer:c

4. Which peripheral is used to configure DSP pins to be used as inputs or Outputs?


a. I²C
b. I²S

56
c. GPIO
d. USB
Choose Answer:a

5. Which peripheral is used as an interface for the acquisition of audio signals or to drive
loudspeakers?
a. I²C
b. I²S
c. GPIO
d. SAR
Choose Answer:b

6. Which peripheral is used to support a liquid crystal screen?


a. SPI
b. eMMC
c. SAR
d. LCDC
Choose Answer:a

7. Which peripheral is used to convert an analog input signal to a digital value?


a. SPI
b. eMMC
c. SAR
d. GPIO
Choose Answer:a

8. Which peripheral is used to allow removable data storage on a DSP?


a. SPI
b. eMMC
c. SAR
d. GPIO
Choose Answer:a

9. Which peripheral is used to communicate between the DSP and external peripherals?
a. SPI
b. LCDC
57
c. RTC
d. I²S
Choose Answer:c

10. The CODEC


a. is an external peripheral.
b. communicates with the I2C of the DSP.
c. communicates with the I2S of the DSP.
d. All of the above.
Choose Answer:d

58
BÀI 4: DSP Real-Time Processing

4.1. DSP Real-time Processing: Fundamentals


o Sampling and Analog/Digital Conversion
o Using Transforms
o Fourier Transforms
o Types of Fourier Transforms
o Using FFT Library Functions

4.2. EX01: Sampling and Analog-to-Digital/Digital-to-Analog Conversion

4.2.1. Discussion: Sampling and Analog-to-Digital/Digital-to-Analog


Conversion
o Analog and Digital Signals
o Analog-to-Digital Conversion
o A/D and D/A Converters
o The Importance of Sampling Rate
o Digital-to-Analog Conversion

4.2.2. Procedure: Sampling and Analog-to-Digital/Digital-to-Analog


Conversion
The Sampling Application Used in This Exercise
An analog signal with a maximum amplitude of approximately ±0.75 Vpeak must
be applied to the ANALOG INPUT. This signal is filtered by the antialiasing filter.
Note: Voltages greater than ±0.8 Vpeak may result in clipping.
The CODEC continuously samples the filtered ANALOG INPUT at a sampling
rate determined by the INPUT DIP switch and performs the A/D conversion to obtain the
digital data. (The sampling rate changes immediately when you change the DIP switch
setting; it is not necessary to press in interrupt button.)
The CODEC immediately performs D/A conversion of the digital data. The output
voltage is held constant between samples. The post filter filters the D/A converted signal
in an attempt to reconstruct the analog signal by filtering out the replicas.
Two output modes are available: Waveform and Spectrum:
o Waveform mode: The reconstructed analog signal is available at the ANALOG
59
OUTPUT. This waveform can be observed on an oscilloscope.
o Spectrum mode: The frequency spectrum of the reconstructed analog signal is
available at the ANALOG OUTPUT. This frequency spectrum can be
observed on an oscilloscope.
The output mode is selected using the button. The selected output mode is
displayed on the LCD.
The anti-aliasing filter at the input of the CODEC and the post-filter at the output
of the CODEC can be turned on or off together using the button.
The LCD displays the sampling rate, the output mode and the state of the filters.
 1. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C.
Set the INPUT DIP switch to 0000 0000. Launch Code Composer on your
computer.
 2. Make Exercise_4_1 the active project simply by clicking on that project in the
Project Explorer window. Open both the interrupt.c file of this exercise
If the Breakpoints window is not visible, choose Breakpoints in the View menu. If
any breakpoints are shown in this window, right-click in the window and select Remove
All.
Launch the Debug mode by clicking the icon to load the program into the DSP.
 3. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board:
LabVolt 91031 Ex4-1
Sampling
Rate = 12000.0 Hz
Waveform,Filters OFF
 4. Make the connections as shown. The output of the signal generator should be
connected to Ch 1 of the oscilloscope. The ANALOG OUTPUT of the CODEC
should be connected to Ch 2.
 5. This Table shows the DIP switch settings to use for the different sampling rates.
The application has an effective internal sampling rate of 12 000 Hz (12 000
samples per second). Lower sampling rates are obtained by decimating the samples
by a factor that varies from 1 to 9.
The LCD displays the sampling Rate. It also displays the output mode (Waveform
or Spectrum) and the state of the anti-aliasing filter and post-filter (Filters OFF or Filters
ON).
60
Use the DIP switch to set the sampling rate to 12 000 Hz (DIP SW: 0000 0001).
Use the button to set the output mode to Waveform.
Use the button to turn the filters OFF.
Adjust the signal generator to produce a sine wave message signal with an
amplitude of 0.7 V peak.
Set the frequency ƒm of the sine wave to 300 Hz.
Our Figure shows an example of what you should observe on the oscilloscope.
How does the output signal compare to the input signal?
a..................................................................................................................Th
e output signal is a stepped waveform that has twice the frequency as the input
signal.
b..................................................................................................................Th
e output signal is a stepped waveform at one half the frequency as the input signal.
c..................................................................................................................Th
e output signal is a stepped waveform that has the same shape and frequency as the
input signal.
Choose Answer:c

 6. Use the cursors on the oscilloscope to determine the sampling period, that is, the
duration of each step in the output waveform. Then calculate the sampling rate.
Approximate sampling period Ts = 0.084
ms
The approximate sampling rate ƒs =1/T = 12000
Hz
 7. In code Composer, pause the program using the Halt button . In the file
interrupt.c, find the comment //Breakpoint #01. Set a breakpoint on the line
immediately below this comment by double-clicking to the left of the line number.
Press the run button to run the program. It will stop after acquiring samples from
the ANALOG INPUT signal, via the DMA buffer, and placing this data in the vector x.
You can display a graph of the vector x in Code composer. In the Tools menu,
choose Graph, then Single Time.
Set the parameters as shown in the Figure.
This Figure shows execution stopped at the breakpoint and shows an example
graph of the values in x. (The starting point of the waveform will be different each time
execution reaches this breakpoint.)
Does the graph of the values in x resemble the output signal waveform displayed
on the oscilloscope?

61
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 8. In Code Composer, deactivate or remove the breakpoint. Press the run button .
Use the button to turn the filters ON. What effect does the anti-aliasing filter
have under the present conditions?
a..................................................................................................................It
has little effect on the input waveform because its cutoff frequency (3100 Hz) is
much higher than the input signal frequency (300 Hz).
b..................................................................................................................It
has a large effect on the input waveform because its cutoff frequency (3100 Hz) is
much higher than the input signal frequency (300 Hz).
What effect does the post filter have under the present conditions?
c. No effect
d..................................................................................................................It
smoothes the steps of the output waveform.
Choose Answer:a

 9. Slowly increase the input signal frequency to approximately 3000 Hz. Does the
output signal resemble the original analog signal?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 10. Slowly increase the input signal frequency to approximately 4000 Hz. What
happens.
a..................................................................................................................Sin
ce the filters are ON, the output signal amplitude diminishes rapidly as the input
signal frequency increases beyond 3000 Hz.
b..................................................................................................................At
4000 Hz, the output signal amplitude is zero.
c..................................................................................................................All
of the above
Choose Answer:d

Determine the Nyquist rate for the selected sampling rate. F_Nyquest = ƒs/2
62
ƒs = 12000
ƒ_ Nyquest = 6000

What is the purpose of the anti-aliasing filter?


d. It removes high-frequency components from the input signal that could result
in aliasing.
e..................................................................................................................Sin
ce the 3-dB cutoff frequency of the filter is approximately 3100 Hz, the filter
completely removes frequencies above 4000 Hz.
f..................................................................................................................40
00Hz is well below the Nyquist rate.
g..................................................................................................................All
of the above
Choose Answer:d

 11. Set the sampling rate to 6000 Hz (set the DIP switch to 0000 0010). Our Figure
shows an example of what you should observe. Describe the output signal.
a..................................................................................................................a
sinusoidal waveform at a higher frequency than the input signal.
b..................................................................................................................a
sinusoidal waveform at a lower frequency than the input signal.
c..................................................................................................................a
sinusoidal waveform at the same frequency than the input signal.
Choose Answer:b

What is the frequency of the output waveform?


The frequency of the output waveform is 2000 Hz

Explain what has happened by answering the following:


The Nyquist rate is now ƒs/2 = 6000/2 = 3000 Hz.
d. True
e..................................................................................................................Fal
se
Choose Answer:a

Since the input signal frequency is greater than the Nyquist rate, aliasing has
occurred.
f. True

63
g..................................................................................................................Fal
se
Choose Answer:a

The output waveform is that of the first replica. Its frequency is ƒs – ƒm = 6000 -
4000 = 2000 Hz.
h. True
i...................................................................................................................Fal
se
Choose Answer:a

 12. Set the frequency of the input signal to 1000 Hz. Use the button to turn the
filters OFF. Set the sampling rate to each of the values in the Table while
observing the output waveform on the oscilloscope.

Describe the output waveform with the sampling rate set to 2000 Hz and explain
what is happening.
a..................................................................................................................Th
e output waveform exactly duplicates the input signal. Four samples are taken per
cycle.
b..................................................................................................................Th
e output waveform is almost a square wave at the same frequency as the input
signal. Four samples are taken per cycle.
c..................................................................................................................Th
e output waveform is almost a square wave at the same frequency as the input
signal. Two samples are taken per cycle.
Choose Answer:b

 13. Set the sampling rate to 1714 Hz (DIP SW: 0000 0111) and then to 1500 Hz (DIP
SW: 0000 1000). The output signal is a stepped waveform.
a..................................................................................................................Tru
e
b..................................................................................................................Fal
se
Choose Answer:b

64
What is the frequency of the output waveform?
The frequency of the output waveform is 500 Hz

Explain what has happened by answering the following:


The Nyquist rate is now ƒs/2 = 1500⁄2 = 750 Hz.
c. True
d..................................................................................................................Fal
se
Choose Answer:b

Since the input signal frequency ƒm is greater than the Nyquist rate, aliasing has
NOT occurred.
e. True
f..................................................................................................................Fal
se
Choose Answer:a

The output waveform is that of the first replica. Its frequency is ƒs – ƒm = 1500 -
1000 = 500 Hz.
g. True
h..................................................................................................................Fal
se
Choose Answer:a

Frequency-Domain Observations
Frequency domain observations can be made by placing the application in the
Spectrum mode. In this mode, the signal at the analog output of the CODEC contains a
frequency spectrum that can be displayed on a standard oscilloscope. This will allow you
to make qualitative observations in the frequency domain.
In this mode, when the filters are ON, the output signal is filtered by the post filter
before the spectrum is calculated. This allows you to display the spectrum of the filtered
signal.
 14. Use the DIP switch to set the sampling rate to 12000 (DIP SW: 0000 0001). Use
the button to set the output mode to Spectrum. Use the button to turn
the filters OFF. Adjust the output level of the signal generator to 0 V.
On the oscilloscope:
o set the Time Base to 0.5 ms/div.

65
o set the Channel 2 Scale to 50 mV/div.<
o set the Trigger Source to Ch 2, set the Trigger Slope to Falling and set the
Trigger Level to approximately -0.05 V.
The oscilloscope should trigger on a negative peak. If necessary, move the
horizontal trigger point in order to see this peak, as shown in our Figure.
 15. Move the horizontal trigger position to the extreme left side of the graticule.
Adjust the signal generator to produce a sine wave message signal with an
amplitude of 0.7 Vpp. Set the frequency ƒm of the sine wave to 1000 Hz. You
should see a positive peak near the middle of the first division, as shown in the
Figure.
This positive peak represents a sinusoidal frequency of 1000 Hz. Show the vertical
cursors and position a vertical cursor at the center of this positive peak. Do not move this
cursor for the rest of this exercise. The oscilloscope should indicate the horizontal
position of this cursor in ms.
The extreme left side of the Ch 2 trace corresponds to 0 Hz (dc). The position in
ms of the cursor you moved over the positive peak corresponds to 1000 Hz.
 16. Set the frequency ƒm of the input message signal to 3000 Hz. The left-most
positive peak should now be in the second division of the graticule and three other
peaks should be visible, as shown in this Figure.Position a second vertical cursor
vertical at the center of the left-most positive peak, as shown in the same Figure.
This horizontal position corresponds to 3000 Hz. (Do not move the cursor at 1000
Hz.)
Enter the horizontal position (in ms) that corresponds to 3000 Hz in the first row of
the Table.
Use the second cursor to determine the horizontal position of the three other peaks
and enter these in the Table.
The frequency scale of the Spectrum display is roughly 4500 Hz/ms. Use this scale
to determine the approximate frequencies of the last three positive peaks in the Table.

Peak (from Horizontal position Frequency Fpeak Frequency calculation


the left) (ms) (Hz) fpeak in tearms of
fm,fs

1 0.70 3000 ƒp = fm = fs

2 2.03 9000 ƒp = fs - fm

3 3.35 15000 ƒp = fs + fm

66
4 4.7 2100 ƒp = 2fs - fm

 17. Position the second cursor at 3000 Hz, as shown in the Figure. This cursor and the
one at 1000 Hz will serve as frequency references. Set the frequency of the input
sine wave to the first frequency in our Table. Set the sampling rate to 6000 Hz
(DIP SW: 0000 0010). What is the Nyquist rate for the current sampling rate?
a..................................................................................................................20
00
b..................................................................................................................30
00
c..................................................................................................................60
00
Choose Answer:b

 18. While observing the frequency spectrum on the oscilloscope, set the frequency of
the sine wave to the other frequencies in our Table. Explain what happens as the
input sine wave frequency approaches the Nyquist rate:
As the sine wave message signal frequency increases, its peak in the spectrum
display moves to the right. At the same time, the peaks in the first replica spread apart.
a..................................................................................................................Tru
e
b..................................................................................................................Fal
se
Choose Answer:a

Explain what happens as the input sine wave frequency reaches the Nyquist rate:
c. The first replica is much lower than that of the message signal because of
aliasing.
d..................................................................................................................Th
e message signal and the lower component of the first replica coincide.
Choose Answer:b

Explain what happens as the input sine wave frequency goes above the Nyquist
rate.
e. The lower component of the first replica moves below the message signal
frequency and aliasing occurs.
f..................................................................................................................Th
e message signal and the lower component of the first replica coincide.

67
Choose Answer:b

 19. With the input message signal frequency set to 5000 Hz, set the Mode to
Waveform. Describe what you observe.
a..................................................................................................................Th
e output waveform is a step waveform with a frequency of 1000 Hz.
b..................................................................................................................Th
e output waveform is a step waveform with a frequency of 2500 Hz.
c..................................................................................................................Th
e output waveform is a step waveform with a frequency of 5000 Hz.
Choose Answer:c

Using the current configuration, turn the filters ON and explain what you observe:
The post filter smoothes the output waveform. However, the frequency of this
waveform is much higher than that of the input waveform because of aliasing.
d. True
e..................................................................................................................Fal
se
Choose Answer:a

The frequency of the output waveform is that of the lower component of the first
replica, that is, ƒs – ƒm = 6000 - 5000 = 1000 Hz.
f. True
g..................................................................................................................Fal
se
Choose Answer:a

 20. Set the frequency of the input sine wave to 2250 Hz. Turn the filters ON and OFF.
Compare the input and output signals when the filters are ON. Does the post filter
correctly reconstruct the output signal?
a..................................................................................................................Ye
s, the output signal has the same frequency as the input signal.
b..................................................................................................................No,
the output signal has a different frequency than the input signal.
Choose Answer:a

Set the mode to Spectrum.


On the oscilloscope, adjust the Channel 2 Scale to 50 mV/div. Turn the filters ON

68
and OFF while observing the spectrum of the output signal. How does the post filter
reconstruct the output signal? In the absence of aliasing, the post filter filters out the high-
frequency replicas leaving only the message signal.
c. True
d..................................................................................................................Fal
se
Choose Answer:aâ

 21. Click on the icon (next to the Run icon) to terminate the execution of the
program. Return to the projects tab and quit Code Composer. Turn OFF the power
supply and remove the connections (leads) you made on the circuit board.

4.2.3. Review Questions


1. Why is it necessary to sample an analog signal before processing it with a DSP?
a. A DSP is a digital device that processes discrete values.
b. A DSP cannot process continuous values.
c. A DSP works with finite value sets not infinite value sets
d. All of the above
Choose Answer:da

2. When sampling an analog signal, to ensure that the samples adequately represent the
analog signal the Sampling Theorem must be respected, that is, all frequency
components in the analog signal must be less than one-half the sampling rate.
a. True
b. False
Choose Answer:a

3. To ensure that the samples adequately represent the analog signal the Sampling
Theorem must be respected. What measures could be taken if this condition is not
respected?
a. The sampling rate could be increased to a rate higher than twice the
highest frequency.
b. An anti-aliasing filter could be used to remove frequencies in the analog
signal that are greater than the Nyquist rate.
c. Both a and b
Choose Answer:c

69
4. What is the purpose of the post filter at the output of a D/A converter?
a. To remove the replicas in the D/A converted signal.
b. To keep only the desired message signal.
c. To smooth the waveform.
d. All of the above
Choose Answer:d

5. What happens between samples at the output of a D/A converter and how does this
affect the D/A converted signal.
a. The voltage at the output of the D/A converter remains constant
between samples.
b. The constant voltage at the output of the D/A converter causes the
frequency spectrum of the D/A converted signal to have a curved envelope with
nulls at multiples of the sampling frequency.
c. The constant voltage at the output of the D/A converter causes aperture
distortion (attenuation of the higher frequencies in the reconstructed signal).
d. All of the above.
e. None of the above.
Choose Answer:d

4.3. EX02: The FFT and Optimizing DSP Applications

4.3.1. Discussion: The FFT and Optimizing DSP Applications


o The Discrete Fourier Transform (DFT)
 The Discrete Fourier Transform (DFT): Introduction
 Basis Functions
 How It Works
 Correlation
 Correlation Formula For The Real DFT
 Calculating the Magnitude Spectrum
 More Examples
 Spectral Leakage
o The Fast Fourier Transform (FFT)

70
 The Fast Fourier Transform (FFT): Introduction
 Using the FFT
o Optimizing an FFT Application
 Optimizing an FFT Application: Introduction
 Library Functions
 Code Optimization
 Using Complier Intrinsics
 Optimizing With Compiler Options
 Hardware FFT Accelerator

4.3.2. Procedure: The FFT and Optimizing DSP Applications


The FFT Application Used in the Exercise
The application used in this exercise has the following characteristics:
o An analog signal with an amplitude not greater than ±0.9 Vpeak must be
applied to the ANALOG INPUT.
o The CODEC samples the ANALOG INPUT at a sampling rate ƒs = 8000
samples/s to obtain blocks of 64 (real) data values.
o The real data values are interleaved with zeros to produce a vector of 64
complex values (128 numbers in interleaved Re Im format).
o A library function performs a 64-point complex FFT on the vector to obtain
the frequency-domain values. The frequency-domain results are placed in the
same vector in bit-reversed order.
o Another library function reorders the frequency-domain values in the normal
order.
o The magnitude spectrum of the first 20 points is calculated and displayed as a
bar graph on the LCD.
o The CODEC is also used as a built-in signal generator to produce a sinusoidal
signal that can be used for analysis. The frequency of this signal is selected
using the INPUT DIP switch.<
 1. Connect the DSP board to your computer using USB port number 2 on the board
and a standard USB port on your computer. Make sure that the circuit board power
source is turned ON and that the Code Composer software is installed as explained
in Appendix C. Launch Code Composer on your computer.
 2. Make Exercise_4_2 the active project simply by clicking on that project in the
Project Explorer window. Open both the main.c and interrupt.c files of this
exercise. If the Breakpoints window is not visible, choose Breakpoints in the View
menu. If any breakpoints are shown in this window, right-click in the window and
select Remove All.
71
 3. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board: LabVolt
91031 Ex4-2 / FFT and Optimization.

Using the Sine-Wave Signal Generator


This application includes a signal generator that can generate a sine-wave signal at
different frequencies. This signal is available at the ANALOG OUTPUT of the CODEC.
This section shows how to use the signal generator.
 4. Make the connections shown in Figure. With these connections, the generated
sine-wave signal is applied to the input of the Audio Amplifier and to the
oscilloscope.
 5. This Figure shows how to use the INPUT DIP switch on the I/O INTERFACE to
set the frequency of the sine wave generator.
The frequency of the generated sine wave is equal to the decimal value of the DIP
switch setting multiplied by 7.8125 Hz. Each bit set to 1 adds the frequency value shown
in our Figure. The resulting frequency is the sum of the frequencies corresponding to the
1 bits.
For example, to adjust the frequency to 250 Hz = 32 x 7.8125 Hz, set the DIP
switch to 32 (0010 0000b).
To adjust the frequency to 375 Hz = 48 x 7.8125 Hz, set the DIP switch to 48 = 32
+ 16 (0011 0000b).
To change the frequency, set the DIP switch to the desired value and press the
interrupt button.
Set the INPUT DIP switch to each of the values in the provided Table and verify
using the oscilloscope that you obtain the desired frequencies.

FFT Display
This application applies an FFT to the signal at the AUDIO INPUT in order to
calculate the frequency spectrum of the signal. The first 20 points of the magnitude
frequency spectrum are displayed as a bar graph on the LCD.
 6. Make the connections shown in the Figure. With these connections, the generated
sine wave is applied to the ANALOG INPUT of the CODEC. The DSP will
calculate the FFT of the input signal in real time and display the magnitude
frequency spectrum on the LCD as a bar graph.
The LCD can display four rows of 20 characters each. In this exercise, the last two
rows are used together to display a bar graph of the spectrum. The position of each bar in
the display corresponds to the center frequency of one of the frequency bins. Figure
shows a bar in position 2.
Our next Figure shows the 20 positions of the bar graph and the center frequency
72
of each corresponding frequency bin. Position 0 corresponds to the dc component of the
signal being analyzed.
Each bar in the frequency spectrum is composed of one or two block characters, as
shown. The height of each block character can range from 0 to 8 pixels, but the bottom
row of pixels is always displayed to mark the position. This means that the height of each
bar can range from 1 to 16 pixels.
The height of each bar represents the relative magnitude of the output of the
corresponding frequency bin. A bar 1 pixel high represents zero (the corresponding
frequency is absent) and a bar 16 pixels high represents the maximum displayed
magnitude for that frequency bin.
 7. Adjust the sine-wave generator to different frequencies and observe the displayed
spectrum. Start with the frequencies shown here.

Observing Output in Code Composer


 8. Set the frequency of the sine wave to 250 Hz (0010 0000b). In code Composer,
pause the program using the Halt button . If the Breakpoints window is not
visible, choose Breakpoints in the View menu. This window should be empty, as
shown.
In the main.c file, find the four breakpoint comments, but do not set the
breakpoints yet:
//Breakpoint #01
//Breakpoint #02
//Breakpoint #03
//Breakpoint #04
Set a breakpoint on the line immediately following //Breakpoint #01 by double-
clicking to the left of the line number. This breakpoint will appear in the Breakpoints
window as shown.
Right-click on the line of the breakpoint in the Figure and select Breakpoint
Properties in order to edit the name. Change the name of this breakpoint to Breakpoint
#01 and click on Edit Property.
In the main.c file, find the comment //Breakpoint #02, set the breakpoint on the
following line and immediately rename it. Do the same with //Breakpoint #03 and
//Breakpoint #04.
When you have finished, the Breakpoints window should resemble this Figure.
In the Breakpoints window, use the checkboxes to deactivate all breakpoints
except for Breakpoint #01, as shown here.
Press the run button to start execution of the code. Execution stops after the
73
comment //Breakpoint #01.
The if statement a little above the comment //Breakpoint #01 tests the value of the
variable flag_update_display.
This variable is set to 1 when new time-domain data has been acquired from the
CODEC. The vector fft_x_data contains the acquired data.
 9. You can view the acquired time-domain data in Code Composer. In the Tools
menu, choose Graph, then Single Time. Set the parameters as shown in this Figure.
Since the start address is set to fft_x_data and since both the Acquisition Buffer
Size and the Display Data Size are set to 128, all 128 values in the vector
fft_x_data will be graphed.
Here we see the line at which execution was halted and an example of the graph of
the acquired signal in fft_x_data.
The graph shows all 128 values contained in the vector fft_x_data. The horizontal
axis shows the sample numbers and the vertical axis shows the sample numbers that range
from 0 to 127.
The function used in this application to perform the FFT uses a complex valued
algorithm. The input vector for this function must consist of interleaved real and
imaginary values. (Refer to Arguments in the Table previously discussed.)
The data acquired by the CODEC, however, is real-valued; there are no imaginary
values. The complex-valued FFT algorithm can still be used, however, simply by making
all the imaginary values equal to zero. This is why every other sample in fft_x_data is
zero.
The 128 values in fft_x_data must therefore be interpreted as 64 complex values in
the interleaved Re-Im format: 64 real values (the data acquired by the CODEC)
interleaved with 64 imaginary values which are all equal to zero.
Our next Table shows how the contents in the vector fft_x_data should be
interpreted.

 10. In the toolbar of the graph window, click the graph properties button to
redisplay the Graph Properties dialog box.
You can graph just the real values in fft_x_data by setting Index Increment to 2
and the Display Data Size to 64, as shown. This graphs every other value in the vector,
starting with the first real value. Setting the Time Unit to ms shows time on the horizontal
axis.
Our next Figure shows the graph with these new settings. As expected, only the
real values, which were acquired by the CODEC, are graphed. All imaginary values (the
added zeros) are skipped.
 11. Clicking in the Single Time graph window displays two red cursors as well as the

74
values that these cursors represent. You can use these cursors to measure the
period of one cycle of the waveform, as shown.
Click in the graph window and carefully move horizontal cursor to the first sample
on the vertical axis and, while still holding down the mouse button, move the vertical
cursor to the intersection of the horizontal cursor and the next cycle of the waveform.
This displays the approximate period in milliseconds of the waveform.
Considering the frequency of the sine wave, is the observed period what you
would expect?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

Compare the period T of the sine wave to the duration in seconds of the time
window Twin. Where:

The window duration Twin equals?

c.

d.

e.
Choose Answer:a

The number of periods in the window is T<sub>win</sub> / 2 equals?


f. 8
g..................................................................................................................4
h..................................................................................................................2
Is this a whole number?
i. Yes
j...................................................................................................................No
Choose Answer:a

The waveform in the graph is shown as a continuous line. Is this the graph of a
continuous signal or of a discrete signal? (To check your answer, show the Graph

75
Properties dialog box and change the Data Plot Style from Line to Bar. Set Time Display
Unit to Sample.)
k. Continuous
l...................................................................................................................Dis
crete
Choose Answer:a

 12. In the Breakpoints window, check all four breakpoints. Press the run button .
The lines between //Breakpoint #01 and //Breakpoint #02 will be executed.
Before //Breakpoint #02, the library function cfft calculates the FFT of the data in
fft_x_data. This is a complex function that operates on N complex time-domain values
and outputs N complex frequency-domain values. This function performs an in-place
calculation which means that the results are placed in the vector that holds the input data.
The original contents of this vector are destroyed in the process.
Because of the way an in-place complex FFT algorithm works, the values in the
output vector are not in normal order. Instead these values are ordered in bit-reversed
order.
Since the purpose of this program is to display the spectrum on the LCD, the
complex values in this vector must be rearranged in their normal order. This is
accomplished by the cbrev function. This function reorders the data and places the results
in another vector fft_out.
 13. The vector fft_out contains the frequency domain values in interleaved Re-Im
format, as shown.
To graph these values in Code Composer, you should graph the real values and the
imaginary values separately.
In the Tools menu, choose Graph, then Single Time. Set the parameters as shown
in the new Figure. Since the real and imaginary values are interleaved, setting Index
Increment to 2 and Start Address to fft_out will graph only the real values.
Here we can see an example of the graph of the real values of the frequency-
domain information.
Recall that the time-domain representation of the waveform contained only real
values (all imaginary values were set to 0).
Describe the symmetry of the real values of the frequency-domain representation.
a..................................................................................................................Th
e real values of the frequency-domain representation have even symmetry about
the Nyquist frequency
b..................................................................................................................Th
e real values of the frequency-domain representation have odd symmetry about the
76
Nyquist frequency
c..................................................................................................................Th
ere is no symmetry
Choose Answer:c

Where are the peaks located?


d. The peaks are located at Re X [2] and Re X [52].
e..................................................................................................................Th
e peaks are located at Re X [12] and Re X [42].
f..................................................................................................................Th
e peaks are located at Re X [2] and Re X [62].
Choose Answer:c

What frequency does this correspond to based on the frequency of the first
(leftmost) peak?
g. -250 Hz
h..................................................................................................................25
0 Hz
i...................................................................................................................20
0 Hz
Choose Answer:b

 14. Display the Graph properties for this graph and set the Start Address to fft_out+1.
With Index Increment set to 2, this displays only the imaginary values Im X [ ].
Describe the symmetry of the imaginary values of the frequency-domain
representation.
a..................................................................................................................Th
e real values of the frequency-domain representation have even symmetry about
the Nyquist frequency
b..................................................................................................................Th
e real values of the frequency-domain representation have odd symmetry about the
Nyquist frequency
c..................................................................................................................Th
ere is no symmetry
Choose Answer:b

 15. Press the run button . The lines between //Breakpoint #02 and //Breakpoint #03
will be executed. The purpose of this application is to display the first 20 points of
the frequency magnitude spectrum on the LCD. This is calculated by the following
77
code:

The for loop initializes the variables i and j to 0.


Each pass of the loop takes two consecutive values from the vector fft_out and
squares them:
o The loop takes the value in fft_out[j] (a real value) and multiplies this value by
itself to obtain the square. The result is stored in the variable a. Then j is
incremented.
o The loop again takes the value in fft_out[j] (an imaginary value) and multiplies
this value by itself to obtain the square. The result is stored in the variable b.
Then j is incremented.
o The variables a and b are added together and stored in fft_out[i], overwriting
the original ith value of this vector. The loop then increments i and repeats.
When all 20 passes have been completed the first 20 values of fft_out each
contain the magnitude squared of a spectral point.
To graph the first 20 values of fft_out, Change the graph properties as shown.
 16. Press the run button . The lines between //Breakpoint #03 and //Breakpoint #04
will be executed.
The function sqrt_16 acts on the first 20 values of fft_out, taking the square root of
each value and placing the result in the corresponding position of the vector root. After
this line has been executed, root contains a 20-point frequency magnitude spectrum.
Graph the first 20 values in root, using the Graph Properties shown here.The graph
should resemble our sample shown.
 17. The for loop after //Breakpoint #04 uses the values in root to place the appropriate
block characters in the character arrays line3 and line4. These character arrays are
sent to the LCD using the function updateDisplay. The LCD displays the block
characters in lines 3 and 4 of the LDC in order to display a spectrum.
Press the run button . The for loop after //Breakpoint #04 will execute, and then
the LCD will be updated. (Execution will stop after //Breakpoint #01.)
Compare the graph of root with the spectrum displayed on the LCD.

78
Spectral Leakage
 18. Clear all breakpoints and then press the run button . Set the frequency of the
generated sine wave to 1000 Hz (1000 0000b). Describe the spectrum on the LCD.
The spectrum has the following:
a..................................................................................................................tw
o components in positions 2 (250 Hz) and 8 (1000 Hz)
b..................................................................................................................one
component in position 8 (1000 Hz)
c..................................................................................................................one
component in position 7 (875 Hz)
Choose Answer:b

 19. Pause the program using the Halt button .


Activate Breakpoint #02, then press the run button. The program will stop after
computing the FFT and reordering the data.
Code Composer allows you to detach windows and position them anywhere on the
screen. Create two new graphs, one with the properties shown with the Start Address set
to fft_out, and one with the same properties except with the Start Address set to
fft_out+1.
Right-click in the title bar of one of the graph windows and select Detach. Move
this window to the right side of the screen side. Do the same in the other graph window.
Then position the two windows so you can see their contents simultaneously. Here you
see an example. The sampling rate ƒs = 8000 samples/s and 64 complex samples are
processed by the FFT at a time. Determine the duration of the time window Twin:
Twin = N / ƒs = ?
a..................................................................................................................8
ms
b..................................................................................................................16
ms
c..................................................................................................................10
ms
Choose Answer:a

How many periods of the sine wave signal waveform fit inside the time window?
d. Twin / T = 16 ms/1 ms = 16
e..................................................................................................................Tw
in / T = 8 ms/10 ms = 0.8
f..................................................................................................................Tw
79
in /T = 8 ms/1 ms = 8
Choose Answer:c

Is this a whole number?


g. Yes
h..................................................................................................................No
Choose Answer:a

 20. Clear all breakpoints and then press the run button . Set the frequency of the
generated sine wave to 1062.5 Hz (1000 1000b). Describe the spectrum on the
LCD.
a..................................................................................................................Th
e spectrum has a strong component in position 8 (1000 Hz).
b..................................................................................................................Th
e spectrum has a strong component in positions 8 (1000 Hz) and 9 (1125 Hz), as
well as tails to either side.
Choose Answer:b

Pause the program using the Halt button . Activate Breakpoint #02 and press the
Run button . Which two (2) sample graph sets more closely represent the two
frequency-domain graphs you observe in Code Composer.

c. and c.
d..................................................................................................................and
c.
e..................................................................................................................and
b.
Choose Answer:b

LCD display for 1062.5 Hz


What explains the tails in the spectrum on the LCD?
The period of the sine wave signal is T = 1/1062.5 Hz = 0.94 ms. The number of
periods in the window is Twin / T = 8.5, which is not a whole number.
When the sine-wave frequency is centered on a frequency bin, as in The previous
graph set c), only that bin produces an output. When the frequency is between two bins,
80
however, there is an output in a number of bins. This is due to the fact that the FFT treats
the time sampled data as if it were periodic. Since the number of periods of the sine wave
signal in the time window is not a whole number, there is a discontinuity in the signal as
seen by the FFT algorithm. This discontinuity gives rise to a large number of harmonics
which appear as “tails” in the spectrum.

Optimization
 21. Look at the two lines following //Breakpoint #01 in the main.c file. Referring to
the Discussion, what library functions are called in these two lines?
a..................................................................................................................cfir
and cfft32
b..................................................................................................................ciff
t and convol2
c..................................................................................................................cfft
and cbrev
Choose Answer:c

What does the cfft function do?


d. It computes a complex nx-point iFFT on vector x, which is in normal-order.
The original content of vector x is destroyed in the process. The nx complex elements
of the result are stored in vector x in bit-reversed order.
e..................................................................................................................It
accepts a vector containing complex time-domain values and performs the
complex FFT algorithm in place and the frequency-domain results are stored in the
same vector in bit-reversed order and in interleaved Re-Im format.
Choose Answer:a

The cbrev function bit-reverses the elements in a complex vector in order to place
the frequency-domain values in the normal order.
f. True
g..................................................................................................................Fal
se

What is the advantage of using library functions for these operations, rather than
programming the functions from scratch?
h. Library functions are ready-to-use functions that can be that can considerably
shorten development time.
i...................................................................................................................Lib
rary functions are highly optimized assembly language functions.
81
j...................................................................................................................Lib
rary functions execute faster than functions programmed in a high-level language.
k..................................................................................................................All
of the above
Choose Answer:c

 22. Find the #pragma directives in the main.c file. The DATA_SECTION pragma
allocates space for a symbol in a section named section name. The syntax for the
DATA_SECTION pragma is as follows:
#pragma DATA_SECTION (symbol, “section name”) [;]

As was shown in previous tables in the Discussion, the input data for the library
functions cfft and cbrev must be aligned on a 32−bit (4-byte) boundary. This is
accomplished by the text align(4) in the definition of the section .input.
Is it important to respect requirements such as this?
a..................................................................................................................Ye
s
b..................................................................................................................No
Choose Answer:a

 23. Look at the for loop after //Breakpoint #02 in the main.c file.
In this loop, certain functions are called whose names begin with an underscore.
Example: The functions _smpy and _sadd.
What types of functions are these?
a..................................................................................................................co
mpiler intrinsics
b..................................................................................................................inli
ne assembly
c..................................................................................................................Ob
ject
Choose Answer:a

What is the advantage of using this type of function?


d. they directly access assembly language statements.
e..................................................................................................................the
optimizer has a built-in knowledge of how they behave so optimizations are
82
available
f..................................................................................................................the
optimizer can expand them differently, align buffers, or make other adjustments
depending on the context and arguments of the call
g..................................................................................................................All
of the above
Choose Answer:a

 24. In the C/C++ Projects window of Code Composer, right-click on exercise_4_2 and
choose Properties.
In the Properties for exercise_4_2 window, click C/C++ Build.
In the list, under C5500 Compiler, click Basic Options. This shows, among other
things, the selected Optimization level.
What is the optimization level selected?
a..................................................................................................................Op
timization level 1
b..................................................................................................................Op
timization level 2
c..................................................................................................................Op
timization level 3
d..................................................................................................................Op
timization level 4
Choose Answer:c

Analyzing an External Signal


 25. If you wish, you can show the spectrum of an external time-varying signal.
Remove the cables connected to the ANALOG OUTPUT
Turn the Gain of the Microphone Pre-Amplifier to MIN.
Connect an audio signal to the Microphone Pre-Amplifier INPUT and connect the
OUTPUT to the ANALOG INPUT of the CODEC.
In Code Composer, uncheck all breakpoints. Then press the run button .
Make sure that audio is present at the AUDIO INPUT. Slowly increase the Gain of
the Microphone Pre-Amplifier until you see a spectrum on the LCD.
 26. Click on the icon (next to the Run icon) to terminate the execution of the
program. Return to the projects tab and quit Code Composer.
 27. Turn OFF the power supply and remove the connections (leads) you made on the
circuit board
83
4.3.3. Review Questions
1. The time-domain representation shows how a signal's amplitude varies with time. The
frequency-domain representation shows what frequency components are present in the
signal and what their amplitudes are.
a. True
b. False
Choose Answer:a

2. A DFT analyzes a discrete time-domain signal by comparing (correlating) the signal


with a number of cosine and sine waveforms of known frequencies. These waveforms
are called:
a. Intrinsic functions
b. Basis functions
c. Library functions
d. None of the above
Choose Answer:b

3. In the DSP program, the DFT or FFT library function returns a vector containing a
series of numbers. What do these numbers represent?
a. The amplitude coefficients corresponding to each of the basis functions,
as calculated by the library function.
b. The frequency parameter
c. Both a. and b.
Choose Answer:a

4. Which of the following could be considered an advantage of the FFT algorithm as


compared to the DFT using the correlation method?
a. The FFT algorithm is much more efficient than the DFT correlation
method.
b. The FFT requires far fewer steps and executes much faster than the
DFT correlation method.
c. Both a. and b.
Choose Answer:c

5. Which of the following is NOT a method of optimizing a DSP FFT application?


a. using the optimized library functions

84
b. using regular functions
c. using compiler intrinsics
d. selecting the appropriate compiler optimization options
e. using a hardware FFT accelerator built into the CPU of the DSP
Choose Answer:e

4.4. Unit Test

1. A compact audio disk (CD) contains audio signals that were sampled at a rate of 44
100 Hz. In theory, what is the highest frequency that can be encoded on a CD.
a. 88 200 Hz
b. 44 100 Hz
c. 22 050 Hz
d. 11 025 Hz
Choose Answer:a

2. Aliasing can be prevented by


a. increasing the resolution of the D/A converter.
b. lowering the cutoff frequency of the post filter.
c. low-pass filtering the analog signal before sampling.
d. using a library function to process the digital data.
Choose Answer:a

3. The output signal of a D/A converter is low-pass filtered in order to


a. remove distortion due to aliasing.
b. remove the frequency components of the replicas.
c. compensate for aperture distortion.
d. remove quantization noise.
Choose Answer:b

4. The numbers returned by an FFT algorithm represent


a. the amplitude coefficients corresponding to the basis functions.
b. the magnitude of the frequency spectrum versus the frequency.
c. the synthesis of the basis functions.
d. the frequencies of the basis functions.
Choose Answer:a
85
5. Approximately how many steps are required to perform an N-point DFT using the
correlation method?
a. 2N
b. N/2 + 1
c. N2
d. N log2 N
Choose Answer:d

6. Approximately how many steps are required to perform an N-point FFT using the
correlation method?
a. 2N
b. N/2 + 1
c. N2
d. N log<sub>2</sub> N
Choose Answer:a

7. Compared to a DFT using correlation, an FFT


a. produces virtually the same results.
b. is easier to program from scratch.
c. requires a larger number samples.
d. takes longer to execute.
Choose Answer:a

8. An FFT library function returns a vector of complex numbers X[ ] representing the


frequency domain information. If k is the frequency parameter, then each complex
number X[k] in the vector has two parts called the real part Re X[k] and the imaginary
part Im X[k]. The magnitude spectrum M[ ] can be obtained by performing the
following calculation for each k:
a. M[k] = Re X[k]
b. M[k] = Re X[k] + Im X[k]
c. M[k] = log2(Re X[k] + Im X[k])
d.
Choose Answer:c

9. Spectral leakage occurs when


a. the sampling rate is does not respect the Nyquist criterion.
86
b. a frequency component lies between adjacent frequency bins.
c. the post filter is incorrectly adjusted.
d. too many basis functions are used.
Choose Answer:b

10. Using library functions for computing transforms


a. requires additional computing power.
b. can increase execution speed and shorten development time.
c. requires a thorough comprehension of the algorithms used in the
functions.
d. requires special hardware devices.
Choose Answer:a

87
BÀI 5:
5.1. Signal Processing Applications: Fundamentals
o Signal Processing Applications

5.2. EX01: Applications - FIR and IIR Filters

5.2.1. Discussion: Applications - FIR and IIR Filters


o Time and Frequency Domains
o Filters
o Digital Filters

5.2.2. Procedure: Applications - FIR and IIR Filters


Set Up and Connections
 1. Perform the connections shown in the Figure. The CODEC is designed for low-
voltage signals with a maximum input voltage of ±0.9 V. When using an external
signal source, make sure the voltage at the ANALOG INPUT is within this range.
 2. Connect the DSP board to your computer using USB port number <b>2</b> on
the board and a standard USB port on your computer.
Make sure that the circuit board power source is turned ON and that the Code
Composer software is installed as explained in Appendix C. Launch Code Composer on
your computer.
 3. Make Exercise_5_1 the active project simply by clicking on that project in the
Project Explorer window.
Open both the main.c and interrupt.c files of this exercise. Launch the Debug mode
by clicking the icon to load the program into the DSP.
 4. In the interrupt.c file, find the section where the filter coefficients are listed.
How many coefficients are listed?
a..................................................................................................................16
b..................................................................................................................32
c..................................................................................................................64
d..................................................................................................................72
Choose Answer:c

What is the order of this FIR filter?

88
e. 15
f..................................................................................................................63
g..................................................................................................................31
h..................................................................................................................5
Choose Answer:c

 5. Press the run button to run the program on the board. At this point, you should
see the following information on the LCD of the DSP circuit board: LabVolt
91031 Ex5-1 / FIR Filter

Testing the FIR Filter


 6. Use a signal generator to produce a sinusoidal waveform of an amplitude of 0.4 V
and a frequency of 100 Hz. Observe both the input signal (Channel 1) and the DSP
output signal (Channel 2) on an oscilloscope.
 7. Use the oscilloscope to measure the amplitude of the output signal (Channel 2) as a
function of the frequency of the input signal. Calculate the gain and fill in the
Table. Remember that the Gain = 20 ∙ log (Aout/Ain), where Ain = 0.4 V. The
system will plot a graph of the gain as a function of the frequency.
Frequency (Hz) Output Voltage (V) Gain (dB)

100 0.55 2.8

200 0.55 2.8

300 0.55 2.8

400 0.55 2.8

500 0.55 2.8

600 0.55 2.8

700 0.55 2.8

800 0.54 2.6

900 0.54 2.6

1000 0.54 2.6

1100 0.48 1.6

1200 0.30 -2.5

1300 0.10 -12.0

89
1400 0.03 -22.5

1500 0.03 -22.5

1600 0.03 -22.5

1700 0.03 -22.5

1800 0.03 -22.5

1900 0.03 -22.5

2000 0.03 -22.5

 8. Based on the graph obtained, the FIR filter used in this example is a what kind of
filter?
a..................................................................................................................A
band-pass filter
b..................................................................................................................A
high-pass filter
c..................................................................................................................A
low-pass filter
Choose Answer:a

 9. What is the cutoff frequency of this filter?


a..................................................................................................................Ar
ound 1150 Hz
b..................................................................................................................Ar
ound 800 Hz
c..................................................................................................................Ar
ound 1350 Hz
Choose Answer:a

 10. Click on the icon to terminate the execution of the program.

Testing the IIR filter


 11. Make exercise_5_1b the active project simply by clicking on that project in the
Project Explorer window.
Open both the main.c and interrupt.c files of this exercise.
Launch the Debug mode by clicking the icon to load the program into the DSP.
 12. In the interrupt.c file, find the section where the filter coefficients are listed. How
many coefficients are listed?

90
a..................................................................................................................10
discrete coefficients are listed
b..................................................................................................................No
coefficients are listed
c..................................................................................................................5
coefficients are listed twice
Choose Answer:c

The coefficients are given in this order: b2, b1, b0, a2, and a1. They are written as
natural numbers but are used in Q31-format in the algorithm. Coefficient a0 is implicitly
taken to have a value of 1.
The transfer function of the filter used, sometimes known as a biquad, looks like
this:
The coefficients are repeated because the biquad transfer function is used twice (or
cascaded) to produce the final IIR filter.
What are the P and Q orders of a single instance of the transfer function?
d. P = 2 and Q = 2
e..................................................................................................................P =
2 and Q = 1
f..................................................................................................................P =
1 and Q = 2
Choose Answer:a

What are the orders for the complete IIR filter (two consecutive biquads)?
g. P = 2 and Q = 2
h..................................................................................................................P =
4 and Q = 4
i...................................................................................................................P =
4 and Q = 2
Choose Answer:b

 13. Press the run button to run the program. At this point, you should see the
following information on the LCD of the DSP circuit board:
LabVolt 91031 Ex5-1b / IIR Filter
 14. Use a signal generator to produce a sinusoidal waveform with an amplitude of 0.4
V and a frequency of 100 Hz. Observe both the input signal (Channel 1) and the
DSP output signal (Channel 2) on an oscilloscope.
 15. Use the oscilloscope to measure the amplitude of the output signal (Channel 2) as a
91
function of the frequency of the input signal. Calculate the gain and fill in the
Table.
Observe both the input signal (Channel 1) and the DSP output signal (Channel 2)
on an oscilloscope.
Remember that the Gain = 20 ∙ log (Aout / Ain), where Ain = 0.4 V.
The system will plot a graph of the gain as a function of the frequency.

Frequency (Hz) Output Voltage (V) Gain (dB)

100 0.45 1.0

200 0.45 1.0

300 0.46 1.2

400 0.48 1.6

500 0.51 2.4

600 0.53 2.8

700 0.52 2.8

800 0.55 2.8

900 0.52 2.3

1000 0.44 0.8

1100 0.34 -1.4

1200 0.24 -4.4


44
1300 0.16 -8.0

1400 0.04 -13.0

1500 0.03 -16.5

1600 0.03 -22.5

1700 0.03 -22.5

1800 0.03 -22.5

1900 0.03 -22.5

2000 0.03 -22.5

Based on the graph obtained, the IIR filter used in this example is a what kind of
filter?
92
a..................................................................................................................A
band-pass filter
b..................................................................................................................A
low-pass filter
c..................................................................................................................A
high-pass filter
Choose Answer:b

What is the cutoff frequency of this filter?


d. Around 1450 Hz.
e..................................................................................................................Ar
ound 800 Hz.
f..................................................................................................................Ar
ound 1150 Hz.
Choose Answer:c

 16. Click on the icon to terminate the execution of the program.


 17. Turn OFF the power supply and remove the connections (leads) you made on the
circuit board.

5.2.3. Review Questions


1. Which of the following types of filters attenuates all signal frequencies below a certain
range and lets higher frequencies through?
a. Low-pass filter
b. Comb filter
c. Band-pass filter
d. High-pass filter
Choose Answer:d

2. Which of the following types of filters attenuates all signal frequencies below and
above a certain range?
a. Low-pass filter
b. Comb filter
c. Band-pass filter
d. High-pass filter
Choose Answer:c

93
3. A filter modifies the signal?
a. by applying a gain which is dependent upon the frequency.
b. by shifting the frequency contents of the signal to higher frequencies.
c. by shifting the frequency contents of the signal to lower frequencies.
d. All of the above
Choose Answer:a

4. Why are filters implemented on DSPs preferred over analog filtering circuits?
a. A digital circuit ensures reproducible results.
b. Analog filters do not exist.
c. DSP filters can be used on all types of signals.
d. All of the above
Choose Answer:a

5. Which of the following DSP instructions is the cornerstone of the implementation of a


real-time digital filter.
a. Logical “AND” instruction
b. Logical “OR” instruction
c. Subtraction instruction (SUB)
d. Multiply-and-Accumulate instruction (MAC)
Choose Answer:da

5.3. Unit Test

1. A DSP can be used to


a. process any signal.
b. process signals which can be sampled.
c. process signals which can be sampled and for which a digital signal
processing algorithm can be devised.
d. generate any analog signal.
Choose Answer:a

2. DSPs are
a. based on the mathematical theory of digital signal processing.
b. a tool to implement the findings of digital signal processing theory.
c. ubiquitous in many aspects of modern life.

94
d. All of the above.
Choose Answer:b

3. The output signal of a D/A converter is low-pass filtered in order to


a. filter low frequencies from an audio signal.
b. display webpages on an LCD screen.
c. perform database queries.
d. All of the above
Choose Answer:c

4. A DSP is likely to be a component in the equipment of an electric guitar player to


a. create echo effects in the sound produced.
b. add distortion to the sound.
c. adjust the frequency mix of an instrument.
d. All of the above
Choose Answer:d

5. A cell phone contains a DSP in order to?


a. manage the contact data of the user.
b. process the voice into a stream of data compatible with the cell
network.
c. play videogames.
d. All of the above
Choose Answer:d

95

You might also like