3 periodic signal generation

51
Digital Signal Processing Applications Using C6713 DSK Communications Laboratory – University of Kassel Project Work by Zemene Walle Mekonnen Supervisor: Dipl.–Ing. Thomas Edlich

Upload: ngomien

Post on 10-Dec-2016

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 3 Periodic Signal Generation

Digital Signal Processing Applications Using C6713 DSK

Communications Laboratory – University of Kassel

Project Work by

Zemene Walle Mekonnen

Supervisor: Dipl.–Ing. Thomas Edlich

Page 2: 3 Periodic Signal Generation

Project Description

DIGITAL SIGNAL PROCESSING APPLICATIONS

USING C6713 DSK

Digital Signal Processors (DSP) are designed for real-time digital signal processing. Using

DSPs offers great flexibility, reconfigurability and easy debugging capabilities. In this student

project, a first introduction to simple DSP applications shall be given to enable future users

quickly getting familiar with the DSP.

The work is based on the DSP Starter Kit C6713 DSK by Texas Instruments, which already

contains a high-quality 24-bit stereo codec including several audio connectors and an onboard

JTAG programming interface via USB. The development environment includes the

programming and debugging tool Code Composer Studio.

The first part of this student project is to get familiar with the DSP Starter Kit and the

development environment. This contains the usage of pre-programmed modules

(eXpressDSP) and the configuration of the real-time operating system DSP/BIOS. After this,

several baseband signals shall be generated with the DSP and put out using the audio

interfaces. Different visualization and interaction capabilities of the integrated development

environment shall be introduced. Finally, examples of real-time signal processing shall be

implemented. A detailed test of the generated programs and a well-documented description of

the implementation complete this work.

Activities: 30% theory, 50% programming, 20% tests and measurements

Prerequisites: basic knowledge of programming in C/C++, willingness to work autonomously, knowledge of programming microprocessors may be helpful

Supervisor: Thomas Edlich

i

Page 3: 3 Periodic Signal Generation

Declaration

To the best of my knowledge I do hereby declare that this documentation is my own work. It

has not been submitted in any form of another degree or diploma to any other university or

institution of education. Information derived from the published or unpublished work of

others has been acknowledged in the text and a list of references is given.

_____________________

Zemene Walle Mekonnen

Kassel, 27th February 2009.

ii

Page 4: 3 Periodic Signal Generation

Table of Contents

Abstract .................................................................................................................................... vi

Acknowledgments ................................................................................................................... vii

1 Introduction ...................................................................................................................... 1 1.1 Why DSP? .................................................................................................................. 1

1.2 Basic Elements of a Real-Time DSP System ............................................................. 2

1.3 Required Tools ........................................................................................................... 3

1.4 Hardware and Software Installation ........................................................................... 5

2 Sampling and Reconstruction ......................................................................................... 6 2.1 Talk-through Using Polling ........................................................................................ 6

2.1.1 Creating a Project ............................................................................................... 7 2.1.2 Code Generation and Options ............................................................................ 9 2.1.3 Building and Running a Project ....................................................................... 10 2.1.4 Plotting with CCS ............................................................................................. 12

2.2 Support Program/Files Consideration ...................................................................... 14

3 Periodic Signal Generation ............................................................................................ 19 3.1 Sine Wave Generation .............................................................................................. 19

3.1.1 Variable Amplitude Sine Wave Generation ..................................................... 21 3.1.2 Variable Amplitude and Frequency Sine Wave Generation ............................ 23

3.2 Triangular Waveform Generation ............................................................................ 25

4 AM Signal Generation ................................................................................................... 27 4.1 Amplitude Modulation (AM) ................................................................................... 27

4.2 DSB-WC Signal Generation .................................................................................... 30

4.3 DSB-SC Signal Generation ...................................................................................... 32

4.4 SSB Signal Generation ............................................................................................. 34

Conclusion and Further Work .............................................................................................. 40

Appendix ................................................................................................................................. 41 FIR Filter Coefficient Generation Using Matlab SPTool .................................................... 41

References ............................................................................................................................... 43

iii

Page 5: 3 Periodic Signal Generation

List of Figures

Figure 1.1: Basic functional blocks of real-time DSP system [3]. ............................................. 3

Figure 1.2: TMS320C6713 DSK board. .................................................................................... 4

Figure 1.3: “C6713 DSK CCS” and “C6713 DSK diagnostic utility” shortcuts. ...................... 5

Figure 2.1: A talk-through system [2]. ....................................................................................... 6

Figure 2.2: Talk_through.c using polling [1-2]. ......................................................................... 6

Figure 2.3: CCS project window for new project creation. ....................................................... 7

Figure 2.4: Project file window. ................................................................................................. 8

Figure 2.5: Project Build Options window for the compile. ...................................................... 9

Figure 2.6: Program compilation, linking, and execution [3]. ................................................. 10

Figure 2.7: Modified talk_through.c [1]. ................................................................................. 12

Figure 2.8: CCS Graph Property Dialog (a) time-domain plot; (b) Frequency-domain plot. .. 13

Figure 2.9: Partial listing of c6713dskinit.c [1]. ....................................................................... 15

Figure 2.10: Partial listing of Vectors_intr.asm [1]. ............................................................... 17

Figure 2.11: Generic linker command file (c6713dsk.cmd) [1]. .............................................. 18

Figure 3.1: Source file for sine wave generation using lookup table (sine_lookup.c) [1]. ...... 20

Figure 3.2: Slider GEL file that represents gain.gel [1]. .......................................................... 21

Figure 3.3: Modified sine_lookup.c [1]. ................................................................................... 22

Figure 3.4: A slider representing Amplitude (Gain). ............................................................... 23

Figure 3.5: gainFreq.gel [1]. .................................................................................................... 23

Figure 3.6: Source file for variable frequency generation (sine_varFreq.c ) [1]. .................... 24

Figure 3.7: Triangular wave form with period T. .................................................................... 25

Figure 3.8 Source code that generates a triangular waveform (triangle.c) [1] ......................... 26

Figure 4.1: Amplitude modulation (a) modulating signal, (b) carrier signal, (c) modulated

signal ................................................................................................................................ 28

Figure 4.2 SSB signal generation using filtering method. ....................................................... 30

Figure 4.3: Amplitude modulation source code (DSBWC.c) [1]. ............................................. 31

Figure 4.4: AM.gel [1]. ............................................................................................................. 31

Figure 4.5: Program file for DSB-SC signal generation (DSBSC.C). ...................................... 33

Figure 4.6: A snapshot of the spectrum of the (a) input signal (inBuffer) , (b) output signal

(outBuffer). ....................................................................................................................... 34

Figure 4.7: Functional sketch of FIR filter. .............................................................................. 35

Figure 4.8: Source code for SSB signal generation using filtering method (SSB.C). .............. 36

iv

Page 6: 3 Periodic Signal Generation

Figure 4.9: (a)Coefficients for low pass FIR filter (LPfilt.cof), (b) Spectrum of the filter. ..... 37

Figure 4.10: (a) Coefficients for band pass FIR filter (BPfilt.cof), (b) Spectrum of the filter. 38

Figure 4.11: (a) Generated DSB-SC signal (b) SSB signal generated after a band pass filter. 39

Figure A.1: statup.spt. .............................................................................................................. 41

Figure A.2: Low pass filter design specifications. ................................................................... 42

v

Page 7: 3 Periodic Signal Generation

Abstract

This manuscript is intended to introduce the reader to the Texas Instruments TMS320C6713

DSP Starter Kit (called C6713 DSK for short), which can be used to implement real-time DSP

algorithms. It is assumed that the reader has basic knowledge of C/C++ Programming

language.

The documentation starts with a brief introduction about DSP, followed by necessary

software and hardware installations. In Chapter 2 the tools (hardware and software) that are

accompanied with the C6713 DSK package are introduced with simple programming

examples.

In Chapter 3 the generation of periodic signals using the C6713 DSK is discussed.

Specifically the generation of sinusoidal and triangular waveforms is considered. Chapter 4

covers the generation of different amplitude modulated (AM) signals. The AM signals that are

discussed include: double-sideband with carrier (DSB-WC), double sideband-suppressed

carrier (DSB-SC), and signal-sideband (SSB).

vi

Page 8: 3 Periodic Signal Generation

vii

Acknowledgments

First of all I would like to thank my project advisor Dipl.-Ing. Thomas Edlich, for giving me

the opportunity to work on the C6713 DSK, for his feedback, comments, suggestions and

most of all for his kindness. I would also like to extend my sincere thanks to all of the

members of the Communications Laboratory (Comlab) at the University of Kassel for their

assistance.

I would also like to express my appreciation to the members of “DSP Related Discussion

Group”, who have helped me in tackling the problems that I faced when I was preparing this

manuscript.

Finally, I would like to thank my family and friends for their help and support.

Page 9: 3 Periodic Signal Generation

1 Introduction

Signals can be divided in to three categories: continuous-time (analog) signals, discrete-

time signals, and digital signals. Analog signals are signals that represent physical

quantities with a function, which is continuous both in time and amplitude. Discrete-time

signals model physical quantities with a function, which is continuous in amplitude but

defined only at some specific time instances. On the other hand Digital signals are defined

for a particular time instances as discrete-time signals but they take only discrete

amplitude values, so they are discrete both in time and amplitude.

Signal processing systems may also be classified along the same line as signals. Digital

systems are those for which the input and output of the system are digital signals [4].

Digital Signal Processing (DSP) is therefore concerned with representation of physical

quantities using digital signals and the processing of these signals to extract information

from them.

1.1 Why DSP?

There are lots of reasons that Digital Signal Processing technique is preferred over analog

signal processing technique, which uses active and/or passive devices to process a signal

[3]. Some of the advantages of a DSP system over the analog counterpart are:

Flexibility: It is easy to change and/or upgrade a DSP system by modifying the software

that has been used to implement the specific algorithm on the same hardware. But in the

analog counterpart we need to change the whole/part of the circuitry that implements the

signal-processing algorithm if we want to modify or upgrade the system. DSP systems,

due to these flexibility characteristics, can also be used to simulate signal processing that

will be implemented on an analog system before constructing the analog hardware. This

enables the analog system designer to have experimental flexibility without wasting

engineering or economic resources.

Complexity: Sophisticated applications can be implemented by using power efficient

(less complex) DSP algorithms.

1

Page 10: 3 Periodic Signal Generation

Reliability: The DSP hardware components (e.g. memory, logic) are resistant to

changing environmental conditions or aging of electronic components than the analog

counterparts.

Cost: Due to the advent of technology, which results in reduction of cost of digital

computers, it is possible to implement a cost effective DSP systems.

Due to these and other reasons Digital Signal Processors (DSPs)1 are used for a wide

range of applications from communication and control to speech and image processing.

Application embedded DSPs are found in cellular phones, fax/modem, disk drives, radio,

printers, MP3 players, high-definition television (HDTV), digital cameras, and so on [1].

Having said some the advantages of DSP systems, it is worthwhile to mention some of

their limitations. For example, the bandwidth of the DSP system is dependent on the

sampling rate and hardware peripherals, initial costs of the DSP system may be expensive

when large bandwidth signals are involved [3].

1.2 Basic Elements of a Real-Time DSP System

DSP applications can be divided as non-real-time and real-time. Non-real-time

applications are those which process signals that have been digitized and stored before the

signal processing action. In other words the result of non-real-time applications is not

needed at the time the signal collection and digitization is performed. But in real-time

signal processing it is necessary to finish a given task with in a certain time frame work; if

not, the system couldn’t operate appropriately. The basic functional blocks of a real-time

DSP is illustrated in figure 1.1.

The Analog to Digital Converter (ADC), in the input channel, converts an analog input

signal in to a digital signal so that it can be processed digitally using the DSP hardware.

The Digital to Analog Converter (DAC), the counterpart for ADC in the output channel,

changes the output of the DSP hardware, which is a digital signal, into an analog signal.

The amplifier at the input channel represents proper electronic sensor that converts

pressure, temperature, or sound into an electrical signal [3]. An example of the input

1 The acronym DSP is used for Digital Signal Processing and Digital Signal Processor interchangeably, the meaning should be clear from the context.

2

Page 11: 3 Periodic Signal Generation

amplifier is a microphone. The amplifier at the output channel performs the reverse action

of the input channel amplifier. An example of the output channel amplifier is a headphone.

The anti-aliasing filter at the input channel is used to cutout signals with a frequency

component above the Nyquist frequency (one half of the sampling frequency). Otherwise

we can’t distinguish signals having frequency above the Nyquist frequency with signals

having lower frequency (aliasing effect), as our sampling rate is too small to take enough

sample of the signal above the Nyquist frequency. For a detailed description of the

functional blocks of figure 1.1 the reader is referred to [3].

Output

DSP Hardware

Amplifier

Anti-aliasing Filter

ADC Other digital systems

Other digital systems

DAC Reconstruction Filter

Amplifier

Input channel

Output channel

Input

Figure 1.1: Basic functional blocks of real-time DSP system [3].

1.3 Required Tools

The main objective of this manuscript is to enable the reader to get to know the DSP

Starter Kit (DSK), which can be used to implement a real-time DSP. Specifically the

TMS320C6713 DSK (called C6713 DSK in short) is used.

3

Page 12: 3 Periodic Signal Generation

The following tools are required to perform the experiments listed in the manuscript:

• TI’s DSK package. It includes:

- A board that contains the floating point DSP (C6713) and built in 32-bit

stereo codec (TLV320AIC23) for input and output (I/O) support. See

figure 1.2 for the photo of C6713 DSK.

- Code Composure Studio (CCS): an Integrated Development Environment

(IDE), which contains compiler, assembler, linker, and debugger that

provide necessary software support.

- A Universal Synchronous Bus (USB), which is used to connect the DSK

board to a PC.

- An adaptor with 5V output that is used to power up the DSK board.

• A Personal Computer (PC): make sure that you have Windows 2000 or Windows

XP operating system running on to your PC.

• An oscilloscope, signal generator, Microphones, and speakers.

• The CD included with this manuscript that contains the soft copy of the examples

that are listed in the manuscript.

Figure 1.2: TMS320C6713 DSK board.

4

Page 13: 3 Periodic Signal Generation

1.4 Hardware and Software Installation

Install the CCS from the CD-ROM included with the DSK package on to your PC.

Throughout it is assumed that you have installed it in the folder C:\C6713. You can install

it in any folder you like it to be, but take this into account in following the instructions that

are listed in the manuscript. After successful installation two shortcuts “C6713 DSK CCS”

and “C6713 DSK diagnostic utility”, shown in figure 1.3, will appear on your desktop (If

you haven’t disabled the option “put a desktop shortcut” during installation). Copy the

files from the CD, which is included with this manuscript, to the directory

C:\C6713\myprojects.

Figure 1.3: “C6713 DSK CCS” and “C6713 DSK diagnostic utility” shortcuts.

When you are ready:

• Plug in the 5V power supply, which is included with the DSK package, on the

DSK board to power it up. Verify that the +5V LED is “ON”.

• Plug the USB cable into the DSK board and plug the other end of the cable to your

PC’s USB port.

• Launch the DSK diagnostic utility from the icon on the desktop to test your

connection. From the diagnostic utility window, press the start button to run the

diagnostics. If the connection is correct, in approximately 30 seconds all the test

indicators shall turn to green and the text “PASS” shall be displayed on the

diagnostic status text box. Incase the test fails, check your connection and retry

until you see a green light.

• Launch the CCS by double clicking on its icon.

• If you are using CCS version 3.1, “No target connected” icon will be displayed on

the bottom-left of CCS IDE screen. Go to “Debug” pull down menu and select

“connect”, this will connect the DSP to the CCS and display “the target is now

connected” icon.

• Up on successful completion you can move on to the next chapter.

5

Page 14: 3 Periodic Signal Generation

2 Sampling and Reconstruction

In this chapter a very simple DSP application, which is depicted on figure 2.1, is

considered. As shown in the figure we simply pass a signal through an ADC and we feed

this signal to a DAC without any further processing, we call this process a talk-through.

With this simple DSP system, the primary focus is to be familiar with the software and

hardware tools of the DSK package not the functional blocks. It is assumed that the reader

has a basic knowledge of C/C++. Readers who are not familiar with C/C++ programming

language are referred to [9-11].

ADC DAC Analog signal

Reconstructed analog signal

Figure 2.1: A talk-through system [2].

2.1 Talk-through Using Polling

A program that implements the talk-through process is shown in figure 2.2.

Figure 2.2: Talk_through.c using polling [1-2].

1 #include "DSK6713_AIC23.h" //codec-DSK file support 2 Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate 3 void main() 4 { 5 short sample_data; 6 comm_poll(); //init DSK, codec, McBSP 7 while(1) //infinite loop 8 { 9 sample_data = input_sample(); //sample input 10 output_sample(sample_data); //output sample 11 } 12 }

Line 2 in the program listing sets the sampling frequency of the codec to Fs = 8 kHz. So

samples are taken from the inputs of the codec every Ts = 0.125 ms. Inside the main1

function comm_poll, a function that is located on the communication and support file

c6713dskinit.c2, is called. This function initializes the DSK, the AIC23 codec, and other

necessary hardware for the process. For now think the file c6713dskinit.c as a black-box

1 Throughout this documentation function names are written in bold-italics font, and file and directory names are written in italics font. 2 This file is inside the CD that is included with this manuscript (or in the myprojects folder if you have copied the files from the CD to this folder) under the subfolder support.

6

Page 15: 3 Periodic Signal Generation

that initialize DSK components and provide necessary functionalities to enable them

communicate each other, we will uncover it in the next section.

The statement while(1) on line 7 creates an infinite loop that enables the DSK to listen for

an incoming signal all the time (of course periodically every Ts seconds). Inside the

infinite loop a function input_sample, which is inside c6713dskinit.c, is called. This

function takes samples of the input signal every Ts seconds. The function output_sample,

which is also inside c6713dskinit.c, then feeds the sampled data to the DAC.

Now let’s create a project which will run the talk_through program on the DSK.

2.1.1 Creating a Project

• Launch the CCS

• To create a project named talk_through.pjt, select Project → New. As shown in

figure 2.3, type the name for the project “talk_through” and select the target

TMS320C67XX. This will create a project named “talk_through” under the folder,

C:\C6713\myprojects\talk_through.

Figure 2.3: CCS project window for new project creation.

• In order to perform the talk-through task we need to equip the project with

necessary functionalities by adding files into it. Let’s add first the source file

talk_through.c in to our project. Select Project → Add Files to Project. From the

folder C:\C6713\myprojects\talk_through, double click on the C source file

talk_through.c to add it to the project. To verify that the file is added, click on the

7

Page 16: 3 Periodic Signal Generation

“+” sign in front of talk_through.pjt inside the Project window with in the CCS;

again click on the “+” sign in front of the source folder. Under the source folder

talk_through.c shall appear.

• It is not only the talk_through.c file that is needed to perform the talk-through task;

we also need other support files (e.g. c6713dskinit.c). Following the step above,

add the following files that are on the folder C:\C6713\myproject\support:

c6713dskinit.c, vectors_poll.asm, C6713dsk.cmd. We will discuss the function of

these files later in this chapter.

• We also need to add library support files that contain functions that are used by

source files. As we have added source files add the run-time support library file

rts6700.lib (from the folder C:\C6713\C6000\cgtools\lib), the board support

library file dsk6713bsl.lib (from the folder C:\C6713\C6000\dsk6713\lib), and the

chip support library file csl6713.lib (from the folder C:\C6713\C6000\csl\lib).

• By now your project window should look like figure 2.4.

Figure 2.4: Project file window.

Except the library files any of the files from the file window can be displayed by double

clicking them. There is no need to add the include files they will be added automatically

8

Page 17: 3 Periodic Signal Generation

when we build the project (or if you right click on the project and select Scan All File

Dependencies). But we need to tell the CCS where to find them as discussed below.

2.1.2 Code Generation and Options

When a project is created, a number of default options will be assigned to it. These options

greatly affect the execution of the project, so care must be taken in assigning project

options. Select Project → Build Options to view the project options. Figure 2.5 shows the

Project Build Options window for the compiler.

Figure 2.5: Project Build Options window for the compile.

Compiler Options

Select the following compiler option under the “Basic” category: C671x (-mv6710) for

“Target version” and leave the default option for “Generate Debug info”, “Opt Speed Vs

Size”, “Opt Level”, and “Program Level Opt”. Under the “Advanced” category change the

memory models option from “Far Aggregate” to “Far (--mem_model:data=far)”. Under

“Processor” category: type CHIP_6713 instead of _DEBUG for “Define Symbol option”

9

Page 18: 3 Periodic Signal Generation

and type the path for dsk6713 header file, i.e. C:\C6713\C6000\dsk6713\include, for

“Include path option”1. Then press OK.

Linker Option

Click on the “Linker” tab of the project build option window to see the linker options.

When the project is build the output of this operation will be stored on the file indicated

by the “Output File Name” option under the “Basic” category. The “.” in the path

represents the folder where the project resides. This file, which will be loaded onto the

DSK board, is a machine language translation of the source code that was written in C or

assembly language.

We can add library support files as discussed above or we can type the paths of each

library file directly within “Include Libraries” option under the “Basic” category,

separated by a comma. This will be the fastest way to add libraries as you get used to the

CCS, but if the library files are added in this way they will not appear under the project

file window.

2.1.3 Building and Running a Project

Programs written in C, which are categorized as high-level languages even though they

allow access to low level routines, need to be translated in to machine language that will

be executed on the DSP hardware. The process of compilation, linking, loading, and

execution is summarized in figure 2.6.

Program output

C compiler C program (Source) Linker/Loader

Libraries

Machine code

(Object) Execution

Data

Under the DSK Under the PC

Figure 2.6: Program compilation, linking, and execution [3].

Building a process refers to the compilation and linking operation, i.e. the source program

is compiled and linked with necessary library files.

1 The files (header files) under this folder will be added to the projects automatically when we build the project (or when “Scan all File Dependencies” is selected).

10

Page 19: 3 Periodic Signal Generation

Let’s build and load the talk_through project:

• Select Project → Rebuild All. This compiles and assembles all the C files using

c16x and assembles the assembly file vectors_poll.asm using asm6x [1]. The

resulting machine code (object files) are then linked with the library files to give

the executable file talk_through.out that will be loaded and executed on the DSP

hardware.

• Select File → Load Program to load the executable file talk_through.out, which is

in C:\C6713\myprojects\talk_through\Debug, on to the DSK. There is an option in

the CCS that enables us to load a program automatically after build operation.

Select Options → Customize Dialog, on the “Customize” dialog box click on the

“Program Load Options” tab, select the option “Load Program After Build”, and

press “OK”.

After building and loading the last step is to run the project. Select Debug → Run to run

the project. Connect the LINE IN port of the DSK with a sinusoidal signal waveform of 2

Vpp and frequency 1 kHz. Connect the output port of the DSK, LINE OUT, to an

oscilloscope and verify that a sinusoidal waveform of the same frequency but delayed and

attenuated version of the input signal is produced.

It can be clearly seen from the output of the DSK that the output signal is the sampled and

reconstructed form of the input signal. First the input signal is sampled every Ts seconds

(0.125 ms) during ADC operation, and during DAC operation an over sampling (10 times

in this case) is introduced to smoothen the output of the DSK. Try to zoom in the

oscilloscope display so that you can clearly see the stairs of length 0.0125 ms

(Ts/oversampling_factor). Change the sampling frequency of the codec by modifying line

2 of the talk_through.c to 16, 24, 32, 44.1, 48, and 96 kHz1 and confirm that the length of

the stairs is always Ts/oversampling_factor.

Let’s now try to determine the amplitude and frequency limits of the DSK:

• Increase the amplitude of the input signal until you encounter a distortion on the

output signal. Confirm that the output signal begins to distort when the input signal

amplitude goes beyond 6 Vpp.

1 These are sampling frequencies that are supported by AIC23 codec.

11

Page 20: 3 Periodic Signal Generation

• Now reset the amplitude of the input signal to 2 Vpp and increase its frequency.

Observe that the output signal gets distorted beyond the frequency Fs/2, as

expected.

So in designing any DSP system with the aforementioned DSK setup these amplitude and

frequency limits need to be taken into account.

2.1.4 Plotting with CCS

We can plot signals both in frequency and time domain using the CCS. To see how it

works we need to modify the talk-through source program of figure 2.2. Open

talk_through.c and edit it to have the form shown in figure 2.7.

1 #include "DSK6713_AIC23.h" //codec-DSK file support 2 Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate 3 shor output_buffer[256]; 4 const short BUFLEN = 256; 5 int index = 0; 6 void main() 7 { 8 short sample_data; 9 comm_poll(); //init DSK, codec, McBSP 10 while(1) //infinite loop 11 { 12 sample_data = input_sample(); //sample input 13 output_buffer[index] = sample_data; // copy of the data 14 // that is feed to the DAC 15 index++;

16 index = index%BUFLEN; // if index is greater than BUFLEN 17 // reinitialize it to zero

18 output_sample(sample_data); //output sample 19 }

20 }

Figure 2.7: Modified talk_through.c [1].

Build and Run the project.

12

Page 21: 3 Periodic Signal Generation

To plot output_buffer, select View → Graph → Time/Frequency. Change the graph

property dialog so that the options are as shown in figure 2.8 (a) to plot the output signal

in time domain, or as shown in figure 2.8 (b) to have frequency-domain plot of the signal,

and leave the default for the other options.

(a)

(b)

Figure 2.8: CCS Graph Property Dialog (a) time-domain plot; (b) Frequency-domain plot.

13

Page 22: 3 Periodic Signal Generation

2.2 Support Program/Files Consideration

In the previous section the support files c6713dskinit.c, vectors_poll.asm, and

c6713dsk.cmd were used for the talk-through project without knowing what was inside.

These files are almost used to support all of the projects that are listed here in the

manuscript so it is worthwhile to understand their functionalities. Discussing how to

construct them will be however out of the scope of this manuscript, so the main emphasis

is on how to use them.

Before we start to discuss these files we need to distinguish between two types of

programming techniques, i.e. polling-based and interrupt-driven. While polling-based

techniques provide continues testing procedure for an occasion to happen, interrupt-driven

techniques, as the name implies, use hardware or software interrupts to inform them for an

occasion.

A simple analogy might help to make things clear. Think of you want to talk to a manager

of a company and you went to his office but he wasn’t there by the time you arrived and

you know that he will comeback but you don’t know when. Now there are two ways to

meet the person: the first is to wait for him in front of his office until he shows up, and the

second one is to tell the secretary to give you a call by the time he comebacks and go to

your work. The first method corresponds to the polling-based technique and the second

one corresponds to the interrupt-driven technique. It is clear from the analogy that the

polling-based methods are simple to implement but they are less efficient as compared to

their interrupt-driven counterpart.

Initialization/Communication file (c6713dskinit.c)

The main functionality of the file c6713dskinit.c is to initialize the DSK and provide

necessary input-output functionalities for communication with the outside world. The

partial listing of the program is shown in figure 2.9.

14

Page 23: 3 Periodic Signal Generation

In the talk-through project, what we have done first was to call the function comm_poll.

This function and comm_intr (for interrupt-driven programs) in turn call the function

c6713_dsk_init that initializes the DSK. When interrupt-driven technique is used, i.e.

when comm_intr is called, interrupt #11 (INT111) is configured and enabled [1].

Figure 2.9: Partial listing of c6713dskinit.c [1].

//C6713dskinit.c Includes functions from TI in the C6713 CSL and C6713DSK BSL ... void c6713_dsk_init() //dsp-peripheral initialization { DSK6713_init(); //call BSL to init DSK-EMIF,PLL) hAIC23_handle=DSK6713_AIC23_openCodec(0, &config);//pointer to codec DSK6713_AIC23_setFreq(hAIC23_handle, fs); //set sample rate ... } void comm_poll() //added for communication/init using polling { poll=1; //1 if using polling c6713_dsk_init(); //init DSP and codec } void comm_intr() //for communication/init using interrupt { poll=0; // 0 since not polling IRQ_globalDisable(); //disable interrupts c6713_dsk_init(); // init DSP and codec … IRQ_map(CODECEventId, 11); //map McBSP1 Xmit to INT11 IRQ_reset(CODECEventId); //reset codec INT 11 IRQ_globalEnable(); //globally enable interrupts IRQ_nmiEnable(); //enable NMI interrupt IRQ_enable(CODECEventId); //enable CODEC eventXmit INT11 output_sample(0); //start McBSP interrupt outputting a sample } void output_sample(int out_data) //for out to Left and Right channels { short CHANNEL_data; AIC_data.uint=0; //clear data structure AIC_data.uint=out_data; //32-bit data -->data structure … if (poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE)); //if ready to transmit MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint); //write data } Uint32 input_sample() //for 32-bit input { short CHANNEL_data; if (poll) while(!MCBSP_rrdy(DSK6713_AIC23_DATAHANDLE));//if ready to receive AIC_data.uint=MCBSP_read(DSK6713_AIC23_DATAHANDLE);//read data … return(AIC_data.uint); } …

1 INT11 is chosen randomly, interrupts INT4 through INT15 can be chosen.

15

Page 24: 3 Periodic Signal Generation

Figure 2.9: (Continued).

… void output_right_sample(short out_data) //for output from right channel { AIC_data.uint=0; //clear data structure AIC_data.channel[RIGHT]=out_data; //data from Right channel -->data structure if (poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE)); MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint); } void output_left_sample(short out_data) //for output from left channel … short input_left_sample() //for input to left channel … short input_right_sample() //for input to right channel

The functions input_sample and output_sample are used to read and write data from/onto

the codec respectively. If the program is polling-based, then poll = 1 and the code

segment,

if(poll) while(!MCBSP_xrdy(DSK6713_AIC23_DATAHANDLE)) ; //ready to transmit

MCBSP_write(DSK6713_AIC23_DATAHANDLE,AIC_data.uint) ; //write data,

will enter the while loop. The function MCBSP_xrdy returns the value of the transmit-

ready (xrdy) register bit (= 1 if ready to transmit, or = 0 if not). While the McBSP1 is not

ready to transmit (i.e. xrdy bit is 0) the loop condition is true, so the “while” loop becomes

an infinite loop. When the McBSP is ready to transmit (i.e. xrdy bit is 1) the loop

condition becomes false, so the loop will be jumped and the data is written on to the

codec. If the program was interrupt-driven (poll = 0), the condition for “if” will become

false so the data will be written without testing the xrdy bit. The same logic holds for the

input_sample function, but in this case it tests the receive-ready (rrdy) bit.

The function input_sample captures a 32-bit data, 16-bits from the left channel and 16-bit

from the right-channel [1]. All of the examples in this manuscript use the codec in mono

format, i.e. we treat both of the channels as a single channel, but the codec has a stereo

capability in which two different input signals can be applied on the left and right channel.

The functions input_left_sample and input_right_sample, which can capture 16 bit data

from the left and right channel of the codec respectively, can be used in DSP applications

that need stereo capability of the codec. Similarly the functions output_left_sample and 1 McSBP = Multi-channel Buffered Serial Port

16

Page 25: 3 Periodic Signal Generation

output_right_sample can be used to write a 16 bit data at the left and right channel of the

codec respectively.

Vector File (vectors_poll.asm/vectors_intr.asm)

When a DSP receives an enabled interrupt, it will jump to a location in the vector table

corresponding to the interrupt and begin execution [2]. The files vectors_poll.asm and

vectors_intr.asm are used to fill the DSP interrupt vector table for polling-based and

interrupt-driven programs respectively. The partial listing of vectors_intr.asm is shown in

figure 2.10.

Figure 2.10: Partial listing of Vectors_intr.asm [1].

*Vectors_intr.asm Vector file for interrupt INT11 .global _vectors ;global symbols .global _c_int00 .global _vector1 .global _vector2 … .global _vector10 .global _c_int11 ;for INT11 .global _vector12 … .ref _c_int00 ;entry address … _vectors: _vector0: VEC_ENTRY _c_int00 ;RESET _vector1: VEC_ENTRY _vec_dummy ;NMI _vector2: VEC_ENTRY _vec_dummy ;RSVD _vector3: VEC_ENTRY _vec_dummy … _vector10: VEC_ENTRY _vec_dummy _vector11: VEC_ENTRY _c_int11 ;ISR address _vector12: VEC_ENTRY _vec_dummy …

As it can be seen from the program listing interrupt #11 (INT11), which was configured

and enabled inside the file c6713dskinit.c when an interrupt-driven technique is used, is

associated with an ISR1 c_int11. So, when an interrupt occurs the DSP will jump to this

ISR, executes the commands inside the ISR, and returns to the place where it was before

the interrupt occurs and continue its execution. We will see an example that utilizes this

ISR in the next chapter.

Polling-based programs don’t listen to interrupts, so for vectors_poll.asm (the vector file

for polling-based programs) the branch instruction to the ISR for interrupt INT11 shall be

replaced by NOP (No Operation) [1].

1 ISR = Interrupt Service Routine

17

Page 26: 3 Periodic Signal Generation

Linker Command File (c6713dsk.cmd)

The object files that result from the compilation of *.c and *.asm files need to be linked

together to produce the executable file that will be loaded into the DSK. To do this, the

linker command file indicates where the physical memory is located, and how code

sections are to be placed into the possible physical locations [2]. The linker command file

c6713dsk.cmd is shown in figure 2.11.

/*C6713dsk.cmd Linker command file*/ MEMORY { IVECS: org=0h, len=0x220 IRAM: org=0x00000220, len=0x0002FDE0 /*internal memory*/ SDRAM: org=0x80000000, len=0x00100000 /*external memory*/ FLASH: org=0x90000000, len=0x00020000 /*flash memory*/ } SECTIONS { .EXT_RAM :> SDRAM .vectors :> IVECS /*in vector file*/ .text :> IRAM .bss :> IRAM .cinit :> IRAM .stack :> IRAM .sysmem :> IRAM .const :> IRAM .switch :> IRAM .far :> IRAM .cio :> IRAM .csldata :> IRAM }

Figure 2.11: Generic linker command file (c6713dsk.cmd) [1].

The linker allocates the program in memory using default allocation algorithm [1]. But as

it is shown in the program listing with a generic linker command file user defined memory

allocations are possible. So the generic linker command file c6713dsk.cmd is used to

indicate the location of the physical memories (IRAM, SDRAM, …) and place different

sections into these physical memory locations (e.g. section “.text” is placed inside IRAM).

18

Page 27: 3 Periodic Signal Generation

3 Periodic Signal Generation

The C6713 DSK can be used to generate different types of signals that have a wide range

of applications in communication systems. It can be used to generate sinusoidal wave-

forms for oscillators, alerting signals (e.g. telephone rings and emergency alert signals),

signaling tones (e.g. DTMF) to mention the few. In this chapter the generation of periodic

signals will be considered.

3.1 Sine Wave Generation

The main thing that you, as a DSK programmer, need to take in to account for generating

a waveform is in writing the sample values of the waveform on to the codec every

sampling period. During DAC operation, as it was discussed in chapter two, an

oversampling will be introduced to smoothen the sample values and then they will be fed

to a reconstruction filter which even smoothes the sample values by cutting out frequency

contents beyond the band of interest. Due to these summed effects you will be able to

measure the intended waveform at the output of the codec.

With this framework, the generation of periodic waveforms can be performed using a

lookup table, where the table entries contain the sample values of the waveform to be

generated. An interrupt-driven program that generates a sine wave using a lookup table is

shown in figure 3.1.

Line 3 in program listing creates a sine wave lookup table, each table entry representing

sine wave values scaled by 1000 for angles loop*45o, where loop = {0, 1, 2, ... 7}. In the

main, the function comm_intr is called. As we discussed in the previous chapter this

function initializes the DSK, the codec and McBSP. Apart from this initialization it

configures and enables interrupt #11 (INT11). The infinite while(1) loop enables the DSK

to listen for interrupts all the time using INT11.

When an interrupt occurs the DSP will jump to the c_int11 (the ISR corresponding to

INT11 in Vectors_intr.asm). In the ISR a sine wave value corresponding to the table index

loop is written on to the codec. If the table index hasn’t reached its limit, it will be

incremented to output the next sample of the sine wave. If it exceeds the limit, it implies

that all the samples belonging to a single period has been written to the codec, so the table

index shall be reinitialized to zero to output the samples for the next period of the

19

Page 28: 3 Periodic Signal Generation

sinusoidal waveform. After performing all these operations the DSP will return to the

place where it was before the interrupt occurs, the infinite while(1) loop, to listen for the

next interrupt.

// Sine generation using lookup table 1 #include "dsk6713_aic23.h" //support file for codec,DSK 2 Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate 3 short sine_table[8]={0,707,1000,707,0,-707,-1000,-707}; //8 sine values for one period 4 int loop = 0; //table index 5 const short TABLE_LEN = 8; 6 interrupt void c_int11() //interrupt service routine 7 { 8 output_sample(sine_table[loop]); //output sine values 9 if (loop < TABLE_LEN - 1) //check for end of table 10 ++loop; 11 else //reinit table index 12 loop = 0; 13 return; //return from interrupt 14 } 15 void main() 16 { 17 comm_intr(); //init DSK, codec, McBSP 18 while(1); //infinite loop 19 }

Figure 3.1: Source file for sine wave generation using lookup table (sine_lookup.c) [1].

Since the sampling rate for the codec is set to 8 kHz, the sample values will be written to

the codec every 0.125 ms. With a lookup table of length 8, i.e. 8 samples per period, this

will generate a sinusoidal waveform of frequency 1 kHz.

Create a project named “sine_lookup”. Add the source files sine_lookup.c (which can be

found in the folder myprojects/Sine_lookup), c6713dskinit.c, and Vectors_intr.asm. Be

careful not to add Vectors_poll.asm because sine_lookup.c is an interrupt driven program.

Add the library files rts6700.lib (run-time support library file), dsk6713bsl.lib (board

support library file), and csl6713.lib (chip support library file). This time try to add them

by typing the full path of each library file separated by a comma in the linker option under

the category “Basic” on the text box “Include Libraries (-l)”.

Following the procedures in the previous chapter set the project options the same as the

“talk_through” project options. Then build and run the project.

By connecting the codec output to an oscilloscope confirm that a 1 kHz sinusoidal wave is

generated. You can also plot the output of the codec using the CCS graphics capability as

20

Page 29: 3 Periodic Signal Generation

we have done it for the “talk_through” project. To perform this modifying the source file

sine_lookup.c to include a buffer that accumulates the output of the codec and plot the

content of this buffer using the CCS.

3.1.1 Variable Amplitude Sine Wave Generation

Representing the variables of a source program with interfaces will enable the user of the

program to control the DSK output during execution. For example, the user can control

the amplitude of the waveform generated by the project “sine_lookup” if some of the

variables in the source file sine_lookup.c are represented by an interface.

A GEL (General Execution Language), a scripting language supported by the CCS, can be

used to create sliders, menu boxes and other interfaces to make our program more user-

interactive. Since these interfaces represent variables that are being used in the source

program, every time a change takes place on the interfaces the DSP will halt the program

execution while the corresponding variables are being updated. Despite of this undesirable

effect, GEL files are being used to represent variables because they can be created easily

using the CCS.

To create a GEL file that will construct a slider that represents the amplitude (gain) of the

waveform generated by the source program sine_lookup.c:

• Open a blank file by selecting File → New → Source File.

• Edit the file to have the form shown in figure 3.2.

• Save it as gain.gel in the folder sine_lookup, where the project sine_lookup.pjt

resides.

1 /*gain.gel Create slider and vary amplitude (gain) of sine wave*/ 2 menuitem "Sine Gain" 3 slider Gain(10,30,5,1,gain_parameter) /*incr by 5,up to 35*/ 4 { 5 gain = gain_parameter; /*vary gain of sine*/ 6 }

Figure 3.2: Slider GEL file that represents gain.gel [1].

Line 2 in the program listing creates a menu item “Sine Gain” that will appear under the

pull down menu “GEL” of the CCS. Lines 3-6 create a submenu item “Gain” under the

21

Page 30: 3 Periodic Signal Generation

newly created pull down menu item “Sine Gain” and a slider described by

“gain_parameter”. The description “gain_parameter” represents a slider labeled “Gain”

with a staring value of 10, ending value of 30, incremental step of 5, and a page scroll of

1.

Variables that are represented by GEL interfaces (“gain” in our case) need to be defined in

the source program. Open the source file sine_lookup.c and edit it as shown in figure 3.3

so that the slider can control the amplitude of output. Load the GEL file gain.gel by

selecting File → Load GEL.

• Build and run the project.

• Open the slider “Gain” by selecting GEL → Sine Gain → Gain. This shall open

the slider shown in figure 3.4.

// Sine generation using lookup table 1 #include "dsk6713_aic23.h" //support file for codec, DSK 2 Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate 3 short sine_table[8]={0,707,1000,707,0,-707,-1000,-707}; //8 sine values for one period 4 int loop = 0; //table index 5 const short TABLE_LEN = 8; 6 short gain =10; 7 interrupt void c_int11() //interrupt service routine 8 { 9 output_sample(sine_table[loop]*gain); //output sine values 10 if (loop < TABLE_LEN - 1) //check for end of table 11 ++loop; 12 else //reinit table index 13 loop = 0; 14 return; //return from interrupt 15 } 16 void main() 17 { 18 comm_intr(); //init DSK, codec, McBSP 19 while(1); //infinite loop 20 }

Figure 3.3: Modified sine_lookup.c [1].

By pressing the up-arrow key verify that the amplitude of the codec output increases as

the value of the variable “gain” increases with step size of 5.

22

Page 31: 3 Periodic Signal Generation

Figure 3.4: A slider representing Amplitude (Gain).

3.1.2 Variable Amplitude and Frequency Sine Wave Generation

The GEL file that generates the two sliders representing the gain and frequency of the

codec output is shown in figure 3.5.

• Remove the existing GEL file gain.gel from the GEL file list in the Project View

Window.

• Load the GEL file gainFreq.gel from the folder myprojects/sine_lookup.

• Remove the source file sine_lookup.c from the project files list.

• Add the source file sine_varFreq.c, which is shown in figure 3.6, to the project.

This file can be found in the folder myprojects/sine_lookup.

/*gainFreq.gel Two sliders to vary gain and frequency*/

enuitem "Sine Parameters" m slider Gain(1,8,1,1,gain_parameter) /*incr by 1,up to 8*/ { }

gain = gain_parameter; /*vary gain*/

ency(2,8,2,2,frequency_parameter) /*incr by 2,up to 8*/ slider Frequ { frequency = frequency_parameter; /*vary frequency*/ }

Figure 3.5: gainFreq.gel [1].

23

Page 32: 3 Periodic Signal Generation

As shown in figure 3.6, the lookup table sine_table of the source file sine_varFreq.c

contains 32 samples of a single period of a sinusoid scaled by 1000. Every time an

interrupt occurs the value in the lookup table indexed by the variable loop is written on to

the codec. Then the index loop is incremented by an amount equal to frequency (the

variable represented by one of the sliders). For example when frequency = 2, the values

that are indexed by loop will be sine_table[0], sine_table[2], sine_table[4], sine_table[6],

… sine_table[30], which in effect generates a sinusoidal waveform with frequency 500

Hz. By setting the variable frequency represented by the slider “Frequency” to 2, 4, 6, and

8 a sinusoidal waveform with frequency 500 Hz, 1 kHz, 1.5 kHz, 2 kHz can be generated.

// sine_varFreq.c, Sine generation with different # of points 1 #include "dsk6713_aic23.h" //support file for codec, DSK 2 Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate 3 short sine_table[32]={0,195,383,556,707,831,924,981,

1000,981,924,831,707,556,383,195, 0,-195,-383,-556,-707,-831,-924, -981,-1000,-981,-924,-831,-707,-556,-383,-195};

4 short loop = 0; //table index 5 const short TABLE_LEN = 32; 6 short gain =1; 7 short frequency = 2; 8 interrupt void c_int11() //interrupt service routine 9 { 10 output_sample(sine_table[loop]*gain); //output sine values 11 loop += frequency; //increment frequency index 12 loop = loop%TABLE_LEN; //reinitialize table index if it goes beyond limit 13 return; //return from interrupt 14 } 15 void main() 16 { 17 comm_intr(); //init DSK, codec, McBSP 18 while(1); //infinite loop 19 }

Figure 3.6: Source file for variable frequency generation (sine_varFreq.c ) [1].

Build and run the project. Open the two sliders “Gain” and “Frequency” under the

submenu GEL → Sine Parameters. By varying the values of the two sliders confirm that

the amplitude and frequency of the codec output vary in a fashion as discussed above.

24

Page 33: 3 Periodic Signal Generation

3.2 Triangular Waveform Generation

A periodic triangular waveform can be generated using the DSK in the same manner as

we have generated a periodic sinusoidal waveform. A source code that generates a

periodic triangular waveform, which is under the folder myprojects/triangle, is shown in

figure 3.8.

The two for loops inside the main generate a lookup table representing the sample values

for a single period of a triangular waveform, which is shown in figure 3.7. The first for

loop generates the sample values for the first half of the period and the second loop

generates the samples the second half of the period. When an interrupt occurs (i.e. every

Ts seconds) the code segment inside the ISR c_int11 will be executed, which in effect

results a periodic triangular waveform at the output of the codec.

• Create a project named “triangle.pjt” inside the folder myprojects.

• Add necessary source and library files to the project.

• Set the “Build Options” the same as the previous examples.

• Build and Run the project.

• By measuring the output of the codec confirm that a triangular waveform with a

fundamental frequency 125 Hz is generated.

Amplitude

T

First half

second half

time

Figure 3.7: Triangular wave form with period T.

25

Page 34: 3 Periodic Signal Generation

//triangle.c Generates a ramp using a look-up table #include "dsk6713_aic23.h" Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; #define table_size 64 short data_table[table_size]; //lookup table int i; // table index interrupt void c_int11() //interrupt service routine { output_sample(data_table[i]); //output value for each Ts if (i < table_size-1) i++; //if table size is reached else i = 0; //reinitialize counter return; } void main() { short step = 2 * 0x7FFF/table_size; for(i=0; i < table_size/2; i++) // Fill the lookup table representing the first { // half of the triangular waveform data_table[i] = -0x8000 + i * step; } for(i=table_size/2; i < table_size; i++) // Fill the lookup table representing the second { // half of the period

data_table[i] =data_table[i-1] - step; } i = 0; //reinit index comm_intr(); //init DSK, codec, McBSP while (1); //infinite loop }

Figure 3.8 Source code that generates a triangular waveform (triangle.c) [1]

26

Page 35: 3 Periodic Signal Generation

4 AM Signal Generation

Amplitude modulated signals can be generated by following the same procedure that we

used for periodic signal generation. Before discussing the generation of these signals, it is

worthwhile to review some fundamentals of amplitude modulation.

4.1 Amplitude Modulation (AM)

One of the possible ways to share the available frequency spectrum among computing

users is to apply frequency multiplexing, where messages of different users occupy

different frequency bins. This multiplexing can be achieved by varying the amplitude,

frequency, and/or phase of an auxiliary waveform (carrier signal) according to the signal

representing the message of each user (baseband signal). This process is called

modulation. In amplitude modulation, as the name implies the amplitude of the carrier

signal is varied according to the baseband signal.

DSB-WC Signals

One method to achieve an AM signal is to add the product of the carrier signal and the

baseband signal to the carrier signal itself. This can be represented mathematically as:

V(t) = Ac [1 + m(t)] cos(2πfct)

With,

m(t): baseband (modulating) signal

Accos(2πfct): carrier signal

V(t): modulated signal.

An example of amplitude modulation is shown in figure 4.1. Figure 4.1 (a) shows a

sinusoidal modulating signal of frequency 400 Hz and Vpp = 1.6. Modulating a carrier

signal having a frequency 2 kHz, figure 4.1 (b), with this modulating signal will result in

the modulated signal shown in figure 4.1 (c). These kinds of AM signals are sometimes

called double sideband with carrier (DSB-WC). The name came from the fact that both

the lower and upper side bands of the modulated signal are transmitted along with the

carrier signal.

27

Page 36: 3 Periodic Signal Generation

(a)

(b)

(c)

Figure 4.1: Amplitude modulation (a) modulating signal, (b) carrier signal, (c) modulated signal

The other thing that needs to be noted is that for an AM signal, generated with the method

mentioned above, to be perfectly demodulated at the receiver the amplitude of the

modulating signal (modulation index) shouldn’t exceed the amplitude of the carrier signal.

DSB-SC Signals

For receivers that implement phase-coherent demodulation it is necessary to maintain

phase synchronization between the transmitter and the receiver local oscillators for perfect

signal demodulation. One way to achieve phase synchronization between the transmitter

and the receiver is to transmit a pilot (carrier) signal along with the information-bearing

signal (modulated signal). With such a transmission the receiver can extract the pilot

signal by employing a narrowband filter, and synchronize its local oscillator to the

frequency and phase of the received signal. Clearly, the DSB-WC modulation scheme

implements this method as it transmits the carrier signal along with the information-

bearing signal.

The other approach to deal with synchronization at the receiver is to estimate the carrier

phase directly from the received signal. This approach is more efficient because the total

transmit power can be allocated for the transmission of the information-bearing signal [8].

A detailed description of different carrier phase estimation techniques can be found in [8].

28

Page 37: 3 Periodic Signal Generation

So for receivers that perform the second carrier synchronization technique the pilot signal

can be suppressed from the AM signal considered above, i.e. it is enough to transmit the

product of the modulating signal and the carrier signal given by:

U(t) = Ac m(t) cos(2πfct).

An AM signal, U(t), generated in this way is called double-sideband suppressed carrier

(DSB-SC) signal.

SSB Signals

Since the baseband signal can be recovered at the receiver from one of the sidebands, it is

of great interest to transmit only one of the sidebands so that the available spectrum can be

utilized more efficiently. Signals that contain only one of the sidebands (upper or lower)

of the DSB-SC signal are called single sideband (SSB) signals.

Two of the methods that are used in practice to generate SSB signals are:

• Filtering, and

• Phasing.

In this manuscript we will consider SSB signal generation using filtering technique. For a

detailed description of the two signal generation techniques the reader is referred to [6].

The processes of generating an SSB signal from a DSB-SC signal using a band pass filter

is summarized in figure 4.2. In the figure it is assumed that the DSB-SC signal is

generated from the modulation of a carrier signal having frequency fc with a baseband

signal having a lower frequency component fl and a higher frequency component fh. This

DSB-SC signal is fed to a band pass filter having a center frequency fc + (fh + fl)/2 and a

passband of fh – fl. With such specifications the filter will pass only the upper side band of

the DSB-SC signal, which in effect will result in the SSB signal shown in the figure.

29

Page 38: 3 Periodic Signal Generation

fc - fh

fc + fh

fc + fl

Spectral ensitd y Spectral

density

freq.

fh - fl

fc + (fh + fl)/2

H1(f)

f

fc - fh

fc – fl

fc fc + fh

fc + fl

Spectral density

freq.

DSB-SC signal

BP filter H1(f)

SSB signal

Figure 4.2 SSB signal generation using filtering method.

4.2 DSB-WC Signal Generation

A polling based program that generates a DSB-WC signal is shown in figure 4.3. Inside

the main two lookup tables are created. The first lookup table, baseband, contains the

sample values of a modulating signal (cosine wave with frequency 400 Hz). The second

lookup table, carrier, contains the sample value of a carrier signal (cosine wave with

frequency 2 kHz).

Note that the contents of the lookup table baseband are the sample values of the

modulating signal for one period, but the contents of the lookup table carrier are the

sample values of the carrier signal for 5 periods. In fact only the first four samples

(samples for a single period) can generate the same carrier signal that could be generated

by the lookup table containing samples of 5 periods. This kind of repetition is introduced

to match the length of both lookup tables, which eases mathematical calculations.

30

Page 39: 3 Periodic Signal Generation

Figure 4.3: Amplitude modulation source code (DSBWC.c) [1].

Inside the for loop a DSB-WC signal sample is written on to the codec every sampling

interval. A GEL file shown in figure 4.4 constructs a slider representing the variable

modIndex, which controls the modulation index. Since only integer variables can be

represented by a slider, it is necessary to translate non-integer variables into an integer to

represent them using a GEL slider. So in our case the slider “ModIndex” represents the

modulation index multiplied by 10. To compensate this we have divided the variable

modIndex by 10 in the DSB-WC equation.

The product of the modulating signal and the carrier signal in the DSB-WC equation is

scaled by 212 to emphasis the modulation.

//DSBWC.c DSBWC signal generation using table for carrier and baseband signals #include "DSK6713_AIC23.h" //codec-dsk support file Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate short modIndex = 1; //index for modulation short output[20]; void main() { short baseband[20]={1000,951,809,587,309,0,-309,

-587,-809,-951, -1000,-951,-809, -587,-309,0,309,587,809,951}; //400-Hz baseband

short carrier[20] ={1000,0,-1000,0,1000,0,-1000, 0,1000,0, -1000,0,1000,0,-1000, 0,1000,0,-1000,0}; //2-kHz carrier

short k; comm_poll(); //init DSK, codec, McBSP while(1) //infinite loop { for (k=0; k<20; k++) { output[k]= carrier[k] + ((modIndex*baseband[k]*carrier[k]/10)>>12); output_sample(20*output[k]); //scale output } } }

/*AM.gel To control modulation index*/

menuitem "Modulation Characteristics"

slider ModIndex(1,10,1,1,index) /*incr by 1,from 1 up to 10*/ { modIndex = index; /*vary modulation index*/

}

Figure 4.4: AM.gel [1].

31

Page 40: 3 Periodic Signal Generation

• Create a project named “DSBWC”.

• Add necessary files to the project including the source file DSBWC.c, which is

under the folder myprojects/DSBWC.

• After setting the usual build options, build and run the project.

• Load the GEL file AM.gel from the folder myprojects/DSBWC.

• Measure the output of the DSK using a scope or plot the content of the buffer

output using the CCS graphics capability and confirm that a DSB-WC signal is

generated.

• Open the slider representing the modulation index by selecting GEL →

Modulation Characteristics → ModIndex. By varying the slider value confirm that

the depth of modulation changes accordingly.

4.3 DSB-SC Signal Generation

A DSB-SC signal can be generated using the DSK by following the same procedure that

we used for DSB-WC signal generation. Figure 4.5 shows a polling based program that

generates a DSB-SC signal.

Inside the main function a lookup table representing a carrier signal with frequency 3 kHz

is generated. In this example we will take an audio signal as an input to the DSK that can

be used as a baseband signal to generate a DSB-SC signal. To do so, inside the infinite

while(1) loop the function input_sample is called to capture the samples of an input signal

from the output of the DAC every sampling period. These sample values are then

multiplied by the carrier signal and written on to the codec to produce the DSB-SC signal.

Create a project named “DSBSC” and include the source file DSBSC.c, which can be

found in the folder myprojects/DSBSC. Also include other necessary library and support

files. After setting the usual build options, build and run the project. A wave file

THEFORCE.wav, which is in the folder myprojects/DSBSC, can be used as an input to the

DSK. Play the wave file and connect your PC's sound card output to the input of the DSK.

32

Page 41: 3 Periodic Signal Generation

Figure 4.5: Program file for DSB-SC signal generation (DSBSC.C).

//DSBSC.c DSB-SC signal generation using table for carrier signal and // an audio signal as a baseband signal #include "DSK6713_AIC23.h" //codec-dsk support file Uint32 fs=DSK6713_AIC23_FREQ_16KHZ; //set sampling rate #define tableLen 16 #define buffLen 256 short outBuffer[256]; short inBuffer[256]; void main() {

short carrier[16] = {1000, 383, -707, -924, 0, 924, 707, -383, -1000, -383, 707, 924, 0, -924, -707, 383}; // carrier signal with

// frequency 3 kHz short index = 0; short k = 0; comm_poll(); //init DSK, codec, McBSP while(1) //infinite loop {

inBuffer[k]=input_sample(); //input new sample data outBuffer[k]= ((inBuffer[k]*carrier[index])>>12); // generate a DSB-SC signal output_sample(outBuffer[k]); k++; index++; k = k% buffLen; index = index% tableLen;

} }

By plotting the input buffer inBuffer and the output buffer outBuffer in the frequency

domain (the magnitude of the FFT) using the CCS graphics capability, confirm that a

DSB-SC signal is generated. The snapshot of the contents of the two buffers, for an input

wave file THEFORCE.wav, is shown in figure 4.6. As it can be seen from the figure a

DSB-SC signal that have two sidebands centered at 3 kHz is generated. From the figure

we also note that the upper sideband contains the exact copy of the input spectrum (only

shifted by 3 kHz), and the lower sideband is the mirror image of the upper sideband (with

the mirror positioned at frequency equal to 3 kHz).

33

Page 42: 3 Periodic Signal Generation

(a)

(b)

Figure 4.6: A snapshot of the spectrum of the (a) input signal (inBuffer) , (b) output signal (outBuffer).

4.4 SSB Signal Generation

As discussed earlier an SSB signal can be generated from a DSB-SC signal using filtering

method. So it is worth revising some of the concepts of digital filters to facilitate our

discussion about SSB signal generation.

The two main categories of digital filters are: finite impulse response (FIR) and infinite

impulse response (IIR). Where the main difference between the two categories lies on the

34

Page 43: 3 Periodic Signal Generation

fact that the FIR filter output depends only on the history of input but the IIR filter output

depends on the history of both the input and output. In this manuscript we will consider

only FIR filters.

A functional sketch of an FIR filter that has N coefficients h(0), h(1), …, h(N-1) is shown

in figure 4.7. As shown in the figure the filtering operation is a convolution, which can be

expressed as:

y(n) = , ∑ −−

=

1

0)()(

N

kknxkh

with x(n) is the filter input and y(n) is the filter output at time n.

Figure 4.7: Functional sketch of FIR filter.

There are several software packages that can be used to generate the coefficients of an FIR

using different windowing functions, such as Hamming, Hanning, Blackman and Kaiser.

For a detailed description of the FIR filter and different windowing functions the reader is

referred to [4]. For the SSB signal generation example we will use filter coefficients

generated using Matlab SPTool (Signal Processing Toolbox). The generation of FIR filter

coefficients using Matlab SPTool is discussed in the appendix.

A polling based program that generates an SSB signal is shown in figure 4.8. In the

program listing two files that contain the coefficients of a low pass filter (LPfilt.cof) and

band pass filter (BPfilt.cof) are included. The coefficient file LPfilt.cof, generated using

Matlab SPTool and shown in figure 4.9 (a), represents a low pass filter with cutoff

frequency at 3 kHz. This low pass filter is used to band limit the input audio signal with in

the band 0 to 3 kHz so that aliasing can be avoided. This assumes that the information-

Z-1

Z-1

Z-1

X

X

X

X

...

Σy(n)

x(n) h(0)

h(1)

x n-1( ) h(2)

x n-2( )

h N( -1)

x n- N( ( -1)

35

Page 44: 3 Periodic Signal Generation

bearing signal is band limited between 0 and 3 kHz, which is the case for human speech.

The spectrum of the filter coefficients is shown in figure 4.9 (b).

The coefficient file BPfilt.cof, which is also generated using Matlab SPTool and shown in

Figure 4.8: Source code for SSB signal generation using filtering method (SSB.C).

figure 4.10 (a), contains the coefficients of a band pass filter centered at 4.5 kHz with a

passband of 3 kHz. As discussed below, this filter is used to select the upper sideband of

the DSB-SC signal. The spectrum of the filter coefficients is shown in figure 4.10 (b).

//SSB.C SSB signal generation using filtering method

mpling rate efficient file efficient file

buff[N]; ut[256], dsbscSig[256], bpfiltOut[256];

rt filtco nction declaration

short sigIndex; ] = {1000, 383, -707, -924, 0, 924, 707, -383,

-1000, -383, 707, 924, 0, -924, -707, 383}; // carrier signal with frequency 3 kHz

comm_poll();

//init the LP filter buffer

}

ndex = 0;

sigIndex]=input_sample(); //input new sample data lpfiltOut[sigIndex] = filter(input[sigIndex], Lpbuff, LPfiltCoff );

e seband signal and

bpfiltOut[sigIndex] = filter(dsbscSig[sigIndex], Bpbuff, Bpfil

carrierBufLen; //reint table index if it exceeds the limit

} }

.

#include "dsk6713_aic23.h" Uint32 fs=DSK6713_AIC23_FREQ_16KHZ; //set sa#include "LPfilt.cof" //low pass filter co#include "BPfilt.cof" //band pass filter co#define carrierBufLen 16 #define sigLength 256 static short LPbuff[N], BPshort input[256], lpfiltOshort filter(short newinp, short *dlyinp, sho ff [ ]); // fu void main() {

short i;

short carrier[16

//init DSK using polling

for (i=0; i< N; i++)

LPbuff[i] = 0; BPbuff[i] = 0; //init the BP filter buffer

{

i =sigIwhile(1) {

input[

0;

dsbscSig[sigIndex] = (lpfiltOut[sigIndex]*carrier[i])>>15; // scale the product of th// ba// the carrier signal tCoff);

output_sample(bpfiltOut[sigIndex]); i++; sigIndex++; i = i%sigIndex = sigIndex%sigLength;

. .

36

Page 45: 3 Periodic Signal Generation

. . . filter(short newinp, short *dlyinp, short filtcoff [ ]) //implement FIR

rt i;

-1] = newinp; //insert the newest sample into the buffer

yn += dly[i] * filtcoff[N-(i+1)]; //y(n)=x[n-(N-1-i)]*h[N-1-i]

} =

ime n }

short{

shoint yn ; dlyinp[Nyn = dlyinp[0] * filtcoff[N-1]; //y(0)=x(n-(N-1))*h(N-1) for (i = 1; i < N; i++) //loop for the rest {

dly[i-1] = dly[i]; //update the filter buffer

yn (yn >>15); //filter's output return yn; //return y(n) at t

Figure 4.8: (continued).

Inside the main, in the program SSB.C, a lookup table representing a carrier signal with

As shown in the program listing the function filter, which takes newinp, dlyinp, filtcoff as

The low pass filter output is then multiplied with the carrier signal to produce the DSB-SC

Figure 4.9: (a)Coefficients for low pass FIR filter (LPfilt.cof), (b) Spectrum of the filter.

frequency 3 kHz is generated. Then within the for loop the buffers for the two filters that

contain the input history of the respective filter are initialized to zero. Inside the infinite

while(1) loop first the input sample is captured from the ADC, then the captured sample is

passed through the low pass filter, which is implemented by the function filter.

its input, returns the output of a convolution operation with newly arriving input sample

newinp, delayed input samples dlyinp and filter coefficients filtcoff. Apart from the

convolution operation the contents of the filter buffer are updated since we have passed

the array Lpbuff to the function using a pointer (passing by reference).

signal sample. This DSB-SC signal sample is then fed to the band pass filter to cut out the

lower sideband. The output of the band pass filter is then fed to the DAC to produce the

SSB signal.

#define N 81 // number of coefficients 3, 29, 45, 0, -63, -57, 36, 107, 47, -99, -147, 0, 188, 162, -98,

1,

(a)

short LPfiltCoff[N] = {0, 12, 12, -8, -28, -1-288, -123, 255, 372, 0, -464, -398, 241, 708, 306, -640, -955, 0, 1285, 1169, -771, -2550, -1314, 3667, 9623, 12288, 9623, 3667, -1314, -2550, -771169, 1285, 0, -955, -640, 306, 708, 241, -398, -464, 0, 372, 255, -123, -288, -98, 162, 188, 0, -147, -99, 47, 107, 36, -57, -63, 0, 45, 29, -13, -28, -8, 12, 12, 0};

37

Page 46: 3 Periodic Signal Generation

(b)

Figure 4.9: (continued).

(a)

short BPfiltCoff[81] = {0, -21, 5, -7, 28, 37, -70, -11, 0, 15, 137, -101, -107, 40, -41, 260, 0, -332, 67, -83, 288, 352, -616, -87, 0, 109, 960, -687, -708, 259, -265, 1686, 0, -2269, 484, -653, 2550, 3742, -8853, -2258, 12288, -2258, -8853, 3742, 2550, -653, 484, -2269, 0, 1686, -265, 259, -708, -687, 960, 109, 0, -87, -616, 352, 288, -83, 67, -332, 0, 260, -41, 40, -107, -101, 137, 15, 0, -11, -70, 37, 28, -7, 5, -21, 0};

(b)

Figure 4.10: (a) Coefficients for band pass FIR filter (BPfilt.cof), (b) Spectrum of the filter.

38

Page 47: 3 Periodic Signal Generation

Create a project named “SSB” and all necessary files to it including the source file SSB.C,

which can be found in the folder myprojects/SSB. After setting the usual build options,

build and run the project. By plotting the spectrum of the output buffer bpfiltOut and input

buffer input, confirm that a SSB signal having the same shape as the input spectrum but

shifted in frequency is generated.

The plot of the DSB-SC signal sample buffer dsbscSig and the SSB signal sample buffer

bpfiltOut for a particular time is shown in figure 4.11.

(a)

(b)

Figure 4.11: (a) Generated DSB-SC signal (b) SSB signal generated after a band pass filter.

39

Page 48: 3 Periodic Signal Generation

Conclusion and Further Work

With this introductory documentation it has been tried to discuss that the Texas Instrument

TMS320C6713 DSP Starter Kit (C6713 DSK) can be used to implement real time DSP

algorithms. As it was discussed with examples the Code Composer Studio (CCS), an IDE1

accompanied with the C6713 DSK package, is a powerful tool that helps to implement

DSP algorithms with high level programming language (C/C++). After compilation and

linking, the machine code translation of the DSP algorithms that was written in C/C++ can

be loaded and run on the DSK.

The built-in AIC23 stereo audio codec performs all the tasks that are necessary to connect

the DSP with the outside world. The operations include ADC, DAC, sampling and low

pass filtering. The codec is designed with sigma-delta technology, where the main design

objective is to achieve higher resolution for audio applications. The higher resolution is

achieved by introducing higher oversampling ratio with the cost of reduction in maximum

achievable sampling rate.

The AIC23 codec supports a sampling rate of 44.1 kHz with CD quality. So if we use this

sampling rate, with Nyquist criterion, the signal that can be recovered from the sampled

values are those that have frequency components less than half the sampling rate (22.05

kHz). Frequency components above the allowed frequency will be filtered out by the anti-

aliasing filter. To work with signals that have frequency components higher than the

frequency that is allowed by the AIC23 stereo codec one need to interface an external

daughter card that enhance the built-in codec. One possible solution is to interface

DAC8581EVM daughter card with the DSK, which can work with signals in the radio

frequency range.

The C6713 DSK is connected with the host PC through the JTAG emulation port (the

USB port). Although this interface allows us to load a machine code translation of a DSP

algorithm that is written using high level programming language, its bandwidth is too

limited to allow a communication between the DSK and a software application running on

the host PC. This problem can be alleviated by interfacing a daughter card, which uses the

Host Port Interface (HPI) pins of the DSK to access the internal memory of the DSP.

1 IDE = Integrated Development Environment.

40

Page 49: 3 Periodic Signal Generation

Appendix

FIR Filter Coefficient Generation Using Matlab SPTool

The coefficients of a finite impulse response (FIR) can be generated by the Matlab

SPTool. In this appendix the generation of FIR filter design using a Kaiser window is

considered.

Enter the command "SPTool" inside the Matlab command window. This shall open a

startup window startup.spt, shown in figure A.1.

Figure A.1: statup.spt.

• Click on the button "New" on the startup window to open the "Filter Designer"

environment.

• In the environment set the sampling frequency to 16 kHz and select "Kaiser

Window FIR" as a window algorithm.

• Edit the "Specification" category to look like the specifications shown in figure

A.2. With these specifications a low pass filter with cutoff frequency 3 kHz is

generated.

41

Page 50: 3 Periodic Signal Generation

• To change the name of the filter, go to the startup window and select Edit → Name

→ "Default name of the designed filter". On the popup box type the desired name

of the filter (e.g. lp3000).

Figure A.2: Low pass filter design specifications.

• On the startup window (startup.spt) select File → Export. On the window "Export

from SPTool" click on the button "Export to workspace". By doing so the filter can

be accessed from the Matlab command window. • Enter the command "lp3000.tf.num" on the command window. "lp3000" represent

the filter, "tf" will access the transfer function of the filter, and "num" will return

the numerators of the transfer function of the filter in a vector form. So the result

of the command is the coefficients of the low pass filter that we have designed. The coefficients of a band pass, high pass and band stop filters can be generated by

following the same procedure.

42

Page 51: 3 Periodic Signal Generation

43

References

[1] R. Chassaing, “Digital Signal Processing and Applications with the C6713 and C6416 DSK”, John Wiley & Sons Inc., New Jersey, 2005.

[2] T. B. Welch, C. H.G. Wright and M. G. Morrow, “Real-Time Digital Signal Processing from Matlab® to C with the TMS320C6x DSK”, Taylor & Francis Group, LLC, 2006.

[3] S. M. Kuo and B. H. Lee, “Introduction to Real-Time Digital Signal Processing”, John Wiley & Sons Ltd, 2001.

[4] A. V. Oppenheim and R. W. Schafer, “Digital Signal Processing”, Prentice-Hall Int.,

1975.

[5] “TMS320C6416/C6713 DSK One-Day Workshop Student Guide”, TI Technical Training Organization, 2003.

[6] H. Taub and D. L. Schilling, “Principles of Communication Systems”, McGraw-Hill, 2nd edition.

[7] L.W. Couch, “Digital and Analog Communication Systems”, Prentice Hall, 6th edition, 2001.

[8] J. G. Proakis, “Digital Communications”, McGraw-Hill, 4th edition, 2001.

[9] B. W. Kernighan and D. M. Ritchie, “C Programming Language”, Prentice Hall Software, 2nd edition, 1988.

[10] S. Oualline, “Practical C Programming”, 3rd edition, O’Reilly®.

[11] R. Lafore, “Object Oriented Programming in C++”, 4th edition, Sams Publishing, 2002.

[12] M. G. Morrow, T. B. Welch and C. H. G. Wright, “A Host Port Interface Board to Enhance the TMS320C6713 DSK”, in Proceedings of the IEEE International Conference on Acoustics, Speech, and Signal Processing, Vol. 2, May 2006.