0001 function [stim, meas_sel]= mk_stim_patterns( ...
0002 n_elec, n_rings, inj, meas, options, amplitude)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 if ischar(n_elec) && strcmp(n_elec,'UNIT_TEST'); do_unit_test; return; end
0081
0082 if nargin<6; amplitude= .01; end
0083 if nargin<5; options= {}; end
0084 v = process_args(n_elec, n_rings, inj, meas, options, amplitude );
0085
0086 [stim,mpat ] = calc_stim(v, n_elec, n_rings);
0087
0088
0089 v.do_redundant = 1; v.use_meas_current = 1;
0090 [jnk ,mpat0] = calc_stim(v, n_elec, n_rings);
0091
0092
0093 meas_sel= meas_select( mpat, mpat0);
0094
0095 function [stim,mpat] = calc_stim(v, n_elec, n_rings)
0096 curr_pat = v.inj(:) * ones(1,n_elec);
0097 meas_pat = v.meas(:) * ones(1,n_elec);
0098 offset = [1;1]*(0:n_elec-1);
0099
0100 stim= struct([]);
0101 mpat= struct([]);
0102 i=1; j=1;
0103 for ring = 0:v.n_rings-1
0104 seen_patterns= struct;
0105 for elec= 0:v.n_elec-1
0106 if v.trig_inj && elec == v.n_elec-1 ; continue; end
0107 s_pat= mk_stim_pat(v, elec, ring );
0108 m_pat= mk_meas_pat(v, elec, ring );
0109
0110 if v.do_redundant == 0
0111 [m_pat, seen_patterns] = elim_redundant(m_pat, s_pat, seen_patterns);
0112 end
0113
0114 if ~isempty(m_pat)
0115 stim(i).stimulation = 'Amp';
0116 stim(i).stim_pattern= sparse(s_pat);
0117 stim(i).meas_pattern= sparse(m_pat);
0118 i=i+1;
0119 end
0120 mpat(j).meas_pattern= sparse(m_pat);
0121 j=j+1;
0122 end
0123 end
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 function meas_sel= meas_select( mpat, mpat0);
0152 meas_sel = [];
0153 for i=1:length(mpat);
0154 [mset, err ] = mk_meas_set( mpat(i).meas_pattern );
0155 [mset0, err0] = mk_meas_set( mpat0(i).meas_pattern );
0156 if err || err0; msel_i = 1 + 0*mset;
0157 else msel_i = ismember(mset0,mset);
0158 end
0159 meas_sel = [meas_sel; msel_i];
0160 end
0161
0162 meas_sel = logical(meas_sel(:));
0163
0164 function [mset,err] = mk_meas_set( meas_pat )
0165 mpats= size(~meas_pat,1);
0166 mset = zeros(mpats,1);
0167 err=0;
0168 for i=1:size(meas_pat,1);
0169 mpat = meas_pat(i,:);
0170 fp = find(mpat>0); if length(fp)==0; fp = 0; end
0171 fn = find(mpat<0); if length(fn)==0; fn = 0; end
0172 if length(fp)>1 || length(fn)>1 ; err=1; return; end
0173 mset(i) = fp*1e7 + fn;
0174 end
0175
0176 function stim_pat = mk_stim_pat(v, elec, ring );
0177 stim_pat = sparse(v.tn_elec, 1);
0178 if v.balance_inj
0179 stim_pat= stim_pat - sum(v.i_factor)/ (v.tn_elec-1);
0180 elseif v.trig_inj
0181 stim_pat = trig_pat( elec, v.tn_elec, v.trig_inj) * v.amplitude;
0182 return;
0183 end
0184
0185 stim_idx = rem( v.inj + elec, v.n_elec) + 1 + v.n_elec*ring;
0186 stim_pat( stim_idx ) = v.amplitude*v.i_factor;
0187
0188
0189
0190 function meas = mk_meas_pat(v, elec, ring );
0191 meas= sparse(v.tn_elec, v.tn_elec);
0192 if v.balance_meas
0193 meas= meas - sum(v.m_factor)/ (v.tn_elec-1);
0194 elseif v.trig_meas
0195 meas= trig_pat( 1:v.tn_elec, v.tn_elec)';
0196 return;
0197 end
0198
0199 if v.rotate_meas
0200 ofs = elec;
0201 else
0202 ofs = 0;
0203 end
0204
0205 mseq= 0:v.tn_elec-1;
0206 within_ring = rem(v.n_elec + mseq , v.n_elec);
0207 ouside_ring = floor( mseq / v.n_elec) * v.n_elec;
0208 meas_seq = mseq *v.tn_elec + 1;
0209
0210 for i=1:length(v.meas)
0211 meas_pat = rem( v.meas(i) + within_ring + ofs, v.n_elec ) + ...
0212 ouside_ring + meas_seq;
0213 meas(meas_pat) = v.m_factor(i);
0214 end
0215
0216 if v.use_meas_current == 0
0217
0218
0219 stim_idx = rem( v.inj + elec, v.n_elec) + 1 + v.n_elec*ring;
0220
0221 if v.use_meas_current_next
0222
0223
0224
0225 for ni= -v.use_meas_current_next:v.use_meas_current_next;
0226 stim_idx = [stim_idx, ...
0227 rem( v.inj + elec + ni, v.n_elec) + 1 + v.n_elec*ring];
0228 end
0229 stim_idx = unique(stim_idx);
0230 stim_idx(stim_idx<=0) = stim_idx(stim_idx<=0) + v.n_elec;
0231 end
0232 elim= any(meas(stim_idx,:),1);
0233 meas(:,elim) = [];
0234 end
0235
0236 meas= meas';
0237
0238
0239 function v = process_args(n_elec, n_rings, inj, meas, options, amplitude )
0240
0241
0242 v.trig_meas= 0;
0243 v.trig_inj = 0;
0244
0245 v.use_meas_current = 0;
0246 v.use_meas_current_next = 0;
0247 v.rotate_meas = 0;
0248 v.do_redundant = 1;
0249 v.balance_inj = 0;
0250 v.balance_meas= 0;
0251
0252
0253
0254 if ischar(inj)
0255 if strcmp(inj,'{ad}')
0256 inj= [0, 1];
0257 rel_ampl= [-1;1];
0258 elseif strcmp(inj,'{op}')
0259 inj= [0, floor(n_elec/2)];
0260 rel_ampl= [-1;1];
0261 elseif strcmp(inj,'{trig}')
0262 v.trig_inj = 1;
0263 v.use_meas_current = 1;
0264 rel_ampl= [];
0265 elseif strcmp(inj,'{trigcscs}')
0266 v.trig_inj = 1;
0267 v.use_meas_current = 1;
0268 rel_ampl= [];
0269 elseif strcmp(inj,'{trigccss}')
0270 v.trig_inj = 2;
0271 v.use_meas_current = 1;
0272 rel_ampl= [];
0273 elseif strcmp(inj,'{mono}')
0274 inj= [0];
0275 rel_ampl= [1];
0276 else
0277 error(['parameter inj=',inj,' not understood']);
0278 end
0279 elseif prod(size(inj))==1
0280 rel_ampl= [1];
0281 elseif prod(size(inj))==2
0282 rel_ampl= [-1;1];
0283 else
0284 error(['parameter inj not understood']);
0285 end
0286
0287 v.inj= inj;
0288 v.i_factor= rel_ampl;
0289
0290
0291
0292
0293 if ischar(meas)
0294 if strcmp(meas,'{ad}')
0295 meas= [0, 1];
0296 rel_ampl= [ 1;-1];
0297 elseif strcmp(meas,'{op}')
0298 meas= [0, floor(n_elec/2)];
0299 rel_ampl= [ 1;-1];
0300 elseif strcmp(meas,'{trig}')
0301 v.trig_meas= 1;
0302 rel_ampl= [ 1;-1];
0303 elseif strcmp(meas,'{mono}')
0304 meas= [0];
0305 rel_ampl= [1];
0306 else
0307 error(['parameter meas=',meas,' not understood']);
0308 end
0309 elseif prod(size(meas))==1
0310 rel_ampl= [1];
0311 elseif prod(size(meas))==2
0312 rel_ampl= [ 1;-1];
0313 else
0314 error(['parameter meas not understood']);
0315 end
0316
0317 v.meas= meas;
0318 v.m_factor= rel_ampl;
0319
0320 v.n_elec = n_elec;
0321 v.n_rings= n_rings;
0322 v.tn_elec= n_rings * n_elec;
0323 v.amplitude = amplitude;
0324
0325 v= parse_options(v, options);
0326
0327 function v= parse_options(v, options);
0328
0329 for opt = options
0330 if strcmp(opt, 'no_meas_current')
0331 v.use_meas_current = 0;
0332 v.use_meas_current_next = 0;
0333 elseif strcmp(opt, 'no_meas_current_next1')
0334 v.use_meas_current = 0;
0335 v.use_meas_current_next = 1;
0336 elseif strcmp(opt, 'no_meas_current_next2')
0337 v.use_meas_current = 0;
0338 v.use_meas_current_next = 2;
0339 elseif strcmp(opt, 'no_meas_current_next3')
0340 v.use_meas_current = 0;
0341 v.use_meas_current_next = 3;
0342 elseif strcmp(opt, 'meas_current')
0343 v.use_meas_current = 1;
0344 elseif strcmp(opt, 'rotate_meas')
0345 v.rotate_meas = 1;
0346 elseif strcmp(opt, 'no_rotate_meas')
0347 v.rotate_meas = 0;
0348 elseif strcmp(opt, 'do_redundant')
0349 v.do_redundant = 1;
0350 elseif strcmp(opt, 'no_redundant')
0351 v.do_redundant = 0;
0352 elseif strcmp(opt, 'balance_inj')
0353 v.balance_inj = 1;
0354 elseif strcmp(opt, 'no_balance_inj')
0355 v.balance_inj = 0;
0356 elseif strcmp(opt, 'balance_meas')
0357 v.balance_meas= 1;
0358 elseif strcmp(opt, 'no_balance_meas')
0359 v.balance_meas= 0;
0360 else
0361 error(['option parameter opt=',opt,' not understood']);
0362 end
0363 end
0364
0365 function [m_pat, seen_patterns] = elim_redundant(m_pat, s_pat, seen_patterns);
0366 m_pat_new= sparse([]);
0367 s_pat_str= ['s',sprintf('%d_', find(s_pat) ),'m'];
0368 for j=1:size(m_pat,1);
0369 this_m_pat= m_pat(j,:);
0370 pat_str= [s_pat_str, sprintf('%d_', find(this_m_pat))];
0371 if ~isfield(seen_patterns,pat_str);
0372 m_pat_new= [m_pat_new;this_m_pat];
0373
0374 seen_patterns.(pat_str)= 1;
0375
0376 pat_str= ['s',sprintf('%d_', find(this_m_pat) ), ...
0377 'm',sprintf('%d_', find(s_pat))];
0378 seen_patterns.(pat_str)= 1;
0379 end
0380 end
0381 m_pat= m_pat_new;
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391 function pat= trig_pat( elec_sel, n_elecs, sel);
0392 if nargin<3; sel=1; end
0393 idx= linspace(0,2*pi,n_elecs+1)'; idx(end)= [];
0394 omega= idx*[1:n_elecs/2];
0395 meas_pat= [cos(omega), sin(omega) ];
0396 if sel==1;
0397
0398 order = reshape(1:n_elecs,[],2)';
0399 meas_pat= meas_pat(:,order(:));
0400 end
0401 meas_pat= meas_pat(:,1:end-1);
0402 pat = meas_pat(:, elec_sel+1);
0403
0404 function trig_tests;
0405 stim = mk_stim_patterns(8,1,'{trig}',[0,1],{},2);
0406 t= linspace(0,2*pi,8+1)'; t(end)= [];
0407 unit_test_cmp('trig: t1',[stim(1:4).stim_pattern], ...
0408 2*[cos(t),sin(t),cos(2*t),sin(2*t)], 1e-10);
0409
0410 stim = mk_stim_patterns(8,1,'{trigcscs}',[0,1],{},2);
0411 unit_test_cmp('trig: t2',[stim(1:4).stim_pattern], ...
0412 2*[cos(t),sin(t),cos(2*t),sin(2*t)], 1e-10);
0413
0414 stim = mk_stim_patterns(8,1,'{trigccss}',[0,1],{},2);
0415 test = 2*[cos(t),cos(2*t),cos(3*t), cos(4*t), sin(t),sin(2*t),sin(3*t)];
0416 unit_test_cmp('trig: t2',[stim(:).stim_pattern], test, 1e-10);
0417
0418 function do_unit_test
0419 trig_tests;
0420 stim = mk_stim_patterns(4,1,[0,1],[0,1],{},1);
0421 unit_test_cmp('t1',stim(1).stim_pattern, [-1;1;0;0]);
0422 unit_test_cmp('t2',stim(4).stim_pattern, [1;0;0;-1]);
0423 unit_test_cmp('t3',stim(1).meas_pattern, [0,0,1,-1]);
0424 unit_test_cmp('t4',stim(4).meas_pattern, [0,1,-1,0]);
0425
0426
0427
0428 stim = mk_stim_patterns(4,1,[0,1],[0,1],{'meas_current'},1);
0429 unit_test_cmp('meas_current: t1',stim(1).meas_pattern, ...
0430 [1,-1,0,0; 0,1,-1,0; 0,0,1,-1; -1,0,0,1]);
0431 unit_test_cmp('meas_current: t2',stim(4).stim_pattern, [1;0;0;-1]);
0432 stim = mk_stim_patterns(4,1,[0,1],[0,1],{'no_meas_current'},1);
0433 unit_test_cmp('meas_current: t3',stim(1).meas_pattern, [0,0,1,-1]);
0434 unit_test_cmp('meas_current: t2',stim(4).stim_pattern, [1;0;0;-1]);
0435
0436
0437
0438
0439 stim = mk_stim_patterns(6,1,[0,1],[0,1],{'no_rotate_meas'},1);
0440 unit_test_cmp('no_rotate_meas: t1',stim(2).stim_pattern, [0;-1;1;0;0;0]);
0441 unit_test_cmp('no_rotate_meas: t2',stim(2).meas_pattern, ...
0442 [0,0,0,1,-1,0; 0,0,0,0,1,-1; -1,0,0,0,0,1]);
0443 unit_test_cmp('no_rotate_meas: t3',stim(3).stim_pattern, [0;0;-1;1;0;0]);
0444 unit_test_cmp('no_rotate_meas: t4',stim(3).meas_pattern, ...
0445 [1,-1,0,0,0,0;0,0,0,0,1,-1; -1,0,0,0,0,1]);
0446
0447 stim = mk_stim_patterns(6,1,[0,1],[0,1],{'rotate_meas'},1);
0448 unit_test_cmp('rotate_meas: t1',stim(2).stim_pattern, [0;-1;1;0;0;0]);
0449 unit_test_cmp('rotate_meas: t2',stim(2).meas_pattern, ...
0450 [0,0,0,1,-1,0; 0,0,0,0,1,-1; -1,0,0,0,0,1]);
0451 unit_test_cmp('rotate_meas: t3',stim(3).stim_pattern, [0;0;-1;1;0;0]);
0452 unit_test_cmp('rotate_meas: t4',stim(3).meas_pattern, ...
0453 [0,0,0,0,1,-1; -1,0,0,0,0,1; 1,-1,0,0,0,0]);
0454
0455
0456
0457 stim = mk_stim_patterns(6,1,[0,1],[0,1],{'do_redundant'},1);
0458
0459 unit_test_cmp('do_redundant: t0',length(stim), 6);
0460 unit_test_cmp('do_redundant: t1',stim(2).stim_pattern, [0;-1;1;0;0;0]);
0461 unit_test_cmp('do_redundant: t2',stim(2).meas_pattern, ...
0462 [0,0,0,1,-1,0; 0,0,0,0,1,-1; -1,0,0,0,0,1]);
0463 unit_test_cmp('do_redundant: t3',stim(3).stim_pattern, [0;0;-1;1;0;0]);
0464 unit_test_cmp('do_redundant: t4',stim(3).meas_pattern, ...
0465 [1,-1,0,0,0,0;0,0,0,0,1,-1; -1,0,0,0,0,1]);
0466
0467 stim = mk_stim_patterns(6,1,[0,1],[0,1],{'no_redundant'},1);
0468 unit_test_cmp('no_redundant: t0',length(stim), 4);
0469 unit_test_cmp('no_redundant: t1',stim(2).stim_pattern, [0;-1;1;0;0;0]);
0470 unit_test_cmp('no_redundant: t2',stim(2).meas_pattern, ...
0471 [0,0,0,1,-1,0; 0,0,0,0,1,-1; -1,0,0,0,0,1]);
0472 unit_test_cmp('no_redundant: t3',stim(3).stim_pattern, [0;0;-1;1;0;0]);
0473 unit_test_cmp('no_redundant: t4',stim(3).meas_pattern, ...
0474 [0,0,0,0,1,-1;-1,0,0,0,0,1]);
0475 unit_test_cmp('no_redundant: t5',stim(4).meas_pattern, ...
0476 [-1,0,0,0,0,1]);
0477
0478
0479
0480
0481 stim = mk_stim_patterns(4,1,'{mono}',[0,1],{'balance_inj','meas_current'},1);
0482 unit_test_cmp('balance_inj: t0',length(stim), 4,1);
0483 unit_test_cmp('balance_inj: t1',stim(2).stim_pattern, -[1;-3;1;1]/3);
0484 unit_test_cmp('balance_inj: t2',stim(2).meas_pattern, ...
0485 [1,-1,0,0;0,1,-1,0;0,0,1,-1;-1,0,0,1]);
0486
0487 stim = mk_stim_patterns(4,1,'{mono}',[0,1],{'no_balance_inj','no_meas_current'},1);
0488 unit_test_cmp('no_balance_inj: t0',length(stim), 4,1);
0489 unit_test_cmp('no_balance_inj: t1',stim(2).stim_pattern, [0;1;0;0]);
0490 unit_test_cmp('no_balance_inj: t2',stim(2).meas_pattern, ...
0491 [0,0,1,-1;-1,0,0,1]);
0492
0493 stim = mk_stim_patterns(4,1,'{mono}',[0,1],{},1);
0494 unit_test_cmp('no_balance_inj: t0',length(stim), 4,1);
0495 unit_test_cmp('no_balance_inj: t1',stim(2).stim_pattern, [0;1;0;0]);
0496
0497
0498
0499
0500 stim = mk_stim_patterns(4,1,[0,1],'{mono}',{'no_balance_meas','meas_current'},1);
0501 unit_test_cmp('no_balance_meas: t0',length(stim), 4,1);
0502 unit_test_cmp('no_balance_meas: t1',stim(2).stim_pattern, [0;-1;1;0]);
0503 unit_test_cmp('no_balance_meas: t1',stim(2).meas_pattern, eye(4));
0504
0505 stim = mk_stim_patterns(4,1,[0,1],'{mono}',{'meas_current'},1);
0506 unit_test_cmp('no_balance_meas: t0',length(stim), 4,1);
0507 unit_test_cmp('no_balance_meas: t1',stim(2).stim_pattern, [0;-1;1;0]);
0508 unit_test_cmp('no_balance_meas: t1',stim(2).meas_pattern, eye(4));
0509
0510 stim = mk_stim_patterns(4,1,[0,1],'{mono}',{'no_meas_current'},1);
0511 unit_test_cmp('no_balance_meas: t0',length(stim), 4,1);
0512 unit_test_cmp('no_balance_meas: t1',stim(2).stim_pattern, [0;-1;1;0]);
0513 unit_test_cmp('no_balance_meas: t1',stim(2).meas_pattern, [1,0,0,0;0,0,0,1]);
0514
0515 stim = mk_stim_patterns(4,1,[0,1],'{mono}',{},1);
0516 unit_test_cmp('no_balance_meas: t0',length(stim), 4,1);
0517 unit_test_cmp('no_balance_meas: t1',stim(2).stim_pattern, [0;-1;1;0]);
0518 unit_test_cmp('no_balance_meas: t1',stim(2).meas_pattern, [1,0,0,0;0,0,0,1]);
0519
0520 stim = mk_stim_patterns(4,1,[0,1],'{mono}',{'balance_meas','meas_current'},1);
0521 unit_test_cmp('balance_meas: t0',length(stim), 4);
0522 unit_test_cmp('balance_meas: t1',stim(2).stim_pattern, [0;-1;1;0]);
0523 unit_test_cmp('balance_meas: t1',stim(2).meas_pattern, (4*eye(4)-ones(4))/3);
0524
0525 stim = mk_stim_patterns(4,1,[0,1],[0,1],{},2);
0526 unit_test_cmp('amplitude: t1',stim(2).stim_pattern, [0;-2;2;0]);
0527 stim = mk_stim_patterns(4,1,'{ad}',[0,1],{},2);
0528 unit_test_cmp('amplitude: t2',stim(2).stim_pattern, [0;-2;2;0]);
0529 stim = mk_stim_patterns(4,1,'{mono}',[0,1],{'no_balance_inj'},2);
0530 unit_test_cmp('amplitude: t3',stim(2).stim_pattern, [0;2;0;0]);
0531 stim = mk_stim_patterns(4,1,'{mono}',[0,1],{},2);
0532 unit_test_cmp('amplitude: t4',stim(2).stim_pattern, [0;2;0;0]);
0533
0534 [stim,msel] = mk_stim_patterns(6,1,[0,2],[0,1],{'meas_current','no_rotate_meas'},2);
0535 msel = reshape(msel, 6, 6);
0536 unit_test_cmp('meas_sel: t1',msel(:,6), [1;1;1;1;1;1]);
0537
0538 [stim,msel] = mk_stim_patterns(6,1,[0,2],[0,1],{'meas_current','rotate_meas'},2);
0539 msel = reshape(msel, 6, 6);
0540 unit_test_cmp('meas_sel: t1',msel(:,6), [1;1;1;1;1;1]);
0541
0542 [stim,msel] = mk_stim_patterns(6,1,[0,1],[0,1],{'no_meas_current','no_rotate_meas'},2);
0543 msel = reshape(msel, 6, 6);
0544 unit_test_cmp('meas_sel: t1',msel(:,6), [0;1;1;1;0;0]);
0545
0546 [stim,msel] = mk_stim_patterns(6,1,[0,2],[0,1],{'meas_current','no_rotate_meas'},2);
0547 msel = reshape(msel, 6, 6);
0548 unit_test_cmp('meas_sel: t1',msel(:,6), [1;1;1;1;1;1]);
0549
0550 [stim,msel] = mk_stim_patterns(6,1,[0,1],[0,1],{'no_meas_current','no_rotate_meas'},2);
0551 msel = reshape(msel, 6, 6);
0552 unit_test_cmp('meas_sel: nnp01',msel(:,[4,5]), [1,1;1,1;0,1;0,0;0,0;1,0]);
0553
0554 [stim,msel] = mk_stim_patterns(6,1,[0,2],[0,1],{'no_meas_current','no_rotate_meas'},2);
0555 msel = reshape(msel, 6, 6);
0556 unit_test_cmp('meas_sel: nnp02',msel(:,[4,5]), [1,0;1,1;0,1;0,0;0,0;0,0]);
0557
0558 [stim,msel] = mk_stim_patterns(6,1,[0,3],[0,1],{'no_meas_current','no_rotate_meas'},2);
0559 msel = reshape(msel, 6, 6);
0560 unit_test_cmp('meas_sel: nnp03',msel(:,[4,5]), [0,0;1,0;0,1;0,0;1,0;0,1]);
0561
0562 [stim,msel] = mk_stim_patterns(6,1,[1,2],[0,1],{'no_meas_current','no_rotate_meas'},2);
0563 msel = reshape(msel, 6, 6);
0564 unit_test_cmp('meas_sel: nnp12',msel(:,[4,5]), [1,0;1,1;1,1;0,1;0,0;0,0]);
0565
0566 [stim,msel] = mk_stim_patterns(6,1,[2,4],[0,1],{'no_meas_current','no_rotate_meas'},2);
0567 msel = reshape(msel, 6, 6);
0568 unit_test_cmp('meas_sel: nnp24',msel(:,[4,5]), [0,0;0,0;1,0;1,1;0,1;0,0]);
0569
0570 [stim,msel] = mk_stim_patterns(6,1,[2,4],[3,6],{'no_meas_current','no_rotate_meas'},2);
0571 msel = reshape(msel, 6, 6);
0572 unit_test_cmp('meas_sel: nnp2436',msel(:,[4,5]), [1,0;0,1;0,0;1,0;0,1;0,0]);
0573
0574 [stim,msel] = mk_stim_patterns(6,1,[0,1],[0,1],{'no_meas_current','rotate_meas'},2);
0575 msel = reshape(msel, 6, 6);
0576 unit_test_cmp('meas_sel: nrp01',msel(:,6), [0;0;1;1;1;0]);
0577
0578 [stim,msel] = mk_stim_patterns(6,1,[0,2],[0,1],{'no_meas_current','rotate_meas'},2);
0579 msel = reshape(msel, 6, 6);
0580 unit_test_cmp('meas_sel: nrp02',msel(:,6), [0;0;0;1;1;0]);
0581
0582 [stim,msel] = mk_stim_patterns(6,1,[0,2],[3,4],{'no_meas_current','rotate_meas'},2);
0583 msel = reshape(msel, 6, 6);
0584 unit_test_cmp('meas_sel: nrp0234',msel(:,6), [1;1;0;0;0;0]);
0585
0586 [stim,msel] = mk_stim_patterns(6,1,[0,1],[0,1],{'no_meas_current','no_rotate_meas','no_redundant'},2);
0587 msel = reshape(msel, 6, 6);
0588 unit_test_cmp('meas_sel: nnp01',msel(:,[2,5]), [0,0;0,0;0,0;1,0;1,0;1,0]);
0589
0590 [stim,msel] = mk_stim_patterns(6,1,[0,2],'{mono}',{'no_meas_current','no_rotate_meas'},2);
0591 msel = reshape(msel, 6, 6);
0592 unit_test_cmp('meas_sel: nnp2436',msel(:,[4,5]), [1,0;1,1;1,1;0,1;1,0;0,1]);
0593
0594 [stim,msel] = mk_stim_patterns(16,1,[0,1],[0,1],{'no_meas_current_next1','no_rotate_meas'},1);
0595 unit_test_cmp('meas_sel: next1a',msel(48+(1:16)), [1;0;0;0;0;0;1;1;1;1;1;1;1;1;1;1]);
0596 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next1','no_rotate_meas'},1);
0597 unit_test_cmp('meas_sel: next1b',msel(48+(1:16)), [1;1;0;0;0;1;1;0;0;0;1;1;1;0;0;0]);
0598 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next1','rotate_meas'},1);
0599 unit_test_cmp('meas_sel: next1c',msel(48+(1:16)), [0;0;1;1;0;0;0;1;1;1;0;0;0;1;1;0]);
0600
0601 [stim,msel] = mk_stim_patterns(16,1,[0,1],[0,1],{'no_meas_current_next2','no_rotate_meas'},1);
0602 unit_test_cmp('meas_sel: next2a',msel(48+(1:16)), [0;0;0;0;0;0;0;1;1;1;1;1;1;1;1;1]);
0603 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next2','no_rotate_meas'},1);
0604 unit_test_cmp('meas_sel: next2b',msel(48+(1:16)), [0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;0]);
0605 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next2','rotate_meas'},1);
0606 unit_test_cmp('meas_sel: next2c',msel(48+(1:16)), [0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0]);
0607
0608 [stim,msel] = mk_stim_patterns(16,1,[0,1],[0,1],{'no_meas_current_next3','no_rotate_meas'},1);
0609 unit_test_cmp('meas_sel: next3a',msel(48+(1:16)), [0;0;0;0;0;0;0;0;1;1;1;1;1;1;1;0]);
0610 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next3','no_rotate_meas'},1);
0611 unit_test_cmp('meas_sel: next3b',msel(48+(1:16)), [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0]);
0612 [stim,msel] = mk_stim_patterns(16,1,[0,5],[0,5],{'no_meas_current_next3','rotate_meas'},1);
0613 unit_test_cmp('meas_sel: next3c',msel(48+(1:16)), [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0]);
0614
0615
0616
0617
0618
0619 pat= mk_stim_patterns(16,1,'{ad}','{ad}',{}, 1);
0620 test_adj(pat);
0621
0622 options= {'no_rotate_meas'};
0623 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0624 test_adj(pat);
0625
0626 options= {'no_rotate_meas', 'no_meas_current'};
0627 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0628 test_adj(pat);
0629
0630 options= {'no_rotate_meas', 'meas_current'};
0631 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0632 test_adj_full(pat);
0633
0634 options= {'meas_current'};
0635 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0636 test_adj_full(pat);
0637
0638 options= {'rotate_meas'};
0639 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0640 test_adj_rotate(pat);
0641
0642 options= {'rotate_meas', 'no_meas_current'};
0643 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0644 test_adj_rotate(pat);
0645
0646 options= {'rotate_meas','no_redundant', 'no_meas_current'};
0647 pat= mk_stim_patterns(16,1,'{ad}','{ad}', options,1);
0648 test_adj_no_redund(pat);
0649
0650 function ok= test_adj(pat)
0651
0652
0653 unit_test_cmp('pt#01', length(pat), 16);
0654 unit_test_cmp('pt#02', pat(1).stimulation, 'Amp');
0655 unit_test_cmp('pt#03', pat(1).stim_pattern, [-1;1;zeros(14,1)]);
0656
0657 meas= pat(1).meas_pattern;
0658 unit_test_cmp('pt#04', size(meas), [13 16] );
0659 unit_test_cmp('pt#05', meas(1,:), [0,0,1,-1,zeros(1,12)] );
0660 unit_test_cmp('pt#06', meas(13,:), [zeros(1,14),1,-1] );
0661 unit_test_cmp('pt#07', pat(10).stim_pattern , [zeros(9,1);-1;1;zeros(5,1)] );
0662
0663 meas= pat(10).meas_pattern;
0664 unit_test_cmp('pt#08', size(meas), [13 16] );
0665 unit_test_cmp('pt#09', meas(1,:), [1,-1,zeros(1,14)] );
0666 unit_test_cmp('pt#10', meas(13,:), [-1,zeros(1,14),1] );
0667
0668 function ok= test_adj_full(pat)
0669
0670
0671 unit_test_cmp('pt#11', length(pat), 16);
0672 unit_test_cmp('pt#12', pat(1).stimulation, 'Amp');
0673 unit_test_cmp('pt#13', pat(1).stim_pattern, [-1;1;zeros(14,1)]);
0674
0675 meas= pat(1).meas_pattern;
0676 unit_test_cmp('pt#14', size(meas), [16 16] );
0677 unit_test_cmp('pt#15', meas(1,:), [1,-1,zeros(1,14)] );
0678 unit_test_cmp('pt#16', meas(13,:), [zeros(1,12),1,-1,0,0] );
0679 unit_test_cmp('pt#17', pat(10).stim_pattern, [zeros(9,1);-1;1;zeros(5,1)] );
0680
0681 meas= pat(10).meas_pattern;
0682 unit_test_cmp('pt#18', size(meas), [16 16] );
0683 unit_test_cmp('pt#19', meas(1,:), [1,-1,zeros(1,14)] );
0684 unit_test_cmp('pt#20', meas(13,:), [zeros(1,12),1,-1,0,0] );
0685
0686
0687 function ok= test_adj_rotate(pat)
0688
0689
0690 unit_test_cmp('pt#21', length(pat), 16);
0691 unit_test_cmp('pt#22', pat(1).stimulation, 'Amp');
0692 unit_test_cmp('pt#23', pat(1).stim_pattern, [-1;1;zeros(14,1)]);
0693
0694 meas= pat(1).meas_pattern;
0695 unit_test_cmp('pt#24', size(meas), [13 16] );
0696 unit_test_cmp('pt#25', meas(1,:), [0,0,1,-1,zeros(1,12)] );
0697 unit_test_cmp('pt#26', meas(13,:), [zeros(1,14),1,-1] );
0698 unit_test_cmp('pt#27', pat(10).stim_pattern, [zeros(9,1);-1;1;zeros(5,1)] );
0699
0700 meas= pat(10).meas_pattern;
0701 unit_test_cmp('pt#28', size(meas), [13 16] );
0702 unit_test_cmp('pt#29', meas(1,:), [zeros(1,11),1,-1,zeros(1,3)] );
0703 unit_test_cmp('pt#30', meas(13,:), [zeros(1,7),1,-1,zeros(1,7)] );
0704
0705 function ok= test_adj_no_redund(pat)
0706
0707
0708 unit_test_cmp('pt#31', length(pat), 14);
0709 unit_test_cmp('pt#32', pat(1).stimulation, 'Amp');
0710 unit_test_cmp('pt#33', pat(1).stim_pattern, [-1;1;zeros(14,1)]);
0711
0712 meas= pat(1).meas_pattern;
0713 unit_test_cmp('pt#34', size(meas), [13 16] );
0714 unit_test_cmp('pt#35', meas(1,:), [0,0,1,-1,zeros(1,12)] );
0715 unit_test_cmp('pt#36', meas(13,:), [zeros(1,14),1,-1] );
0716 unit_test_cmp('pt#37', pat(10).stim_pattern, [zeros(9,1);-1;1;zeros(5,1)] );
0717
0718 meas= pat(10).meas_pattern;
0719 unit_test_cmp('pt#38', size(meas), [5 16] );
0720 unit_test_cmp('pt#39', meas(1,:), [zeros(1,11),1,-1,zeros(1,3)] );
0721 unit_test_cmp('pt#40', meas(5,:), [-1,zeros(1,14),1] );
0722