Created
May 10, 2019 15:37
-
-
Save kouichi-c-nakamura/d23cffc14cde7c8846c8d511f228df05 to your computer and use it in GitHub Desktop.
Removal of large FCV artefact online using TTL puses in CED Spike2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'removeFCVartifactForFreya.s2s | |
' See onskel.zip at http://ced.co.uk/downloads/scriptspkmeth | |
'' | |
'it contains toolbar to enable the user to open | |
' a new data file for sampling and start and stop sampling. | |
'It displays the log view at the botton of the screen to place | |
' values in that the user may wish to extract | |
'All on-line analysis should be placed in the idle routine | |
' | |
'Note this script is UNDER DEVELOPMENT BY CED and is included for | |
'illustration only. We make no warranties as to its suitability | |
'or otherwise. It has not been thoroughly tested. | |
'You should use it 'as is' | |
' | |
'Written by Diarmid Campbell for CED September 1997. | |
' Modified by Kouichi C. Nakamura, Ph.D. kouichi.c.nakamura@gmail.com | |
' MRC Brain Network Dyanmics Unit, University of Oxford | |
' May 2019 | |
'### PARAMETERS ############################################### | |
const startArtFromPulse := -0.0105; ' sec, relative to TTL pulses | |
const artDuration := 0.012; ' sec, duration of the artefact | |
var artTTLchan% := 6; | |
'############################################################## | |
var data%; 'Handle of new data file | |
var sTime; 'The last time we looked at the idle routine | |
var memChan% := 0; | |
var startArt := 0; ' sec | |
var endArt := 0; 'sec | |
var endArtFromPulse := artDuration + startArtFromPulse; | |
ToolbarVisible(1); 'Make toolbar visible always | |
data% := View(); | |
New%(); 'Set up new sampling window | |
DoToolbar(); 'Do the toolbar | |
'=============================================================================== | |
func New%() 'New sampling window | |
'View(LogHandle()); 'Make log view the current view | |
'EditSelectAll(); 'Select all text in log view | |
'EditClear(); 'Delete it | |
'Window(0,80,100,100); 'Display it at the bottom of the screen | |
'WindowVisible(1); 'Make it visbible | |
if data%>0 then 'If there is already a data view open then | |
View(data%); 'Close it | |
FileClose(); | |
endif; | |
data%:=FileNew(0,1); 'Open a new data file for sampling | |
if data%<0 then | |
Message("Unable to open new data file"); | |
Halt; | |
endif; | |
if ViewKind(data%) <> 0 then | |
PrintLog(ViewKind(data%)); | |
Halt; | |
endif; | |
View(data%); | |
DrawMode(-1,2); 'Set event draw mode to lines | |
'Window(0,0,100,80); 'Make data window in top bit of screen | |
'XRange(0,10); | |
'FrontView(LogHandle()); 'Bring the Log view to the front | |
'FrontView(data%); 'Bring the data view to the front | |
ToolbarEnable(3,0); 'Disable "Sample stop" button | |
ToolbarEnable(2,1); 'Disable "Sample stop" button | |
ToolbarText("Press SAMPLE START to commence sampling"); | |
memChan% := MemChan(1, 0, 5e-005); 'Add new Waveform channel | |
ChanShow(memChan%); 'Make it visible | |
ChanScale(memChan%, ChanScale(3)); | |
ChanOffset(memChan%, ChanOffset(3)); | |
ChanUnits$(memChan%, ChanUnits$(3)); | |
ChanTitle$(memChan%, ChanTitle$(3) + "_"); | |
YRange(memChan%,-1,1); | |
var comment$ := Print$("startArtFromPulse, %.4f ms; endArtFromPulse, %.4f ms", | |
startArtFromPulse*1000, endArtFromPulse*1000); | |
ChanComment$(memChan%, comment$); | |
return 1; | |
end; | |
'=============================================================================== | |
proc DoToolbar() | |
ToolbarSet(0,"",Idle%); 'Call Idle%() whenever there is free time .... If button 0 is defined with an associated Idle function, that function is called repeatedly while no button is pressed | |
ToolbarSet(1,"Quit",Quit%); 'Set up toolbar buttons | |
ToolbarSet(2,"Sample start", Start%); | |
ToolbarSet(3,"Sample stop", Stop%); | |
ToolbarSet(4,"New file", New%); | |
ToolbarEnable(3,0); 'Disable "Sample stop" button | |
Toolbar("Press SAMPLE START to commence sampling", 1023); 'Wait here until quit is pressed | |
end; | |
'=============================================================================== | |
func Quit%() 'If "Quit" is pressed | |
SampleStop(); 'Stop sampling | |
return 0; 'leave toolbar | |
end; | |
'=============================================================================== | |
func Start%() 'If "Start" is pressed | |
SampleStart(); 'Start sampling | |
ToolbarEnable(4,0); 'Disable "New file" button | |
ToolbarEnable(3,1); 'Enable "Sample stop" button | |
ToolbarEnable(2,0); 'Disable "Sample start" button | |
ToolbarEnable(1,0); 'Disable "Quit" button | |
ToolbarText("Press SAMPLE STOP to stop sampling"); | |
return 1; 'Stay with toolbar | |
end; | |
'=============================================================================== | |
func Stop%() 'If "Stop" is pressed | |
SampleStop(); 'Stop sampling | |
'TODO | |
'Save the memory channel to disk | |
'var dest% := 15; | |
'ChanSave(memChan%, dest%); | |
'ChanShow(dest%); | |
'ChanDelete(memChan%); | |
'memChan% := 0; | |
' | |
ToolbarEnable(4,1); 'Enable "New file" button | |
ToolbarEnable(3,0); 'Disable "Sample stop" button | |
ToolbarEnable(1,1); 'Enable "Quit" button | |
ToolbarText("Press FILE NEW to capture more data"); | |
return 1; 'Stay in toolbar | |
end; | |
'=============================================================================== | |
func Idle%() 'The Idle routine is called when PC has time | |
if ViewKind(data%) <> 0 then | |
Halt; | |
endif | |
View(data%); | |
if startArt > MaxTime() -0.1 then 'too soon | |
return 1; | |
endif | |
if memChan% = 0 then | |
return 1; | |
endif | |
var foundTemp := 0; | |
'foundTemp := NextTime(artTTLchan%,endArt); | |
const dataPoints% := 14;' by CED | |
while foundTemp >= 0 do | |
foundTemp := ChanSearch(artTTLchan%,dataPoints%,endArt,XHigh()); | |
if foundTemp > 0 then ' new event found | |
startArt := foundTemp + startArtFromPulse; | |
if startArt > 0 then | |
MemImport(memChan%,3,endArt, startArt); | |
if startArt < MaxTime() - endArtFromPulse then | |
Yield(endArtFromPulse); ' wait for 12 ms | |
endif | |
endArt := foundTemp + endArtFromPulse; | |
endif; | |
endif | |
wend | |
return 1; 'Stay in toolbar | |
end; | |
'=============================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment