'this script is an enhanced version for finding spike events in a waveform channel. It uses a threshold, but after that looks for the maximum of the spike and uses this 'as the event time '--------------------------------------- 'select data channel from which trigger will be get var dataChan%,trigmem%,evint,test1,test2,risefall; evint:=0.008; 'minimum interval from one spike to next (8ms); evint:=evint*1000; 'to have minimum interval im ms WindowVisible (3); 'sets the time view to the front 'select data channel from which trigger will be get DlgCreate("Set Trigger Channel"); DlgChan(1,"Select waveform data channel",1); Dlgreal(2,"Minimum delay to next triggerpoint in ms?",0,5000); Dlglist(3,"rising or falling waveform?","rising|falling"); DlgShow(dataChan%,evint,risefall); 'evint:=Input("Minimum delay to next triggerpoint in ms?", evint, 0, 5000); evint:=evint/1000; 'to get it back to sec trigmem%:=MemChan(3,0); 'make trigchannel CursorDelete(-1); 'delete all Cursors CursorNew(XLow()+1); 'make new cursor at left window edge + 1 sec CursorNew(Xhigh()-1); 'make new cursor at right window edge - 1 sec Interact("Place the cursors around the region to be analysed...", 1023); 'select range CursorRenumber(); 'renumbered cursor -> left cursor becomes cursor 1 HCursorDelete(1);HCursorNew(dataChan%); 'make new horizontal cursor Interact("place Hcursor", 1023); var newmem,firstnewmem,pre,post,countit,mini,maxi,minitime,maxitime; 'define a couple of new variable newmem:=MemChan(2); 'make new memchannel 'we will not show this channel. It is just temporary if risefall=0 then MemImport(newmem, dataChan%, Cursor(1), Cursor(2), 2, evint, HCursor(1)); 'write all spike / artifact events to memchannel, rising waveforn else MemImport(newmem, dataChan%, Cursor(1), Cursor(2), 3, evint, HCursor(1)); 'write all spike / artifact events to memchannel, falling waveform endif; test1:=Cursor(1); '2 variable which remember the cursor times test2:=Cursor(2); 'now lets find the maximum of each spike / artifact and make new memory channel firstnewmem:=nexttime(newmem,0); 'find first spike / artifact event CursorNew(); 'make new cursor draw(firstnewmem-0.02,0.04); 'draw window around first event 'place cursors around first spike/artifact Cursor(1,firstnewmem-0.01); Cursor(2,firstnewmem); Cursor(3,firstnewmem+0.01); interact("set Cursor1 to start of spike/artifact Cursor2 to maximum/minimum and Cursor3 to end",1023); 'let user set the beginning, maximum and end of spike/artifact pre:=Cursor(2)-Cursor(1); 'pre has the time between beginning and maximum of spike/artifact post:=Cursor(3)-Cursor(2); 'post has the time between maximum and end of spike/artifact countit:=firstnewmem; ' now walk along the memchannel with the spike events and find maxima While countit>=0 do minmax(dataChan%,countit-pre,countit+post,mini,maxi,minitime,maxitime); 'maxitime hat zeit des maximums if risefall=0 then Memsetitem(trigmem%, 0, maxitime); 'schreib in Memchan, rising waveforn else Memsetitem(trigmem%, 0, minitime); 'schreib in Memchan, falling waveforn endif; countit:=nexttime(newmem,countit); wend; Chandelete(newmem,0); 'delete the temporary memory channel chantitle$(trigmem%,"trigger"); 'give it a name Chanshow(trigmem%); ' and show the trigger channel Draw(test1,test2-test1); 'draw the selected range