UNIVERSITY OF HONG KONG

Department of Electrical & Electronic Engineering ELEC 2201 Signals and Linear Systems

Experiment SLS-02: TMS320C30 Development Environment and the Sampling Theorem

Objectives: 1) To understand the TMS320C30 DSP hardware and software development environment. 2) To learn how to program the TMS320C30 processor and the host interface. 3) To learn how to acquire real data by discrete-time sampling. 4) To understand the principle and implications of the sampling theorem. 5) To recover a corrupted speech signal using signal processing techniques

Apparatus: TMS320C30 Evaluation Module (EVM) Card (installed in the PC) A general speaker An ordinary microphone The TMS320C30 software development package An IBM Compatible PC with MATLAB and signal processing toolbox

Preparation: 1) Read the laboratory sheet and the related documents carefully. 2) Try to understand at least the main programs on the PC (OS_PC.C) and the evaluation board (C30.C). 3) You should go through the Appendix B of the textbook “Programming in MATLAB” and SLS01, which is a test of your knowledge on MATLAB. 4) Use MATLBE M-file to compute the Discrete Fourier Transform of a given speech segment using the direct computation method. You should divide your speech into 20ms windows, compute the DFT coefficients for each window for all windows, and display it using the spectrogram format (i.e. x-axis is the frequency, y-axis is time in window sequence and z-axis is the power (square of the coefficient)). Use MATLAB for the display. 5) Invoke MATLAB and to type 'demo' to get a more comprehensive demonstration of the capability of MATLAB. Read the Signal Processing Toolbox tutorial and go through the following tutorials: - Signals as Vectors and Matrices - Filter Analysis and Implementation - FFT and Spectral Analysis (excluding Cepstrum) - Convolution and Correlation Functions - Interpolation and Decimation You should feel free to explore the other functionality of MATLAB. 6) Find out more about the command “fft” in MATLAB.

Procedures:

Part A Simple data acquisition and play back In this part of the experiment, you are expected to read and understand part of a sample program that simulates a digital oscilloscope using the EVM. The EVM is capable of acquiring data at a maximum rate of 19.2kHz. The sampling rate, input high-pass filter, input and output low-pass filters and the sin x/x compensation filters can all be controlled using software through the AIC chip. The data is acquired through the microphone connected to the analog input of the EVM. It passes through the input section of the AIC and is sampled at the desired sampling rate after the input filters. It is also converted back to an analog signal via the D/A converter and can be played on the speaker. In this part of the experiment, the EVM is programmed to pass all the acquired data to the PC that displays it on a small window and thereby simulating an oscilloscope. Various parameters as mentioned earlier are controlled by the function keys on the PC keyboard, which in-turn are sent to the EVM for alteration. The program also optionally allows you to acquire a window of real-time signal and store on a disk file (called the recording mode).

The experimental set up is shown in Figure 1. Your task in this part of the experiment is as follows:

A1) Compile the sample files according to the instruction given in the TMS302C30 Development Tools Use Guide provided in the Laboratory. You need to assemble or compile the following files and produce the *.obj object files.

Figure 1 Experimental Set Up

Source File Header Files Tools Purpose Object File PC_C.C PC_1.H, PC_2.H bcc Drivers for the PC-host computer PC-C.obj VECS.ASM none asm30 Interrupt vectors for the C30 VECS.obi C30.C C30_1.H, C30_2.H C130 Drivers to be loaded on the EVM C30.obj OSC_PC.C OSC_PC.H bcc Main oscilloscope program OSC_PC.obj OSC_C30.C OSC_C20.H, OSC_CMD.H C130 Oscilloscope program on EW OSC_C30.obj

2) There are two sets of object files to be linked: a) PC-host program to be linked under the Borland-C environment and produce the .exe files to be run on the PC. b) C30-EVM programs to be linked using the Ink30 and the OSC.CMD link command file as follows: /*************************************************************************/ /* OSC.CMD */ /* TMS320C30 EVALUATION DEMO PROGRAM LINK COMMAND FILE */ /*************************************************************************/ /* LINK COMMAND FILE FOR OSC PROGRAM */ -c vecs.obj c30.obj osc_c30.obj -o osc.out -heap 0x800 -1 rts.lib

MEMORY { VECS: org = 0 len = 0x40 /* RESERVED VECTOR LOCATIONS */ SRAM: org = 0x40 len = 0x3FCO /* PRIMARY BUS SRAM (16K) */ RAM org = 0x809800 len = 0x800 /* INTERNAL RAM (2K) */ }

SECTIONS .text: {} > SRAM /*CODE */ .cinit: {} > SRAM /* C INITIALIZATION TABLES */ .stack: {} > RAM /* STACK (MODIFIED TO 64 WDS) */ .bss: {} > RAM /* C VARIABLES */ .data: {} > RAM /* ASSEMBLY CODE CONSTANTS */ vecs: {} > VECS /* RESET/INTERRUPT VECTORS */ } Figure 2 Link Command File

The following steps should be followed in this part: a) login to the network b) make a subdirectory on your local disk (say c:\dsplab) and copy all files frorn the w:\dsplab\sls_01\*.* to your local subdirectory. The files should include: i) the dsp_init.bat batch file to set all the necessary paths ii) all the necessary *1 header files iii) all the necessary *.c source files (for both the PC and C30 programs) iv) the vecs.asin assembly files containing the C30 vector addresses v) the RESWT.001 and RESWT.002 files used by the C30 loader vi) the osc.cmd link command files for the C30 vii) the object files att.obj and egavga.obj which contain the libraries for the keyborad and some graphics functions needed on the PC c) execute the dsp_init.bat batch file to set all the necessary paths to access Borland C and C30 Cross C-compilers by: dsp_jnit

d) compile the PC-host programs by the following command: bcc -ml osc_pc.c pc.c att.obj egavga.obj graphics.lib this will generate the osc_pc.exe executable file for the PC e) compile the C30 driver program and assembly interrupt vectors definitions by the following command: cl30 iw:\dsplab\lib c3O.c asm30 vecs.asm this will generate the object file c30.obj for the C30. The -i option specifies that the include files should be found in the directory w:\dsplib f) compile the osc-c30.c program by the following command: cl30 ose_c3O.c g) link all the C30 modules using the link command file osc.cmd by: Ink30 ose.cmd this will produce an loadable output file with C30 codes called osc.out h) reset the EW and load the osc.out program to the C30 EW by: evmreset evinload ose.out i) execute the program on the PC to interact with the C30 EW by: psc_pc 3) Load and execute the program to verify that all are working as expected. You may speak into the microphone to hear your own voice played back on the loudspeaker (after a small delay). You may also vary the various sampling parameters to observe any changes in the signals. 4) Alter the program to a) disable the input high-pass filter permanently and use a single parameter (A) to control the sampling rate (instead of using both A and B). The sampling rate is given by the following formula:

f 3.75MHz f  MCLK   samplingfrequency c 2AB AB

f 3.75MHz f  MCLK   switch  capfilter frequency SCF 2A A

Here, fMCLK for the EW is 7.5MHz. For a lpf with a cutoff at 3.6kHz, f SCF should be 288kHz and the cutoff frequency of the lpf can be computed proportionally. It is recommended you fix B=36 (for example) and vary A to obtain different frequencies. Recompile the programs and test again.

The following changes are to be made to the corresponding files: a) change the main-menu definition in osc_pc.h to reflect the new functions b) change the prints in status( ) in file osc_pc.c to show the corresponding text on the AIC status window on the screen c) change the sampling_rate assignment statement and all the necessary command processing statements in osc_pc.c. Here, it may be easier to retain the symbolic name of the commands, ie INCA for F1 etc. You may choose to change that too but the corresponding definition in the osc_cmd.h header file must also be changed accordingly. Part B Acquire Your Own Speech Segment Use A = 13, B=36, compile the program in Part A and store a window of your own speech segment for offline processing in the post-laboratory assignment. The speech segment should be: “DSP is interesting”.

Part C Effect of Aliasing due to Inadequate Sampling Rate In this part of the experiment, you should fix the sampling rate at 3kHz using an appropriate values of A and B, and artificially create a sinusoidal signal whose frequency can be varied from 1.2kHz to 2kHz in step of 100Hz. You must also change the data acquisition part of the program so that instead of sampling real signals using the EVM, you are now sending synthesis signal to the EVM for outputting to the speaker (via the D/A converter and output filter). 1) Modify the program accordingly to achieve this. 2) Recompile and relink all the necessary modules. 3) Execute the program, listen to the output on the speaker and observe any unusual phenomenon. 4) In the lab report, you have to explain the observed phenomenon.

Hint: To achieve this, you need to modify the osc_pc.c program as follows: a) add a for-loop to generate a sine function with a magnitude of about 300 in the array disk[i]. This array should be added before the infinite for loop for (;;) in the main function of osc_pc.c. The frequency of the generating function should be a variable which is changed by the function keys. The size of the function should be set to 48*buffer_size where buffer_size is 512. b) permanently set play=ON so that the signal is sent to the EVM for ‘playback’. c) remove the codes for the record mode.

Part D Signal Processing of Speech Signal Using the MATLAB Signal Processing Toolbox, process the noise corrupted speech file given to you by the demonstrator during the lab. Your objective is to recover the speech signal and enhance it as much as possible. You should 'play' the enhanced signal and try to find out what exactly the speech says.

Format of your lab report SLS02:

Page 1: Cover page. You must follow the same format as given to you. Page 2: Section title – Introduction. Write in only one page what preparations you have done before the lab. Page 3: Section title – Data acquisition. Write in only one page what you did in Part A and B. Page 4: Section title – Aliasing.. Write in only one page what you did in Part C. Explain in detail the observed phenomenon and how it relates to the Sampling Theorem.

Page 5: Section title – Signal processing of speech signal. Write in only one page what you did in Part D. You should state clearly the frequency of noise in the corrupted speech file. Page 6: Section title – Conclusions.

You final report must have SIX pages only.

Notes: 1) You are expected to keep an up-to-date record of your experiment on the log book. 2) You should submit an individual report. Write in your own words any observations and explanations of the observations.

NOTE : Plagiarism in lab report writing will be heavily penalized.