103 
NEURAL NETWORKS FOR TEMPLATE MATCHING: 
APPLICATION TO REAL-TIME CLASSIFICATION 
OF THE ACTION POTENTIALS OF REAL NEURONS 
Yiu-fai Wong, Jashojiban Banik]. and James M. Bower$ 
]'Division of Engineering and Applied Science 
$Division of Biology 
California Institute of Technology 
Pasadena, CA 91125 
ABSTRACT 
Much experimental study of real neural networks relies on the proper classification of 
extracellulary sampled neural signals (i.e. action potentials) recorded from the brains of ex- 
perimental animals. In most neurophysiology laboratories this classification task is simplified 
by limiting investigations to single, electrically well-isolated neurons recorded one at a time. 
However, for those interested in sampling the activities of many single neurons simultaneously, 
waveform classification becomes a serious concern. In this paper we describe and constrast 
three approaches to this problem each designed not only to recognize isolated neural events, 
but also to separately classify temporally overlapping events in real time. First we present two 
formulations of waveform classification using a neural network template matching approach. 
These two formulations are then compared to a simple template matching implementation. 
Analysis with real neural signals reveals that simple template matching is a better solution to 
this problem than either neural network approach. 
INTRODUCTION 
For many years, neurobiologists have been studying the nervous system by 
using single electrodes to serially sample the electrical activity of single neu- 
rons in the brain. However, as physiologists and theorists have become more 
aware of the complex, nonlinear dynamics of these networks, it has become 
apparent that serial sampling strategies may not provide all the information 
necessary to understand functional organization. In addition, it will likely be 
necessary to develop new techniques which sample the activities of multiple 
neurons simultaneously 1. Over the last several years, we have developed two 
different methods to acquire multineuron data. Our initial design involved 
the placement of many tiny microelectrodes individually in a tightly packed 
pseudo-floating configuration within the brain 2. More recently we have been 
developing a more sophisticated approach which utilizes recent advances in 
silicon technology to fabricate multi-ported silicon based electrodes (Fig. 1). 
Using these electrodes we expect to be able to readily record the activity pat- 
terns of larger number of neurons. 
As research in multi-single neuron recording techniques continue, it has be- 
come very clear that whatever technique is used to acquire neural signals from 
many brain locations, the technical difficulties associated with sampling, data 
compressing, storing, analyzing and interpreting these signals largely dwarf the 
development of the sampling device itself. In this report we specifically consider 
the need to assure that neural action potentials (also known as "spikes") on 
each of many parallel recording channels are correctly classified, which is just 
one aspect of the problem of post-processing multi-single neuron data. With 
more traditional single electrode/single neuron recordings, this task usually in- 
American Institute of Physics 1988 
104 
volves passing analog signals through a Schmidt trigger whose output indicates 
the occurence of an event to a computer, at the same time as it triggers an 
oscilloscope sweep of the analog data. The experimenter visually monitors the 
oscilloscope to verify the accuracy of the discrimination as a well-discriminated 
signal from a single neuron will overlap on successive oscilloscope traces (Fig. 
lc). Obviously this approach is impractical when large numbers of channels 
are recorded at the same time. Instead, it is necessary to automate this classifi- 
cation procedure. In this paper we will describe and contrast three approaches 
we have developed to do this. 
layer 
Traces 
on lower 
layer 
., ,, ; 
0 1 
2 3 4 
me (mc) 
Receding site b. 
75 sq 
Fig. 1. Silicon probe being developed in our lababoratory for multi-single unit recording 
in cerebellax cortex. a) a complete probe; b) surface view of one recording tip; c) several 
superhnposed neuronal action potentials recorded from such a silicon electrode in cerebellax 
cortex. 
While our principal design objective is the assurance that neural waveforms 
are adequately discriminated on multiple channels, technically the overall ob- 
jective of this research project is to sample from as many single neurons as 
possible. Therefore, it is a natural extention of our effort to develop a neural 
waveform classification scheme robust enough to allow us to distinguish activi- 
ties arising from more than one neuron per recording site. To do this, however, 
we now not only have to determine that a particular signal is neural in origin, 
but also from which of several possible neurons it arose (see Fig. 2a). While 
in general signals from different neurons have different waveforms aiding in 
the classification, neurons recorded on the same channel firing simultaneously 
or nearly simultaneously will produce novel combination waveforms (Fig. 2b) 
which also need to be classified. It is this last complication which particularly 
105 
bedevils previous efforts to classify neural signals (For review see 5, also see 
3-4). In summary, then, our objective was to design a circuit that would: 
1. distinguish different waveforms even though neuronal discharges tend 
to be quite similar in shape (Fig. 2a); 
2. recognize the same waveform even though unavoidable movements 
such as animal respiration often result in periodic changes in the amplitude 
of a recorded signal by moving the brain relative to the tip of the electrode; 
3. be considerably robust to recording noise which variably corrupts all 
neural recordings (Fig. 2); 
4. resolve overlapping waveforms, which are likely to be particularly in- 
teresting events from a neurobiological point of view; 
5. provide real-time performance allowing the experimenter to detect 
problems with discrimination and monitor the progress of the experiment; 
6. be implementable in hardware due to the need to classify neural sig- 
nals on many channels simultaneously. Simply duplicating a software-based 
algorithm for each channel will not work, but rather, multiple, small, in- 
dependent, and programmable hardware devices need to be constructed. 
1 1 
signal recorded 
2 2 
t 5o v 
electrode 
a. 
Fig. 2. a) Schematic diagram of an electrode recording from two neuronal cell bodies b) An 
actual multi-neuron recording. Note the similarities in the two waveforms and the overlapping 
event. c) and d) Synthesized data with different noise levels for testing classification algorithms 
(c: 0.3 NSR; d: 1.1 NSR). 
106 
METHODS 
The problem of detecting and classifying multiple neural signals on sin- 
gle voltage records involves two steps. First, the waveforms that are present 
in a particular signal must be identified and the templates be generated; 
second, these waveforms must be detected and classified in ongoing data 
records. To accomplish the first step we have modified the principal com- 
ponent analysis procedure described by Abeles and Goldstein 3 to automat- 
ically extract templates of the distinct waveforms found in an initial sam- 
ple of the digitized analog data. This will not be discussed further as it is 
the means of accomplishing the second step which concerns us here. Specif- 
ically, in this paper we compare three new approaches to ongoing wave- 
form classification which deal explicitly with overlapping spikes and vari- 
ably meet other design criteria outlined above. These approaches consist of 
a modified template matching scheme, and two applied neural network im- 
plementations. We will first consider the neural network approaches. On 
a point of nomenclature, to avoid confusion in what follows, the real neu- 
rons whose signals we want to classify will be referred to as "neurons" while 
computing elements in the applied neural networks will be called "Hopons." 
Neural Network Approach -- Overall, the problem of classifying neural 
waveforms can best be seen as an optimization problem in the presence of 
noise. Much recent work on neural-type network algorithms has demonstrated 
that these networks work quite well on problems of this sort 6-8. In particular, 
in a recent paper Hopfield and Tank describe an A/D converter network and 
suggest how to map the problem of template matching into a similar context 8. 
The energy functional for the network they propose has the form: 
where T/j = connectivity between Hopon i and Hopon j, V/ = voltage output 
of Hopon i, Ii = input current to Hopon i and each Hopon has a sigmoid 
input-output characteristic V -- g(u) = 1/(1 + exp(-au)). 
If the equation of motion is set to be: 
dui/dt = -OE/OV =  TsV  + I 
(la) 
then we see that dE/dt = -(j TiVj + Ii)dV/dt - -(du/dt)(dV/dt) = 
-g'(u)(du/dt) 2 50. Hence E will go to to a minimum which, in a network 
constructed as described below, will correspond to a proposed solution to a 
particular waveform classification problem. 
Template Matching using a Hopfield-type Neural Net -- We have 
taken the following approach to template matching using a neural network. For 
simplicity, we initially restricted the classification problem to one involving two 
waveforms and have accordingly constructed a neural network made up of two 
groups of Hopons, each concerned with discriminating one or the other wave- 
form. The classification procedure works as follows: first, a Schmidt trigger 
107 
is used to detect the presence of a voltage on the signal channel above a set 
threshold. When this threshold is crossed, implying the presence of a possible 
neural signal, 2 msecs of data around the crossing are stored in a buffer (40 
samples at 20 KHz). Note that biophysical limitations assure that a single real 
neuron cannot discharge more than once in this time period, so only one wave- 
form of a particular type can occur in this data sample. Also, action potentials 
are of the order of i msec in duration, so the 2 msec window will include the full 
signal for single or overlapped waveforms. In the next step (explained later) 
the data values are correlated and passed into a Hopfield network designed to 
minimize the mean-square error between the actual data and the linear com- 
bination of different delays of the templates. Each Hopon in the set of Hopons 
concerned with one waveform represents a particular temporal delay in the 
occurrence of that waveform in the buffer. To express the network in terms of 
an energy function formulation: Let x(t) - input waveform amplitude in the 
ttn time bin, sj(t) -- amplitude of the jtn template, Vj denote if sj(t- k)(j n 
template delayed by k time bins)is present in the input waveform. Then the 
appropriate energy function is: 
1 2 
t j,k 
i ,. V.(Vj _ 1)s(t- k) 
2 
+q 
j,kl <k2 
(2) 
The first term is designed to minimize the mean-square error and specifies 
the best match. Since V C [0, 1], the second term is minimized only when each 
Vj assumes values 0 or 1. It also sets the diagonal elements T/j to 0. The 
third term creates mutual inhibition among the processing nodes evaluating 
the same neuronal signal, which as described above can only occur once per 
sample. 
Expanding and simplifying expression (2), the connection matrix is: 
T(j,),(j2,) = { 
--  'jl (t - k)sia(t - k2) - '5 
t (3a) 
0 ifj=j2, k=k 
and the input current 
i (t-k) 
I. :  x(t)si(t - k) -   sl 
t t 
(3b) 
As it can be seen, the inputs are the correlations between the actual data and 
the various delays of the templates subtracting a constant term. 
Modified Hopfield Network -- As documented in more detail in Fig. 
3-4, the above full Hopfield-type network works well for temporally isolated 
spikes at moderate noise levels, but for overlapping spikes it has a local minima 
problem. This is more severe with more than two waveforms in the network. 
108 
Further, we need to build our network in hardware and the full Hopfield net- 
work is difficult to implement with current technology (see below). For these 
reasons, we developed a modified neural network approach which significantly 
reduces the necessary hardware complexity and also has improved performance. 
To understand how this works, let us look at the information contained in the 
quantities Ti5 and Ii5 (eq. 3a and 3b ) and make some use of them. These 
quantities have to be calculated at a pre-processing stage before being loaded 
into the Hopfield network. If after calculating these quantities, we can quickly 
rule out a large number of possible template combinations, then we can sig- 
nificantly reduce the size of the problem and thus use a much smaller (and 
hence more efficient) neural network to find the optimal solution. To make the 
derivation simple, we define slightly modified versions of T/i and Ii5 (eq. 4a 
and 4b) for two-template case. 
Ti5 = Z sl(t - i)s.(t - j) (4a) 
t 
[ 1 1 1 
Iff =  x(t) s(t - i) + s2(t - j)] -   s(t - i) -   s(t - j) (4b) 
t t t 
In the case of overlaping spikes the T/i's are the cross-correlations between s (t) 
and s2 (t) with different delays and Iis's are the cross-correlations between input 
x(t) and weighted combination of s(t) and s(t). Now if x(t) = s(t- i) + 
s. (t - j) (i.e. the overlap of the first template with i time bin delay and the 
second template with j time bin delay), then Ai5 = ITi- Iii]: 0. However 
in the presence of noise, Aij will not be identically zero, but will equal to the 
noise, and if A,i > AT/ (where AT/i = IT/5 - Tvi, I for i  i  and j  j) this 
simple algorithm may make unacceptable errors. A solution to this problem 
for overlapping spikes will be described below, but now let us consider the 
problem of classifying non-overlapping spikes. In this case, we can compare 
the input cross-correlation with the auto-correlations (eq. 4c and 4d). 
7[: . s(t- i); T[' = '. s(t - i) (4c) 
t t 
I:  x(t)s(t - i); I'=  x(t)s2(t - i) 
t t 
(4d) 
So for non-overlapping cases, if x(t) = s(t- i), then A; = IT[ - 11 = 0. If 
x(t): s=(t - i), then A:': IT['- IJ' I = 0. 
In the absence of noise, then the minimum of AiS, A'i and A{ represents the 
correct classification. However, in the presence of noise, none of these quantities 
will be identically zero, but will equal the noise in the input x(t) which will 
give rise to unacceptible errors. Our solution to this noise related problem is 
to choose a few minima (three have chosen in our case) instead of one. For 
each minimum there is either a known corresponding linear combination of 
templates for overlapping cases or a simple template for non-overlapping cases. 
A three neuron Hopfield-type network is then programmed so that each neuron 
corresponds to each of the cases. The input x(t) is fed to this tiny network to 
resolve whatever confusion remains after the first step of %ross-correlation" 
comparisons. (Note: Simple template matching as described below can also be 
used in the place of the tiny Hop field type network.) 
109 
Simple Template Matching -- To evaluate the performances of these 
neural network approaches, we decided to implement a simple template match- 
ing scheme, which we will now describe. However, as documented below, this 
approach turned out to be the most accurate and require the least complex 
hardwaxe of any of the three approaches. The first step is, again, to fill a buffer 
with data based on the detection of a possible neural signal. Then we calculate 
the difference between the recorded waveform and all possible combinations of 
the two previously identified templates. Formally, this consists of calculating 
the distances between the input x(m) and all possible cases generated by all 
the combinations of the two templates. 
= Ix(t) - {s(t - i) + s(t - 
t 
di- -.[x(t)- i)l; d'[ = lx(t)- i)l 
t t 
d,i, -' rnin( dij, d' i, d',') 
d,i, gives the best fit of all possible combinations of templates to the actual 
voltage signal. 
TESTING PROCEDURES 
To compare the performance of each of the three approaches, we devised a 
common set of test data using the following procedures. First, we used the prin- 
cipal component method of Abeles and Goldstein 3 to generate two templates 
from a digitized analog record of neural activity recorded in the cerebellum 
of the rat. The two actual spike waveform templates we decided to use had 
a peak-to-peak ratio of 1.375. From a second set of analog recordings made 
from a site in the cerebellum in which no action potential events were evident, 
we determined the spectral characteristics of the recording noise. These two 
components derived from real neural recordings were then digitally combined, 
the objective being to construct realistic records, while also knowing absolutely 
what the correct solution to the template matching problem was for each oc- 
curring spike. As shown in Fig. 2c and 2d, data sets corresponding to different 
noise to signal ratios were constructed. We also carried out simulations with 
the amplitudes of the templates themselves varied in the synthesized records to 
simulate waveform changes due to brain movements often seen in real record- 
ings. In addition to two waveform test sets, we also constructed three waveform 
sets by generating a third template that was the average of the first two tem- 
plates. To further quantify the comparisons of the three diffferent approaches 
described above we considered non-overlapping and overlapping spikes sepa- 
rately. To quantify the performance of the three different approaches, two 
standards for classification were devised. In the first and hardest case, to be 
judged a correct classification, the precise order and timing of two waveforms 
had to be reconstructed. In the second and looser scheme, classification was 
judged correct if the order of two waveforms was correct but timing was al- 
lowed to vary by 100 secs(i.e. +2 time bins) which for most neurobiological 
applications is probably sufficient resolution. Figs. 3-4 compare the perfor- 
mance results for the three approaches to waveform classification implemented 
as digital simulations. 
11o 
PERFORMANCE COMPARISON 
Two templates - non-overlapping waveforms: As shown in Fig. 3a, at 
low noise-to-signal ratios (NSRs below .2) each of the three approaches were 
comparable in performance reaching close to 100% accuracy for each criterion. 
As the ratio was increased, however the neural network implementations did 
less and less well with respect to the simple template matching algorithm with 
the full Hop field type network doing considerably worse than the modified 
network. In the range of NSR most often found in real data (.2 - .4) simple 
template matching performed considerably better than either of the neural 
network approaches. Also it is to be noted that simple template matching 
gives an estimate of the goodness of fit betwwen the waveform and the closest 
template which could be used to identify events that should not be classified 
(e.g. signals due to noise). 
.Z .4 .G .8 
noise level: 3a/peak amplitude 
.2 .4 .6 .B 
noise level: 3(r/peak amplitude 
degrees of overlap 
light line -- absolute criteria 
heavy line -- less stringent criteria 
simple template matching 
Hopfield network 
modified Hop field network 
Fig. 3. Comparisons of the three approaches detecting two non-overlapping (a), and over- 
lapping (b) waveforms, c) compares the performances of the neural network approaches for 
different degrees of waveform overlap. 
Two' templates - overlapping waveforms: Fig. 3b and 3c compare perfor- 
mances when waveforms overlapped. In Fig. 3b the serious local minima prob- 
lem encountered in the full neural network is demonstrated as is the improved 
performance of the modified network. Again, overall performance in physi- 
111 
ological ranges of noise is clearly best for simple template matching. When 
the noise level is low, the modified approach is the better of the two neural 
networks due to the reliability of the correlation number which reflects the 
resemblence between the input data and the template. When the noise level 
is high, errors in the correlation numbers may exclude the right combination 
from the smaller network. In this case its performance is actually a little worse 
than the larger Hopfield network. Fig. 3c documents in detail which degrees 
of overlap produce the most trouble for the neural network approaches at av- 
erage NSR levels found in real neural data. It can be seen that for the neural 
networks, the most serious problem is encountered when the delays between 
the two waveforms are small enough that the resulting waveform looks like the 
larger waveform with some perturbation. 
Three templates - overlappin9 and non-overlappin9: In Fig. 4 are shown 
the comparisons between the full Hopfield network approach and the simple 
template matching approach. For nonoverlapping waveforms, the performance 
of these two approaches is much more comparable than for the two waveform 
case (Fig. 4a), although simple template matching is still the optimal method. 
In the overlapping waveform condition, however, the neural network approach 
fails badly (Fig. 4b and 4c). For this particular application and implementa- 
tion, the neural network approach does not scale well. 
ao 
Co 
2 
bo 
.2 .4 .6 .8 1. 
noise level: 3a/peak amplitude 
.2 .4 .fi .11 I.B 
noise level: 3a/peak amplitude 
O .2 .4 .& .8 
noise level: 3r/peak amplitude 
Hopfield network 
simple template matching 
light line -- absolute criteria 
heavy line -- less stringent criteria 
rr = variance of the noise 
Fig. 4. Comparisons of performance for three waveforms. a) nonoverlapping waveforms; b) 
two waveforms overlapping; c) three waveforms overlapping. 
HARDWARE COMPARISONS 
As described earlier, an important design requirement for this work was the 
ability to detect neural signals in analog records in real-time originating from 
112 
many simultaneously active sampling electrodes. Because it is not feasible to 
run the algorithms in a computer in real time for all the channels simultane- 
ously, it is necessary to design and build dedicated hardware for each channel. 
To do this, we have decided to design VLSI implementations of our circuitry. 
In this regard, it is well recognized that large modifiable neural networks need 
very elaborate hardware implementations. Let us consider, for example, im- 
plementing hardwaxes for a two-template case for comparisons. Let n = no. 
of neurons per template (one neuron for each delay of the template), rn = 
no. of iterations to reach the stable state (in simulating the discretized dif- 
ferential equation, with step size = 0.05), l = no. of samples in a template 
tj(rn). Then, the number of connections in the full Hopfield network will be 
4n 2. The total no. of synaptic calculations = 4rnn . So, for two templates 
and n = 16, rn = 100, 4rnn  = 102,400. Thus building the full Hopfield-type 
network digitally requires a system too large to be put in a single VLSI chip 
which will work in real time. If we want to build an analog system, we need 
to have many (O(4n2)) easily modifiable synapses. As yet this technology is 
not available for nets of this size. The modified Hopfield-type network on the 
other hand is less technically demanding. To do the preprocessing to obtain 
the minimum values we have to do about n 2 = 256 additions to find all possible 
Iijs and require 256 subtractions and comparisons to find three minima. The 
costs associated with doing input cross-correlations are the same as for the full 
neural network (i.e. 2nl = 768(/ = 24) multiplications). The saving with the 
modified approach is that the network used is small and fast (120 multiplica- 
tions and 120 additions to construct the modifiable synapses, no. of synaptic 
calculations = 90 with m = 10, n = 3). 
In contrast to the neural networks, simple template matching is simple 
indeed. For example, it must perform about n2l + n'= 10, 496 additions and 
n 2 = 256 comparisons to find the minimum dii. Additions are considerably less 
costly in time and hardware than multiplications. In fact, because this method 
needs only addition operations, our preliminary design work suggests it can be 
built on a single chip and will be able to do the two-template classification 
in as little as 20 microseconds. This actually raises the possibility that with 
switching and buffering one chip might be able to service more than one channel 
in essentially real time. 
CONCLUSIONS 
Template matching using a full Hopfield-type neural network is found to 
be robust to noise and changes in signal waveform for the two neural waveform 
classification problem. However, for a three-waveform case, the network does 
not perform well. Further, the network requires many modifiable connections 
and therefore results in an elaborate hardware implementation. The overall 
performance of the modified neural network approach is better than the full 
Hopfield network approach. The computation has been reduced largly and 
the hardware requirements are considerably less demanding demonstrating the 
value of designing a specific network to a specified problem. However, even the 
modified neural network performs less well than a simple template-matching 
algorithm which also has the simplest hardware implementation. Using the 
simple template matching algorithm, our simulations suggest it will be pos- 
sible to build a two or three waveform classifier on a single VLSI chip using 
CMOS technology that works in real time with excellent error characteristics. 
Further, such a chip will be able to accurately classify variably overlapping 
113 
neural signals. 
REFERENCES 
[1] G. L. Gerstein, M. J. Bloom, I. E. Espinosa, S. Evanczuk & M. R. Turner, 
IEEE Trans. Sys. Cyb. Man., SMC-13,668(1983). 
2 J.M. Bower & R. Llinas, Soc. Neurosci. Abst., 9, 607(1983). 
3 M. Abeles & M. H. Goldstein, Proc. IEEE, 65, 2(1977). 
W. M. Roberts & D. K. Hartline, Brain Res.-94, 141(1976). 
E.M. Schmidt, J. of Neurosci. Methods, 12, 95(1984). 
J. J. Hopfield, Proc. Natl. Acad. Sci.(USA), 81, 3088(1984). 
J. J. Hopfield & D. W. Tank, Biol. Cybern., 52, 141(1985). 
D. W. Tank & J. J. Hopfield, IEEE Trans. Circuits Syst., CAS-33, 
533(1986). 
ACKNOWLEDGEMENTS 
We would like to acknowledge the contribution of Dr. Mark Nelson to the intellectual 
development of these projects and the able assistance of Herb Adams, Mike Walshe and John 
Powers in designing and constructing support equipment. This work was supported by NIH 
grant NS22205, the Whitaker Foundation and the Joseph Drown Foundation. 
