var n, chan1, chan2,verst, curs1, curs2, oridata1, oridata2, newdata, inv$, memo, sample, zeitv, zeit1, zeit2, neuerKanal; var trigchan, triggers[100],x,y,linksrechts; '****************** comments ****************** ' this script subtracts or adds a waveform channel from / to another ' for this it determines the amplitude difference and the time difference between the channels ' example from the stomatogastric world: You have the same spike on 2 extracellular recordings (e.g. lvn (high) and lgn. ' You want to subtract the LG spikes from the lvn to better see the pyloric neurons. ' The you first need to know how large the spikes are on each recording (they WILL have a different amplitude) ' and then you have to find out whether there is a time difference between the occurrence of the spike on both recordings ' (there will be a difference in this example). ' after that, the channels are subtracted and the result is copied to a memory channel. x:=1; triggers[0]:=0; chan1:=input("number of Channel that will be subtracted",4); chan2:=input("number of Channel from which will be subtracted",3); inv$:=input$("do you want to invert the Channel (=add instead of subtract channel)? (y/n)","n"); sample:=Binsize(chan1); 'get Binsize of data file ' make Cursors HCursordelete(-1); HCursornew(chan1); HCursornew(chan1,HCursor(1)-0.1); HCursorNew(chan2); HCursorNew(chan2,HCursor(3)-0.1); Cursordelete(-1); Cursornew(); Cursornew(Cursor(1)+0.05); '***********messages for Dawn******************* '**** can be deleted **** message("now we have to determine whether the two channels have the same size"); message("so that we can subtract them corretly"); message("Look for a spike of the same neuron on both recordings"); message("and use horizontal Cursors next"); '*** do not delete below this line*** interact("Give lower and upper maximum peak of the spike on both recordings (Cursor 1+3 for one channel, 2+4 for the other)",1023); '***********messages for Dawn******************* '**** can be deleted **** message("Use the vertical Cursors for determining a time shift between the Channels"); '*** do not delete below this line*** interact("Use Cursor to measure time difference between channels (Channel that will be subtracted with Cursor1) ",1023); zeit1:=Cursor(1); zeit2:=Cursor(2); zeitv:=zeit2-zeit1; 'Calculate time delay between both recordings, positive values: chan1 leads chan2 verst:=(HCursor(1)-HCursor(2))/(HCursor(3)-HCursor(4)); 'calculate correction factor for amplitude differences if inv$="y" then verst:=verst*(-1); 'if a channel is inverted we need to add data from chan1 to chan2 instead of subtracting them endif; '***********messages for Dawn******************* '**** can be deleted **** message("you can edit the amplification factor by hand, if you wish to"); '*** do not delete below this line*** verst:=input("the amplification factor between both recordings is ",verst); trigchan:=input("Give Triggerchannel (0 if you don't have a triggerchannel)",5); memo:=Memchan(1,0,sample); 'make memchan if trigchan=0 then 'we have to get the timerange for subtraction interact("Give time area for subtraction with vertical Cursors 1 + 2 angeben, NOT ZERO OR MAXTIME!",1023); curs1:=Cursor(1); curs2:=Cursor(2); repeat oridata1:=Chanvalue(chan1,curs1); oridata2:=Chanvalue(chan2, curs1+zeitv); newdata:=oridata2 - oridata1/verst; memsetitem(memo,0,curs1,newdata); curs1:=curs1+sample; until curs1>=curs2; else 'ok, lets subtract a specific time range around trigger points linksrechts:=input("what time range before and after the trigger events should be subtracted?",1); repeat 'put trigger points in an array triggers[x]:=nexttime(trigchan,triggers[x-1]); x:=x+1; until triggers[x-1]<0; x:=x-1; 'forget the last x because its out of range for y:= 1 to x do curs1:=triggers[y]-linksrechts; 'read array and add range curs2:=triggers[y]+linksrechts; if curs1 > 0 and curs2 < maxtime() then 'only if time is above 0 and below maxtime repeat oridata1:=Chanvalue(chan1,curs1); oridata2:=Chanvalue(chan2, curs1+zeitv); newdata:=oridata2 - oridata1/verst; memsetitem(memo,0,curs1,newdata); curs1:=curs1+sample; until curs1>=curs2; else message("one of the trigger events is too close to zero or maxtime"); endif; next; endif; chanshow(memo); neuerKanal:=input("Write to channel number? Type 0 to only keep it as a memory channel",0,0,32); if neuerKanal>0 then memsave(memo,neuerKanal); chandelete(memo); chanshow(neuerKanal); endif;