function channel = probe2channel(probe, config)
% function channel = probe2channel(probe, config)
%
% This function is to convert coordinates of probe to channels
%
% probe: Nx3 matrix, the coordinates of each probe
% config: either '4x4', '3x5' or '3x11'
%
% return:
% channel: Nx3 matrix
%
% Xu Cui
% 2009/06/11
%

if(strcmp(config, '4x4'))
    s = [
            1 2
            2 3
            3 4
            1 5
            2 6
            3 7
            4 8
            5 6
            6 7
            7 8
            5 9
            6 10
            7 11
            8 12
            9 10
            10 11
            11 12
            9 13
            10 14
            11 15
            12 16
            13 14
            14 15
            15 16
            17 18
            18 19
            19 20
            17 21
            18 22
            19 23
            20 24
            21 22
            22 23
            23 24
            21 25
            22 26
            23 27
            24 28
            25 26
            26 27
            27 28
            25 29
            26 30
            27 31
            28 32
            29 30
            30 31
            31 32];
elseif(strcmp(config, '3x5'))
    s = [
            1 2
            2 3
            3 4
            4 5
            1 6
            2 7
            3 8
            4 9
            5 10
            6 7
            7 8
            8 9
            9 10
            6 11
            7 12
            8 13
            9 14
            10 15
            11 12
            12 13
            13 14
            14 15
            16 17
            17 18
            18 19
            19 20
            16 21
            17 22
            18 23
            19 24
            20 25
            21 22
            22 23
            23 24
            24 25
            21 26
            22 27
            23 28
            24 29
            25 30
            26 27
            27 28
            28 29
            29 30];
elseif(strcmp(config, '3x11'))
    s = [
            1 2
            2 3
            3 4
            4 5
            5 6
            6 7
            7 8
            8 9
            9 10
            10 11
            1 12
            2 13
            3 14
            4 15
            5 16
            6 17
            7 18
            8 19
            9 20
            10 21
            11 22
            12 13
            13 14
            14 15
            15 16
            16 17
            17 18
            18 19
            19 20
            20 21
            21 22
            12 23
            13 24
            14 25
            15 26
            16 27
            17 28
            18 29
            19 30
            20 31
            21 32
            22 33
            23 24
            24 25
            25 26
            26 27
            27 28
            28 29
            29 30
            30 31
            31 32
            32 33];
end

for ii=1:size(s,1)
    channel(ii,:) = (probe(s(ii,1),:) + probe(s(ii,2),:)) / 2;
end