Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Making DSP Fun For Students Using Matlab and The C31 DSK: Cameron H. G. Wright

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Texas Instruments DSPS Fest

Houston, TX, August 4–6, 1999

Making DSP Fun for Students Using Matlab and the C31 DSK
Cameron H. G. Wright
Department of Electrical Engineering, U.S. Air Force Academy, USAFA, CO 80840

Thad B. Welch and Michael G. Morrow


Department of Electrical Engineering, U.S. Naval Academy, Annapolis, MD 21402

Abstract – This paper describes some innovative programs us- ability to apply signal processing concepts to real-world
ing a graphical user interface (GUI) for Matlab and the C31 DSP hardware such as the widely-used Texas Instruments
DSK which makes DSP concepts interesting and entertain-
ing, yet educational. The programs eliminate the need to pur- TMS320C series of fixed-point and floating-point DSP mi-
chase any expensive specialized software or hardware, relying croprocessors. In particular, the sptool program supplied
on the commonly available Matlab program and the inexpen- with the latest release of the student edition1 of Matlab
sive Texas Instruments C31 DSK for this purpose.
and also available in the latest Signal Processing Tool-
The programs described in this paper are a follow-on to the box (version 4.2, written for Matlab 5.3 Professional)
one presented at DSPS Fest ’98. The new programs are far provides an excellent interactive graphical user interface
more capable and even easier to use than their predecessor: (GUI) for designing both FIR and IIR digital filters [13].
one author (TBW) even managed to get 4th graders to design
real-time digital filters then run them on a C31 DSK with one
The sptool program also allows interactive viewing and
of these programs, and college students love the graphical user analysis of signals and their spectra, but this paper con-
interface and the ease of interfacing with the DSP hardware. centrates on the filter design capabilities.
The programs have been used with great success at both the
U.S. Air Force Academy and the U.S. Naval Academy.
A discussion of how to effectively use sptool in DSP edu-
cation can be found in previous papers [14–16]. Various
Keywords – DSK, TMS320C31, Matlab, education, DSP filter specifications can be easily selected by the student,
with an immediate customizable display of the resulting
I. INTRODUCTION magnitude response. For a more complete analysis of the
filter design, the student can click the “View” button from
ODERN software tools such as Matlab greatly fa-
M cilitate the professor’s ability to demonstrate the
concepts of digital signal processing (DSP) in class, and to
the filter column of the main sptool window, executing
the Filter Viewer tool, which displays magnitude, phase,
impulse response, step response, poles and zeros on the z-
assign realistic projects to reinforce these concepts [1–3].
plane, group delay, etc., all at the click of a button. The
An increasing number of DSP textbooks are becoming
student can switch back to the Filter Designer tool with
available which take advantage of this ability [4–8], and a
a click of the mouse to modify the design parameters and
growing trend is for DSP concepts to be introduced ear-
interactively see the results. The Filter Designer tool also
lier in the curriculum [9]. These concepts can be further
includes a method to design filters by interactively plac-
reinforced, and greater interest generated by the students,
ing poles and zeros on the z-plane. The student can also
if they can be easily implemented in real-time on modern
process any stored signal with the desired filter and view
DSP hardware [10]. Affordable hardware is now available
the resulting output signal and its associated spectrum
to schools: Texas Instruments, for example, markets DSP
by clicking the “Apply” button from the filter column of
Starter Kits (DSKs) for $99 [11]. While fixed-point pro-
the main sptool window. The sptool program encourages
cessors are more prevalent in industry [12] (albeit floating
the student to pursue “what if?” explorations to satisfy
point is gaining in use), floating-point processors are be-
their intellectual curiosity and gain a more complete un-
coming more popular for schools due to pedagogical rea-
derstanding of the underlying DSP concepts.
sons. We will examine how Matlab, already accepted
as a powerful learning tool for DSP, can be closely inte- Note that sptool is simply an easy to use GUI that exe-
grated with a DSK for teaching purposes while avoiding cutes m-file programs for filter design that existed in pre-
the tedium of manually programming the DSP processor. vious versions of both the Signal Processing Toolbox and
the Student Edition of Matlab. The only really new
A. Teaching with Matlab
aspect is the interactive GUI. Students tend to use the
Matlab is an excellent learning tool for DSP educa- sptool GUI much more than they ever used the collection
tion, enabling an easier transition for the student from of individual m-files from previous versions [14].
theory to practice. This greatly facilitates a student’s
1 The Mathworks is now introducing the more powerful “Student
Author e-mail addresses: CHGW: c.h.g.wright@ieee.org, Version” of Matlab which will eventually replace the “Student Edi-
TBW: t.b.welch@ieee.org, MGM: morrow@nadn.navy.mil tion” of Matlab.
B. Teaching with DSKs TI TMS320C5x series) tend to be harder to teach in in-
troductory courses compared to floating-point processors
Another powerful tool to energize and excite students is such as the TMS320C3x and TMS320C4x. For this rea-
the ability to implement a particular signal processing son, many schools are opting to buy floating-point DSP
technique in real-time on a DSP microprocessor such as hardware (such as the C31 DSK from TI described above)
one of the Texas Instruments (TI) TMS320C series. When for teaching purposes. While the fixed-point effects are
a student speaks into a microphone and hears their “per- important concepts for students to grasp, many schools
sonally designed” digital filter algorithm working in real- would appreciate a way to teach and demonstrate these
time, they are often “hooked” on DSP from then on. The topics without having to buy additional hardware. The
recent availability of affordable DSP Starter Kits (DSKs) program described below integrates Matlab closely with
has made this feasible for most schools. The C31 DSK the C31 DSK, eliminates the need to create individual as-
described in this paper costs only $99 and contains on a sembly language or C programs to manipulate the hard-
single inch circuit board the following items.2 ware, and allows the primary fixed-point effects to be sim-
ulated in real-time on the floating-point DSK. If the stu-
• TMS320C31 DSP microprocessor (capable of up to dent desires to load and run a digital filter design on the
50 MFLOPS) with 50 MHz clock oscillator. The C31 DSK without the added effects of fixed-point processors,
contains 2 K words (a word is 32 bits) of on-chip it is also easily accomplished.
RAM, and can also be used with external memory
on an add-on card. II. COMBINING MATLAB WITH THE C31 DSK
• TLC32040 analog interface chip (AIC), which com-
bines a selectable cutoff frequency antialiasing filter
The authors identified a pressing need for a GUI-based
(which can also be bypassed), a selectable sampling
program which would run under Matlab, be able to
frequency (up to 20 kHz but can be used at higher fre-
directly utilize the benefits of sptool mentioned above,
quencies) 14-bit analog-to-digital converter (ADC), a
and also communicate seamlessly with the C31 DSK.
digital-to-analog converter (DAC), a reconstruction
While the capabilities provided by sptool are impressive
filter, and a small output power amplifier which can
and greatly facilitate students’ comprehension of various
drive loads ≥ 300 W. The analog input and output
DSP topics, there is no straightforward way to use it
are intended for audio line-level (±3 V peak) connec-
directly with a DSK. Also lacking in sptool is the abil-
tions.
ity to simulate for teaching purposes certain fixed-point
• Regulated power supply that accepts either 7–12 Vdc
effects, suitable for presentation to our senior-level EE
or 6–9 Vac input.
majors, such as filter coefficient quantization. Matlab
• Host logic for the PC parallel port communication
performs double precision calculations in sptool, thus a
(IEEE 1284).
filter design could perform far differently than expected
• Various connectors: RCA jacks for the analog in and
if implemented on a fixed-point processor [14]. While
out, DB25 parallel port, a 2.1 mm power jack, and
floating-point DSP hardware (such as Texas Instruments
four 32-pin headers which can connect all C31 signals
TMS320C3x series) is much easier to present from a peda-
to custom add-on cards.
gogical standpoint, the fact remains that fixed-point DSP
The C31 DSK comes with an assembler, debugger, and hardware (such as the Texas Instruments TMS320C5x se-
assorted documentation. An optimizing C compiler and ries) is still more prevalent due to it’s cost and speed
a wide variety of other development tools are available at advantages. It therefore behooves the professor to ex-
extra cost. pose the students to the important differences between
floating-point and fixed-point hardware. Specialized soft-
The C31 DSK is inexpensive, easy to set up, and can ware programs exist which address this design issue, but
greatly enhance a DSP class. There are obstacles to us- they are typically expensive, require the student to learn
ing DSKs, however. The learning curve for programming another interface, and/or are not written for educational
modern DSP microprocessors is a significant hurdle for purposes.
most students. They must contend with specialized top-
ics such as parallel instruction execution, block-repeat, A. A Fixed-Point Simulation Using Matlab
bit-reversed addressing, and the often unfamiliar Harvard
architecture-and must usually program at the assembly In response to this need, the authors wrote a Matlab
language level. This scares away many students. While program that takes up where sptool leaves off, adjusting
fixed-point processors are more prevalent in industry due the filter coefficients to simulate fixed-point hardware, al-
to their cost and speed advantages, they add further prob- lowing interactive analysis of the design effects, and seam-
lems: coefficient quantization, scaling, and other fixed- lessly downloading the filter code to a C31 DSK when the
point ALU and register effects. From a pedagogical point user is ready. This allows the floating-point DSK to sim-
of view, fixed-point processors (such as the widely-used ulate a fixed-point device as desired, and eliminating the
2 A C33 DSK with much larger memory on board will be available need for buying fixed-point hardware just for this pur-
soon. pose. Based upon feedback received at IEEE ICASSP
’99, the authors recently addded the additional capabil- shown in Figure 2 through Figure 4.
ity to simulate fixed-point register and ALU effects. The
program allows the student to interactively compare the The student can imediately see that with quantization ef-
theoretical filter performance with the real-world perfor- fects, the filter performance is altered radically. There
mance that would be encountered using any fixed-point are significant changes to the originally calculated magni-
DSP microprocessor, yet still make full use of sptool. The tude (Figure 2) and phase (Figure 3) response of the filter,
actual performance of the student’s filter design can be which were predicated on the assumption of floating-point
observed in real-time with the click of a mouse button, processing. But this isn’t the whole story!
which loads and runs the filter on the C31 DSK. The pro-
gram eliminates the need for the student to learn another There is always a danger in relying too heavily on the re-
software interface, eliminates the need for the students sults of computer simulations and blindly accepting the
to manually program the DSK, and is perfectly suited to results. The filter used for the example above clearly
educational use. While it runs outside of sptool, the pro- demonstrates this, as even the filter magnitude and phase
gram easily exchanges information in both directions by response after quantization can be misleading. It is ev-
using the same data structure format defined by sptool. ident in Figure 4 that due to the quantization process,
some poles have moved outside the unit circle on the com-
B. A Typical Example plex z-plane. Assuming this is a causal filter design, this
implies that the region of convergence for the z-transform
In order to examine the effects of digital filter coeffi- does not contain the unit circle, meaning the filter design
cient quantization or other fixed-point effects, the stu- is unstable. We can verify this by importing the quan-
dent merely designs a filter to the desired specifications tized filter back into sptool and examining the impulse
using sptool in the normal manner. The student then response. As expected, the filter “blows up” and would
exports the filter from sptool to the Matlab workspace be unstable. Yet the quantized filter magnitude response
and runs our program by typing qfilt at the Matlab com- in Figure 2, while no longer meeting the design specifica-
mand prompt. This brings up the custom GUI shown in tions, doesn’t look unstable. How do we explain this dis-
Figure 1 which allows the user to select with the mouse crepancy? We routinely tell our students that no matter
the simulation constraint method (rounding or truncat- how fast the computer simulation may be, the students
ing coefficient quantization, floating- or fixed-point ALU are smarter than the computer, and to always perform
and register behavior, and implementation as either a Di- a “sanity check” on any results. In this case, Figure 4
rect Form Type II transpose or as second-order cascaded would indicate a stability problem. Matlab evaluates
sections), number of bits (8 to 32) for the fixed-point ef- the magnitude and phase response of a discrete transfer
fects, and plotting preference (magnitude vs. frequency, function by substituting z = ejω (mathematically equiva-
phase vs. frequency, or poles and zeros on the complex lent to evaluating the discrete-time Fourier transform, the
z-plane). The GUI also allows control over the DSK, and DTFT, of the filter). The student should know, however,
the user can select the port to which the DSK is connected that if the unit circle is not contained in the region of
(LPT1–LPT3), the sampling frequency of the AIC (fifty convergence of the z-transform, then the DTFT does not
choices from 4509 Hz to 20292 Hz), and control whether exist, and the magnitude and phase response as calculated
or not the antialiasing filter is in the signal path. Note by Matlab is meaningless. Since Matlab doesn’t check
that the previous version of this program used a command for this condition, we added a routine in qfilt which de-
line interface and had no ability to communicate with a tects it and warns the user by showing the plot with a red
DSK; we have found the GUI version to be far more ap- background and a special plot title. If no poles move out-
pealing to our students and the ability to run their filters side the unit circle as a result of quantization, or we are
in real time on a DSK has been incredibly motivational. dealing with FIR filters (which have no non-trivial poles),
When the “Apply” button is clicked with the mouse, the then the calculated magnitude and phase response will be
program automatically generates and displays any of the valid and the plot background would be white.
three selected plots which each compare the floating-point
vs. fixed-point filter implementations on the same plot. The student might then explore if the same filter would
behave any differently if it was implemented as a cascaded
To demonstrate the process a student would use, a dig- second order section (referred to in some DSP texts as “bi-
ital filter was previously designed using sptool with the quads”). The student simply selects this with the mouse
following parameters: bandpass elliptic IIR, sample fre- and clicks the “Apply” button once again for the various
quency F s = 8117 Hz, passband 900–1400 Hz with 3 dB plots. As can be readily seen in Figure 5 and Figure 6, the
ripple maximum, transition regions of ≤ 50 Hz, and stop filter is now stable (note the plot titles and background
band attenuation of ≥ 70 dB. The resulting design pro- color) and comes so close to matching the floating point
duced by sptool is an 8th order filter with actual stopband performance that the difference is virtually indistinguish-
edges at 872 Hz and 1439 Hz. When the filter coefficients able. Without qfilt, the student would likely assume that
have been quantized by qfilt to 16 bits (as would be the the filter design from sptool would meet the desired speci-
case with the Texas Instruments TMS320C5x) and imple- fications no matter how it was implemented. By using our
mented as a Direct Form Type II transpose, the result is program, however, the student gains a better understand-
Fig. 1. Initial screen of the graphical user interface (GUI) for qfilt.

ing of the design ramifications of a fixed-point digital filter can be used as a normal floating-point unit or, as de-
realization, including the significant differences of the di- scribed above, the same floating-point DSK can be use to
rect form versus second-order section implementations. simulate fixed-point unit.

When the filter design is satisfactory, the user can sim- A companion program called polezero with a similarly
ply click the “Load/Run DSK” button on the GUI to designed GUI for teaching DSP using Matlab and the
download the software to the C31 DSK and run the fil- C31 DSK allows students to perform interactive adjust-
ter algorithm for a real-time demonstration. This down- ment and “what if?” analysis of pole-zero plots [16]. The
load and run process takes less than a quarter of a sec- polezero program allows the student to design basic digi-
ond, which gives a feeling of immediacy to the student. tal filters by interactively placing poles and zeros on the
No programming is necessary, making this especially at- complex z-plane, observing the results, and immediately
tractive for introducing students to DSP hardware. The running the resulting filter on the C31 DSK. The initial
“Load/Run DSK” button activates a 32-bit dynamic link screen presented to the user for polezero is shown in Fig-
library (DLL) written with Microsoft Visual C++ 5.0 and ure 7.
the Matlab MEX file process to run under Windows 9x
or Windows NT; different programs execute depending III. CONCLUSIONS
upon whether the user has selected Direct Form Type
II transpose or cascaded second order sections. To stay The programs qfilt and polezero written by the authors
within the on-chip memory limits of the C31 DSK, the provide the educator with easy to use, inexpensive, and
maximum order supported is a 254 order IIR Direct Form interactive methods to teach various concepts of digital fil-
Type II transpose and a 256 order IIR cascaded second ter design so important in DSP classes. The programs are
order sections. By specifying a high bit number (such as completely compatible with sptool provided with version 5
32), quantization effects are miniscule and the C31 DSK of the Student Edition of Matlab and also with version
Fig. 2. Magnitude plot of 8th order IIR Elliptic digital filter, quantized to 16 bits and implemented as a Direct Form II transpose.

4.2 of the Signal Processing Toolbox. They both easily ference, pp. 1207–1210, June 1994.
communicate with the C31 DSK that is used by many [2] C. S. Burrus, “Teaching filter design using Matlab,” in Pro-
ceedings of the IEEE International Conference on Acoustics,
universities, they eliminate the need for tedious program- Speech, and Signal Processing, pp. 20–30, Apr. 1993.
ming of the DSK, and both are freely available from the [3] R. G. Jacquot, J. C. Hamann, J. W. Pierre, and R. F. Ku-
following Web site. bichek, “Teaching digital filter design using symbolic and nu-
meric features of Matlab,” ASEE Computers in Education,
vol. VII, pp. 8–11, January-March 1997.
wseweb.ew.usna.edu/ee/links/ee_links.htm [4] B. Porat, A Course in Digital Signal Processing. John Wiley
& Sons, 1997.
[5] V. K. Ingle and J. G. Proakis, Digital Signal Processing Using
Should the URL be changed, then navigate from the Naval Matlab V.4. Bookware Companion Series, PWS Publishing,
Academy home page and select Academics, Academic Di- 1997.
visions and Departments, Electrical Engineering, Links. [6] S. K. Mitra, Digital Signal Processing: A Computer-Based Ap-
proach. McGraw-Hill, 1998.
Note that while these programs do not require program- [7] A. Ambardar and C. Borghesani, Mastering DSP Concepts Us-
ing Matlab. Prentice-Hall, 1998.
ming by the student, our experiences have shown that [8] J. H. McClellan, C. S. Burrus, A. V. Oppenheim, T. W. Parks,
once most students “play” with these programs a bit, be- R. W. Schafer, and S. W. Schuessler, Computer-Based Exer-
come comfortable with the DSK, and start to see what cises for Signal Processing Using Matlab 5. Matlab Curricu-
lum Series, Prentice-Hall, 1998.
the device can do, they want to learn how to program
[9] M. A. Yoder, J. H. McClellan, and R. W. Schafer, “Experiences
the DSK. This is how learning DSP can be fun for the in teaching DSP first in the ECE curriculum,” in Proceedings of
student. the 1997 ASEE Annual Conference, June 1997. Paper 1220-06.
[10] R. Chassaing, Digital Signal Processing: Laboratory Experi-
References ments Using C and the TMS320C31 DSK. John Wiley & Sons,
1999.
[1] R. F. Kubichek, “Using Matlab in a speech and signal pro- [11] Texas Instruments, Inc., TMS320C3x DSP Starter Kit User’s
cessing class,” in Proceedings of the 1994 ASEE Annual Con- Guide, 1996.
Fig. 3. Phase plot of 8th order IIR Elliptic digital filter, quantized to 16 bits and implemented as a Direct Form II transpose.

[12] C. Inacio and D. Ombres, “The DSP decision: Fixed point or


floating?,” IEEE Spectrum, pp. 72–74, Sept. 1996.
[13] The MathWorks, Inc., Natick, MA, Matlab: The Language of
Technical Computing, 1996.
[14] C. H. G. Wright and T. B. Welch, “Teaching real-world DSP us-
ing Matlab,” ASEE Computers in Education Journal, vol. IX,
pp. 1–5, Jan–Mar 1999.
[15] C. H. G. Wright and T. B. Welch, “Teaching DSP concepts
using Matlab and the TMS320C31 DSK,” in Proceedings of
the IEEE International Conference on Acoustics, Speech, and
Signal Processing, Mar. 1999. Paper 1778.
[16] T. B. Welch, C. H. G. Wright, and M. G. Morrow, “Poles,
zeros, and Matlab, oh my!,” in Proceedings of the 1998 ASEE
Annual Conference, (Charlotte, NC), June 1999. Paper 1320-
02.
Fig. 4. Pole-zero plot of 8th order IIR Elliptic digital filter, quantized to 16 bits and implemented as a Direct Form II transpose.
Fig. 5. Magnitude plot of 8th order IIR Elliptic digital filter, quantized to 16 bits and implemented as cascaded second order sections.
Fig. 6. Pole-zero plot of 8th order IIR Elliptic digital filter, quantized to 16 bits and implemented as cascaded second order sections.
Fig. 7. Initial screen of the graphical user interface (GUI) for polezero.

You might also like