0001 function [thrad,thdeg] = space_electrodes(spacing_type, n_elecs, params);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if ischar(spacing_type) && strcmp(spacing_type,'UNIT_TEST'); do_unit_test; return; end
0015
0016 switch spacing_type
0017 case 'ellipse';
0018 thrad = ellip_space_elecs( n_elecs, params );
0019 otherwise
0020 error('spacing_type not recognized')
0021 end
0022
0023 thdeg = 180/pi*thrad;
0024
0025
0026 function th = ellip_space_elecs( n_elecs, rad )
0027
0028
0029
0030
0031 if n_elecs==0; th=[]; return; end
0032
0033 th = linspace(0,2*pi, 100*(n_elecs)); th(1)=[];
0034 len = cumsum( sqrt( rad(1)*cos(th).^2 + rad(2)*sin(th).^2 ) );
0035 len = len/max(len);
0036 xi = linspace(0,1,n_elecs+1); xi(1)= []; xi(end)=[];
0037 yi = interp1(len,th,xi);
0038
0039 th= [0;yi(:)];
0040 for exact = 0:3;
0041 eth = exact/2*pi;
0042 ff = abs(th-eth)<1e-3;
0043 th(ff) = eth;
0044 end
0045
0046
0047 function do_unit_test
0048 th = space_electrodes('ellipse',16,[1,1]);
0049 unit_test_cmp('circle', th(1), 0, 1e-14);
0050 unit_test_cmp('circle', diff(th), 2*pi/16, 1e-14);
0051
0052 th = space_electrodes('ellipse',16,[1,2]);
0053 unit_test_cmp('ellipse [1,2]', th(1), 0, 1e-14);
0054 unit_test_cmp('ellipse [1,2]', [th(1), min(diff(th)) max(diff(th))], ...
0055 [ 0 0.340379981348740 0.462371789340561 ], 1e-14);