-
Notifications
You must be signed in to change notification settings - Fork 0
/
chGeometricLayoutH32_64.m
105 lines (87 loc) · 3.94 KB
/
chGeometricLayoutH32_64.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function [correctedCh, correctedChAbs, conf, nChan] = chGeometricLayoutH32_64(probe, probeFlip, headstage)
% This function maps headstage channels onto recording site coordinates and
% outputs channel geometric correction order for H32 chronic probes
% connected to 64-channel headstages.
% Inputs: probe - probe name, e.g., 'H32_A1x32_Edge_5mm_20_177'.
% probeFlip is true or false.
% headtsage - which headstage was used. At this stage presumes it
% was RHD2164, thus the value should be 'top' if the
% 32ch probe was recorded using RHD2164's top bank, or
% 'bottom' otherwise.
% HEADSTAGE TO PROBE
% Arrange headstage pins to correspond to headstage channels 1 to 16
if strcmpi(headstage, 'top')
[headstageMap, ~, headstageConf] = RHD2164_headstageTopMap_ind2ch;
headstageCh = num2cell(sort(cell2mat(values(headstageMap))));
headstageMap = RHD2164_headstageTopMap_ch2ind;
elseif strcmpi(headstage, 'bottom')
[headstageMap, ~, headstageConf] = RHD2164_headstageBottomMap_ind2ch;
headstageCh = num2cell(sort(cell2mat(values(headstageMap))));
headstageMap = RHD2164_headstageBottomMap_ch2ind;
else
error('Wrong input')
end
headstagePins = cell2mat(values(headstageMap, headstageCh)); % on which pin of the headstage each channel is found
% Probe channels viewed from the headstage
[~, probeCh, probeOutConf] = probeChronicH32Map_ch2ind(probeFlip);
probeCh = fliplr(probeCh);
% Transformation
headstage2probe = num2cell(probeCh(headstagePins));
% HEADSTAGE TO COORDINATES
if strcmp(probe, 'H32-A1x32-Edge-5mm-20-177')
[channelMap, ~, probeInConf] = A32_A1x32_Edge_5mm_20_177_probeMap(); % same as H32...
probeInConf.probe = 'H32-A1x32-Edge-5mm-20-177';
elseif strcmp(probe, 'H32-Buzsaki32-5mm-BUZ-200-160')
[channelMap, ~, probeInConf] = A32_Buzsaki32_5mm_BUZ_200_160_probeMap(); % same as H32...
probeInConf.probe = 'H32-Buzsaki32-5mm-BUZ-200-160';
end
chCoords = cell2mat(values(channelMap,headstage2probe));
% CORRECTED HEADSTAGE CHANNEL ORDER
if strcmp(probe, 'H32-Buzsaki32-5mm-BUZ-200-160')
chCoords = [chCoords(1:2:length(chCoords))' chCoords(2:2:length(chCoords))'];
[~, sortedInd] = sort(chCoords(:,1),'ascend');
chCoords = chCoords(sortedInd,:);
chCoordsSh4 = chCoords(25:32,:);
sortedIndSh4 = sortedInd(25:32,:);
chCoordsSh3 = chCoords(17:24,:);
sortedIndSh3 = sortedInd(17:24,:);
chCoordsSh2 = chCoords(9:16,:);
sortedIndSh2 = sortedInd(9:16,:);
chCoordsSh1 = chCoords(1:8,:);
sortedIndSh1 = sortedInd(1:8,:);
[~, sortedInd] = sort(chCoordsSh1(:,2),'ascend');
chCoordsSh1 = chCoordsSh1(sortedInd,:);
sortedIndSh1 = sortedIndSh1(sortedInd);
[~, sortedInd] = sort(chCoordsSh2(:,2),'ascend');
chCoordsSh2 = chCoordsSh2(sortedInd,:);
sortedIndSh2 = sortedIndSh2(sortedInd);
[~, sortedInd] = sort(chCoordsSh3(:,2),'ascend');
chCoordsSh3 = chCoordsSh3(sortedInd,:);
sortedIndSh3 = sortedIndSh3(sortedInd);
[~, sortedInd] = sort(chCoordsSh4(:,2),'ascend');
chCoordsSh4 = chCoordsSh4(sortedInd,:);
sortedIndSh4 = sortedIndSh4(sortedInd);
sortedInd = [sortedIndSh1; sortedIndSh2; sortedIndSh3; sortedIndSh4];
chCoords = [chCoordsSh1; chCoordsSh2; chCoordsSh3; chCoordsSh4];
else
[~, sortedInd] = sort(chCoords,'ascend');
chCoords = chCoords(sortedInd)';
end
headstageCh = cell2mat(headstageCh);
correctedCh = headstageCh(sortedInd);
correctedChAbs = 1:numel(headstageCh);
correctedChAbs = correctedChAbs(sortedInd);
nChan = numel(correctedChAbs);
% CONFIGURATION
conf.headstageConf = headstageConf;
conf.probeConf = probeInConf;
conf.probeConf.probe = probe;
conf.probeConf.out = probeOutConf.out;
if size(chCoords,2) == 2
conf.probeConf.xcoords = torow(chCoords(:,1));
conf.probeConf.ycoords = torow(chCoords(:,2));
elseif size(chCoords,2) == 1
conf.probeConf.ycoords = torow(chCoords);
else
error('Erroneous probe recording site coordinates');
end