Attachment 'split_ctf_recording.m'
Download 1 function split_ctf_recording(origDS, newDSpath, sampRate, totalTrials)
2 % splits CTF .ds recordings into chunks according to the head
3 % movement. Run the Brainstorm process 'process_detect_movement.m' first to get the
4 % headpositions.txt file
5 %
6 % Inputs: origDS - file to split
7 % newDSpath - directory where the new file will be written
8 % sampRate - sampling rate of the data set
9 % totalTrial - total trials in the file
10 %
11 % Elizabeth Bock 2013-2015
12
13 %% Info
14 info = load(fullfile(origDS, 'headpositions.txt'));
15 [p,n] = fileparts(origDS);
16
17 posFile = dir([origDS '/*.pos']);
18 posFile = fullfile(origDS, posFile.name);
19
20 % find files that are > 5 secs
21 len = diff(info(:,1));
22 ind = find(len > sampRate*5);
23 disp(['Files ' num2str(ind') ' are greater than 5 seconds']);
24
25 %% split first chunk
26 if info(1,1) == 1
27 disp('first chunk has a new head position also')
28 % go directly to the 'N-1 chunks' to get the new head position
29 else
30 st = 1;
31 en = round(info(1,1)/sampRate) - 1;
32 newDS = [newDSpath '/' n '_s1.ds'];
33 command = ['ctf newDs -includeTrialRange ' num2str(st) ' ' num2str(en) ' ' origDS ' ' newDS];
34 system(command)
35 try
36 copyfile(posFile,newDS)
37 catch
38 disp (['cannot copy pos file to ' newDS])
39 end
40 end
41
42
43 %% next N-1 chunks
44 for ii = 1:size(info,1) - 1
45 % split next chunk
46 st = max(1,round(info(ii,1)/sampRate));
47 en = round(info(ii+1,1)/sampRate) - 1;
48 newDS = [newDSpath '/' n '_s' num2str(ii+1) '.ds'];
49 command = ['ctf newDs -includeTrialRange ' num2str(st) ' ' num2str(en) ' ' origDS ' ' newDS];
50 system(command)
51
52 % update head position (need mm for input to this function)
53 na = info(ii,3:5).*1000;
54 le = info(ii,6:8).*1000;
55 re = info(ii,9:11).*1000;
56 command = ['ctf changeHeadPos -na ' num2str(na) ' -le ' num2str(le) ' -re ' num2str(re) ' ' newDS];
57 system(command)
58
59 try
60 copyfile(posFile,newDS)
61 catch
62 disp (['cannot copy pos file to ' newDS])
63 end
64 end
65
66 %% last chunk
67 ind = size(info,1);
68 st = round(info(ind,1)/sampRate);
69 en = totalTrials;
70 newDS = [newDSpath '/' n '_s' num2str(ind+1) '.ds'];
71 command = ['ctf newDs -includeTrialRange ' num2str(st) ' ' num2str(en) ' ' origDS ' ' newDS];
72 system(command)
73
74 % update head position
75 na = info(ind,3:5).*1000;
76 le = info(ind,6:8).*1000;
77 re = info(ind,9:11).*1000;
78 command = ['ctf changeHeadPos -na ' num2str(na) ' -le ' num2str(le) ' -re ' num2str(re) ' ' newDS];
79 system(command)
80
81 try
82 copyfile(posFile,newDS)
83 catch
84 disp (['cannot copy pos file to ' newDS])
85 end
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.