Using Matlab To Debug Software Written For A Digital Signal Processor
Using Matlab To Debug Software Written For A Digital Signal Processor
processor
Malcolm J. Goris
Netherlands Foundation for Research in Astronomy
Post Box 2
7990 AA Dwingeloo
The Netherlands
email: mgoris@nfra.nl
phone: +31 521 595 286
fax: +31 521 597 332
Abstract
Digital signal processors (DSPs) are high-powered and highly-integrated processing
units that are used in computationally-intensive embedded-computing applications. Nor-
mal debugging tools are too low level to use for debugging the high-level functions that
DSPs are often programmed to do. However, a useful debugging environment may be cre-
ated by using Matlab to perform the same calculations as the DSP and verifying the DSP’s
results at suitable points in the software. The Matlab software can be easily written and it
provides a “truth” model for the results that should be obtained by the DSP. If the DSP’s
results differ from Matlab’s results then it is the DSP software that must be corrected.
In this paper, we describe how we used Matlab to debug an adaptive digital-beamforming
system. There was little overhead to the DSP to implement the debugging procedure,
allowing it to run in real time. We estimate that it sped our debugging and testing cycle
by a factor of six.
1 Introduction
Digital signal processors (DSPs) are typically used in embedded-computing applications that
require a fast CPU core that is optimized for signal processing tasks. They are used in ap-
plications such as mobile telephony, speech encoding and decoding and image processing and,
typically, perform tasks such as filtering, matrix manipulation, and transforms in real time. In
this paper we explain how normal debugging tools are insufficient to fully verify and correct
the operation of real-time DSP software. We give, as an example, an overview of a DSP-based
system that we developed and we show how we were able to fix high-level functions of the DSP
software using Matlab. The efficiency of using Matlab with respect to the normal debugging
tools was such that our debugging and testing cycle was sped by a factor of six.
To detect software bugs that were related to program design we used Matlab to verify that
the results of DSP functions were correct. An RS232 connection from the DSP to a PC was
used to communicate the input and output data of any function to and from Matlab via data
files. We created some simple Matlab scripts to read data from the files and used Matlab to
do the same computations that the DSP was doing on the same data. We were then able to
compare the results from the DSP with those from Matlab to verify whether the DSP software
was performing correctly. We could also make different calculations on the same data if we
needed to. The advantage of using Matlab in this way is that the complex functions under test
on the DSP can be written, often, in just one or two Matlab commands. This leaves very little
room for error in Matlab. And so, if the results given by Matlab were different to those of the
DSP’s then invariably the DSP software was at fault. Conversely, if Matlab’s and the DSP’s
results were the same then that was positive proof that the DSP software was correct because
the chance of getting the same results accidentally are negligible.
The remainder of this paper is structured as follows. In Section 2 we introduce the moti-
vation for using Matlab to debug DSP software. In Section 3 we briefly describe a real-time
1
system that we built and that uses a DSP for the main computing element. In Section 4 we
give, by way of a demonstration, the procedures we used to find and correct two software bugs
in our system. Section 5 concludes the paper.
2
3 Our DSP application – adaptive array processing
Our application is an adaptive digital-beamformer system that uses application-specific inte-
grated circuits (ASICs) and a DSP. A block diagram of the software is shown in Figure 1. The
array has eight antennas whose outputs are digitized in quadrature at 8 MHz. The ASICs
weight and sum the data to produce a single quadrature output. The adaptive algorithm, im-
plemented on the DSP, is known as a minimum-variance (MV) beamformer and it calculates
the eight complex weights that are delivered to the ASICs for the weight-and-sum operation.
The weights are calculated repetitively from blocks of data. The MV beamformer is described
quadrature
data interpolate
look direction steering
commands vectors calculate
weights to
ASICs
calc. array
covariance
matrix
as follows [2, 1]. Let the digitized quadrature signal at time n from the mth antenna be given
by xm (n). The snapshot vector, x(n), represents all of the antenna signals as
where M is the number of sensors. A block of data, X, representing all snapshot vectors from
n = 1 . . . N , is given by
X = [x(1), x(2), . . . , x(N )].
An estimate of the array-covariance matrix, Rxx is calculated using
where the superscript H represents Hermitian transpose. The operator of the MV beamformer
provides a look direction relative to the array and the DSP uses this to calculate a steering
vector, a. Then the complex weights vector, w, calculated by the DSP is given by
Rxx −1 a
w= . (2)
aH Rxx −1 a
A second non-adaptive beamformer, known as a Fourier beamformer, was also implemented
in the DSP software. The operator could switch between the MV and Fourier beamformers
and this provided a control for verifying the performance of the MV beamformer. The weights
vector from the Fourier beamformer, wF , is equal to the steering vector (wF = a).
Calculating a steering vector, a, for use in (2) involves measurement and interpolation.
Under normal operation, the steering vector for an arbitrary direction is interpolated from a
small set of steering vectors that have been stored in memory. When the system is set up
specially for calibration the DSP can measure steering vectors for given directions and these
are stored for the interpolation step.
We can calculate (1) and (2) with the following Matlab code.
Rxx = XX’ ;
w = (Rxx\a) / (a’*(Rxx\a)) ;
3
The same program in C requires around 200 lines of code. The ASICs’ filtering operation can
be described as wH X. Note that if the MV beamformer fails to work properly, the fault can
lie with either the implementation of (1) or (2), the measurement of the steering vectors or the
interpolation of the steering vectors. In other words, virtually the entire program is suspect if
the beamformer does not operate correctly.
4 Debugging examples
In this section we describe our Matlab-based debugging environment and we give examples of
how we used Matlab to correct two bugs in our DSP software. Section 4.1 describes how we
discovered a problem with the part of the software that calculates the weights and Section 4.2
describes how we discovered a problem with the software that measures the steering vectors. On
the surface, these bugs may seem trivial but, as part of a complex system in which we were, at
the same time, dealing with hardware problems and which contains many interrelated software
functions, even just isolating the functions with the bugs would have been very difficult without
Matlab. Section 4.3 summarizes all of the ways in which we used Matlab in the two debugging
examples.
A serial link from the DSP to a PC was available so that an operator could send commands
to the DSP. Serial ports are a feature of DSPs so even if one is not part of an application there
is no significant extra hardware to implement serial communication with a PC. Simple messages
can be sent to and from the DSP. Each message begins with an integer tag that identifies the
content of the message and the rest of the message is any amount of binary data that we wish
to communicate. When the PC receives a message the operator’s software appends the binary
data to a file on the hard drive. Each message with, its identifying tag, is saved in a unique
file. When enough data has been written to the file or files, Matlab is run and the data is read
with scripts that are tailored to each file. Appendix A has examples of some script files that
we used to read the binary data into Matlab. Using this scheme requires a small processing
overhead on the DSP. This allows the DSP to operate with almost no additional burden and in
real time.
4
difference in performance. Further analysis of the errors showed that they were much less than
the variance of the eigenvectors of the array-covariance matrix estimates which eliminated the
extra signals as the cause of the problem. At this point we tried moving the signal to a different
direction and that caused the Fourier beamformer to stop working also. Now it seemed that
the problem was related to a part of the software that was common to both beamformers. We
verified that the array-covariance matrix was being calculated correctly and that left only the
function that downloaded the weights to the DSP. Having narrowed the problem down to just
one function, we took a very close look at it and realized that, although the ASICs performed
the filtering correctly, the DSP was required to conjugate the weights before downloading them.
We corrected the code in one line and tested the beamformers with the signal at 0◦ azimuth
and elevation again. Both beamformers worked correctly.
28
200
26
24 0
Phase (degrees)
Amplitude
22
−200
20
18
−400
16
14 −600
−50 0 50 −50 0 50
elevation (degrees) elevation (degrees)
(a) (b)
Figure 2: Amplitude (a) and phase (b) of the steering vectors versus elevation.
5
4.3 Summary of the ways we used Matlab
The following list gives all of the ways that we used Matlab as we described in the last two
sections:
1. checked that the calculation of (2) was correct,
2. estimated the condition number of the array-covariance matrix,
3. estimated the eigenvalues of the array-covariance matrix,
4. computed and displayed the power spectrum of the quadrature data,
5. estimated the variance of the eigenvectors of the array-covariance matrix,
6. checked that the calculation of (1) was correct,
7. plotted the measured steering vectors versus direction, and
8. estimated the variances of steering-vector measurements.
5 Conclusion
Normal DSP debugging tools are insufficient to debug some functions of DSP software because
they are too low level in relation to the DSP functions. We have used Matlab as part of
our DSP debugging cycle by exporting data from the DSP to Matlab. We are then able to
verify the operation of the DSP functions and analyze the data further, if necessary. We
gave examples of how we applied Matlab-based debugging to our adaptive digital-beamforming
system. Exporting the data to Matlab was a simple task that did not noticeably burden the
DSP which allowed it to run in real time. Matlab’s powerful functions allowed us to test DSP
results and data, often with a single command. We were able to spot and fix a potential bug,
choosing the order of interpolation to be too high, by viewing data in plots. Using Matlab as
a debugging tool sped our debug cycle by an estimated six times over a normal debugger.
References
[1] Simon Haykin. Array signal processing. Number ISBN 0-13-046482-1 in Signal processing
series. Prentice-Hall, 1985.
[2] S. Unnikrishna Pillai. Array signal processing. Springer-Verlag, 1989.
[3] William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery. Nu-
merical recipes in C. Cambridge University Press, 2nd edition, 1992.
6
% Read the data.
while (~isempty(tmp))
an=an+1;
for c=1:8
for e=1:8
tmp=fread(fd,1,’float’);
if isempty(tmp) break;
else ac(c,e)=tmp; end
ac(c,e)=ac(c,e)+i*fread(fd,1,’float’);
end
end
% Load in the steering vectors that are saved in the file dsp_cal.svc.
% End of file is reached when a fread returns an empty matrix.
ns=1000;
% Close the file and remove the empty parts of the matrices.
fclose(fd);
sv=sv(:,1:c-1);
ld=ld(:,1:c-1);