A signal averaging program

Share Embed


Descrição do Produto

Brain Research

Bulkfin,

Vol. 21, pp. 851-8.53. @ Pergamon

Press plc, 1988. Printed

in the

0361.9230/88

U.S.A.

LABORATORY INSTRUMENTATION

$3.00 + .OO

AND COMPUTING

A Signal Averaging Program JAMES

DUFFIN

Departments of Anaesthesia and Physiology University of Toronto, Toronto, Ontario, Canada M5S IA8 Received

14 June

1988

DUFFIN, J. A signal averaging program. BRAIN RES BULL 21(5) 851-853, 1988.-The and software required for an inexpensive signal averaging system.

Averaging

computer

Software

article describes the hardware

Neurophysiology

SIGNAL averaging is a useful method of extracting timelocked signals from noise, and the more specific method of spike-towered averaging of intraceIlular potentials is a useful method (1) of determining synaptic connections within the central nervous system. This paper is a brief description of the implementation of a signal averaging system utilizing an inexpensive computer (Atari 1040 ST) and an analog to digital converter cartridge (SP Innovations Inc.). The intention of the paper is to inform the reader of the existence of such a method of implementing signal averaging, and to describe the assembler code portion of the program so as to assist others to develop their own signal averaging system. Although the hardware described here is specific, it is felt that the assembler code and the algorithm that it represents will be of use to programmers of other computers which use the 68000 microprocessor, such as the Apple Macintosh and Commodore Amiga. Any analog to digital conversion device which presents its data at fixed memory addresses at the required speed would be appropriate. The averaging system described here used two channels of the 8 channel analog to digital converter, one for the trigger signal and the other for the data signal, to make a single channel averager with 8 bit resolution. In this form the averager is capable of collecting data during a triggered sweep of 1024 samples at a maximum rate of 100 kHz.

SOFTWARE

The main body of the program was written with a high level language Modnla-2, which is a moduhuized form of Pascal. The program makes full use of the GEM user interface (designed by Digital Research Inc.) of the Atari ST computer. Drop-down menus, either mouse or keyboard selected, access dialogue boxes for setting up the averager parameters. The parameters are then editable by mouse or keyboard. As well as the usual parameters such as sampling rate, the user can set the total number of sweeps to be acquired, and, because updating the screen display is the slowest aspect of the averager system, the user can set the number of sweeps to be acquired between screen updates. The display of the average may be resealed as well as offset. It can be shown as a series of points or as a line, and with or without a grid. The relevant average parameters are also displayed. The average and its acquisition parameters may be stored on disk for subsequent recall, and the screen may be dumped to a printer. Listing 1 shows the ModuIa-2 source code for the averaging procedure “DoAverage.” The main program passes the number of sweeps to be done (NumberSweeps), the trigger level to be detected (TrigLevel), the address of the start of the average storage buffer (poutput), the number of points or bins per sweep (NumberofBins), and the time between samples or bin width (BinWidth) in sec. From the bin width the variable “delay” is calculated from a formula which is based upon the execution time of the program steps at the Atari ST clock speed of 8 MHz (see Listing 3). The triggering level, delay, number of points or bins and the average storage buffer address are then written into the appropriate bytes in the machine language string (Routine), with the procedure “SweepInit,” from the implementation module “Sweep” in Program Listing 2. The supervisor mode is entered and all inte~pts are turned off before starting the machine language program with

HARDWARE

The analog to digital converter is a cartridge which plugs into the cartridge port of the Atari ST and has 8 analog to digital channels of 8 bit resolution, 2 digitaI to analog channels outputs and 4 latched digital outputs. The converter is accessed by a M0VE.W instruction with the input channel selected in the source address register, and the input from the last conversion deposited in the destination data register. The computer used is an Atari 1040 ST with one megabyte of memory, and a monochrome monitor with a resolution of 640x400 pixels. At the time of writing the total hardware cost was less than $1,3~.~ Canadian (excluding printer).

851

852

DUFFlN PROGPAN

PRKED”RE

Dawerage(

LISTING

1

PROGRAM

window. NumberSweeps “AR

:

MODULE Sweep.

FROM SYSTEM

IMPORT ADR. ADDRESS

LISTING

2

INTEGER:

Countsweeps : INTEGER: TrigLevel poutput NumberofBins. BinWidth : INTEGER)

: mmmE~: : ADDRESS: BOOLEAN

CONST

TYPE

..-.

IMPLEMENTATlON

0”TP”T pO”TP”T

ARRAY [O..l0241 OF LONGINT: POINTER TO OUTPUT:

= =

Routineslze TYPE RO”tl”e

“nR

Delay,i.pOuT AverageOK SSP

: :

pR0U "AR

pOUTPUT: BOOLEAN: LONGCARD.

po"T := poUtput: *"erageoK := TRUE: Delay := (8 * Binwidth - 521 DIV 14: SveepInit(TrigLevel.Delay.NumberofB~ns.pOUTi: WHILE AverageOK DO (* Do Trig and A\D ML *) i := 0: (* supervisor mode on *I CODE~42A7H.3F3CH.002oH,4E4lH,5c6FH~: SSP := LOWGCRRD(REGISTERlO)): CODE(007CH.0600H): DOSWeep: 1 := INTEGER(RECISTER(O,,.

CODE(O~~CH,OF~FFH): supernsar off *I

t*

InterrUDtS off I* do &rage

c* >nterrupts

t* SETREG(O.SSPI:

CODE~2FOOH,3F3CH.0020H.4E41H.5C85Hl IF i = 1 THEN I* Triggered INC~C~~ntSweepsl: END'

c*

Done

ELSE END; IF

enough sweeps2

Status0

AverageoK END: END, IF CountSweeps

r

THEN '= FALSE.

NumberSweeps

an *I

Sweep *I

THEN

!* Key pressed7

PROCEDURE

*,

THEN

RETURN TRUE. ELSE RETVRN FALSE: END; END DoAverage:

SweepInit(Tr~gLeVel.Delay.Slze

HighBuffei.LowBuffer BEGIN HighSuffer~=INTEGER(Polnter

INTEGER:

Pointer

ADDRESS,

DI" 10000H) 207CH:

~~^I131 ML:[161 ;,_t;;;

= = .= = := :=

72~~": ~L~[141 '= 343~~. 383CH: ML:[171 '= Delay: 51C9H: ML_lZOl .= OOOAH: 4CDFW: ML [231 = 07lEH. INTEGER(9651Hl:

6DECH: ML’t281 ML’1301 := INTEGER(OD398Hl: ML-[321 := 6CFCH: ML-031 ~~“[351 .= 700111: ~~“[361 ML-[381 := 071EH: ML-1391 END SveepInlt:

PROCEDURE "AR EXItI

OF INTEGER.

“EiR

ML-[251 ML-[271

a,

CountSweeps < NumberSweeps AYerageOK '= TRUE: AverageOK := FALSE:

IF

*I *I

Rautlnesirel TO Routine:

PRO"

ML

BEGIN

= 100. = ARRAYi = POINTER

:=

36048.

;;_[2;;

:= := :=

51CRH. 3611H. 4E75H.

ML^[341 ML-[371

DoWeep ADDRESS-

TemDRea BEGIN’

ML:[211 ML [241 ML:(Z61

LowBuffer OOOOH: 2000H. TrigLevel Size: 3611H; 7000H: 4E75H: INTEGER(OB64OH). 3212H. 5343li: INTEGER(OFFFBH, 4CDFH.

-

TempReg:'REGISTER,S) SETREG(S.ML): CODE(4E90H,. SETREG(8 TWDR~.J) END

Dosweep:

END

sweep.

(* JSR

(A01 *I

.

Listing I. The Modula-2 program for the procedure “DoAverage.”

Listing 2. The Modula-2 program for the procedures “SweepI&” and “DoSweep.”

the procedure “DoSweep” (Program Listing 2) which executes a JSR to the address of the first byte of the machine language routine. The machine language routine is shown in Listing 3. The program waits a set time for a sweep trigger to be detected, on channel 1, as determined by the value in the register dl (# trigs). If no trigger is detected then register d0 is set to 0, and an RTS is executed. If a trigger is detected then channel 2 data are read and added to the average storage buffer at the appropriate sampling rate. Register d0 is set to 1 and an RTS executed. The “DoAverage” procedure (Listing 1) then restores the interrupt status, returns to user mode, and increments the number of sweeps accumulated (CountSweeps) if a sweep was done. When the required number of sweeps has been completed, or the average has been interrupted by the user, then control is returned to the main program.

following the ADC label in Listing 3. Any changes made to this loop will require a new formula for the “delay” variable. The disadvantage of this timing method is that some choices of binwidth (sampling rate) will not be timed exactly at the faster sampling rates. The error will be constant per sample (bin) however, so that if a calibration pulse is included in the averaged signal, as is usual practice, then the time scale for the average can be determined from that. The program has been validated by computing averages simultaneously with a hard-wired averager (Neurolog NL 750), and Fig. 1 shows calibration pulses of 1 msec width at delays of 2 and 8 msec averaged for 1000 sweeps at 50 kHz for both averagers. The program has been in use in my laboratory for over a year, and has functioned without problems for my particular use of spike triggered averaging of intracellular potentials. This result does not, of course, mean that the program is completely bug-free when used in other circumstances, and it should be meticulously checked for performance in its specific use. A modification was made later to the averager program as described here which utilized the algorithm somewhat differently. During spike-triggered averaging of intracellular potentials, the occurrence of an action potential in the intracellular recording is not permissible, but sometimes difficult to prevent, thereby invalidating the average. With the acquisition of an Atari Mega ST4 computer with 4 megabytes of memory, it became possible to store several thousand sweeps. The averager program was therefore modified to

DISCUSSION

The assembly language program was designed to avoid the use of the system timers and interrupts so as to save the processing time required for their implementation. In order to determine the times for sampling, the program operates the 68000 processor in supervisor mode with other interrupts turned off, and bases its timing on the number of clock cycles per instruction and the 8 MHz clock rate. The variable “delay” in Listing 1 is calculated, based upon the 6 instructions

SIGNAL AVERAGING

PROGRAM

PRoGP.An

LISTING

853 A

3

************************************I*****

*

Averager program detect trigger then : * do sweep addlnq a2d to buffer ********* ****I* ***********************

* * * * * * * *

d0 dl d2 d3 d4 a0 al a2

= = = = = = = =

trig level then trig yes/no =1/O: number of trig loops * buffer length scratch : sampling lnrerval * data buffer address * ACC channel 1 trigger * ACC channel 2 data

PUSH movem.1

dl-dQ/aO-a2:lsp)

INIT movea. movea. movea. move.w move.1 mave.w move.~

YSFFFFFFFF.aO XSOOFBOOOO.al #S00FB2000.?.2 tSFFFF.dO #SFFFFFFFF.dl XlOOO,dZ XSFFFF.d4

* * * * * * *

inove.w dbf

lal).d3 dl.SKIP

* trig 1 * enough ?

moveq.1 movem.1 Its

* Yes XO.dO Lsp)+.dl-d4/aO-a2 * quit

SKIP

s"b." ET:."

(al).d3 dO.d3 TRIG

ADC

ITIOVO.W d4.d3 rnn.'dciw(aZ).dl dl,(aO)t

TRIG

WAIT 6ubq.w bge

data addr * ADC 1 : ADC 2 trig level: # trigs x samples : interval

!

* *

* trig 2 * * > level ? * 8 MHz * No clock Cycles * interval * 4 : z:arata * 8 * 14

!

*

* wait for * delay

* 4 * 8110

dbf

d2,ADC

" done ?

* 14

moveq.1 move.w movcm.1

tl.dO * trig yes * lal).d3 * trig teset* (sp)+,dl-d4/aO-a2

= I52 + 14 * delay)/8

in (IS _

10

* *

Xl.d3 WAIT

TtS * BlnWidth

Tine Rxls

us

*

B8

FIG. 1. (A) An example of the screen display for the averager with two calibration pulses of 1 msec width at 1 and 8 msec delay superimposed on the output of an intracellular amplifier. (B) The same (simultaneous) average as in A computed with the Neurolog NL750, hard-wired averager. Note that the time scales shown are not exactly the same, because the printing devices used were different (Laser printer and XY plotter respectively).

****x*********x*********I**I************

* Program to turn on supervisor mode * * * with no interru ts ~*************x*" P ****************XI"*** c1r.1 move." trap add.1 ori

-(spl ~$20.-(sp) 06.9p WS0600.sr

***************************************** * Program to enable interrupts and * * turn off supervisor mode ****""****""***********************II**: andi move.1 move." trap add.1

XSFZFF.sr dO,-(sp) :;20.-(ap) W6,SP

Listing 3. The Assembly code for the machine language portion of the averager program.

REFERENCE 1. Kirkwood, P. A.; Sears, T. A. The measurement

of synaptic connections in the mammalian central nervous system by means of spike-triggered averaging. In: Desmedt, J. E., ed. Spinal and supraspinal mechanisms of voluntary motor control and locomotion. Progress in clinical neurophysiology. vol. 8. Basel: Karger; 198044-71.

store each sweep rather than accumulate the sum for averaging. Later, off-line, the user can accumulate the average by

examining each sweep in turn and accepting or rejecting it. In this way, it was possible to edit out sweeps containing action potentials, and this ability has allowed the spiketriggered averaging of intracellular potentials of cells which would otherwise have been discarded because their firing could not be suppressed. The system described here is thought to be very cost effective, and lends itself to further development. The software is available from the author by sending a disk, a self-addressed mailer, and an international postal reply coupon to cover the mailing cost.

EQUIPMENT

SOURCES

1. Atari Corp., 11% Borregas Avenue, Sunnyvale, CA 94086. 2. S. P. Innovations Inc., Box 33395, North Royalton, OH 44133, (216) 237-2382. 3. Neurolog., Medical Systems Corp., 1 Plaza Road, Greenvale, NY 11548, (516) 621-9190. 4. Modula-2 language, TDI Software Inc., 10355 Brockwood Rd., Dallas, TX 75238, (214) 340-4942.

Lihat lebih banyak...

Comentários

Copyright © 2017 DADOSPDF Inc.