0001 function idxr = reciprocity_idx( fmdl);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if isstr(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0019
0020 sm_0= []; sm_r = [];
0021 for stim = fmdl.stimulation(:)';
0022 sp = stim.stim_pattern';
0023 nsp = sum(abs(sp))/2;
0024 mp = stim.meas_pattern;
0025 sp = ones(size(mp,1),1)*sp;
0026 sm_0= [sm_0; [sp/nsp, mp*nsp]];
0027 sm_r= [sm_r; [mp, sp]];
0028 end
0029 idxr = ones(size(sm_0,1),1);
0030 for i=1:size(idxr)
0031 sm0i= ones(size(sm_0,1),1)*sm_0(i,:);
0032 mm= all( abs(sm0i - sm_r) < 1e-10, 2);
0033 mp= all( abs(sm0i + sm_r) < 1e-10, 2);
0034 m = [find(mm), find(mp)];
0035 if length(m)>1;
0036 meas= sprintf('%d,',m);
0037 error('More than one reciprocal measure %d=>(%s). Giving up', i,meas);
0038 elseif length(m)==0;
0039 idxr(i) = NaN;
0040 else
0041 idxr(i) = m;
0042 end
0043 end
0044
0045 function do_unit_test
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 tst.stimulation = mk_stim_patterns(8,1,[0,1],[0,1],{'rotate_meas'},1);
0057 idx = reciprocity_idx( tst ); idx = reshape(idx,5,8);
0058 unit_test_cmp('8-[01]-[01]-rotate',idx(:,[1,5]), ...
0059 [15,19,23,27,31;35,39,3,7,11]');
0060
0061 tst.stimulation = mk_stim_patterns(8,1,[0,1],[0,1],{'rotate_meas'},10);
0062 idx = reciprocity_idx( tst ); idx = reshape(idx,5,8);
0063 unit_test_cmp('8(10)-[01]-[01]-rotate',idx(:,[1,5]), ...
0064 [15,19,23,27,31;35,39,3,7,11]');
0065
0066
0067
0068
0069
0070
0071
0072
0073 tst.stimulation = mk_stim_patterns(6,1,[0,1],[0,1],{'rotate_meas'},1);
0074 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0075 unit_test_cmp('6-[01]-[01]-rotate',idx(:,[1,4]), [9,11,13;18 2 4]');
0076
0077 tst.stimulation = mk_stim_patterns(6,1,[0,1],[0,1],{'no_rotate_meas'},1);
0078 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0079 unit_test_cmp('6-[01]-[01]-no_rotate',idx(:,[1,4]), [7,10,13;2 4 18]');
0080
0081
0082
0083
0084
0085
0086
0087
0088 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'rotate_meas'},1);
0089 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0090 unit_test_cmp('6-[02]-[02]-rotate',idx(:,[1,4]), [6,11,16;15,2,7]');
0091
0092 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'no_rotate_meas'},1);
0093 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0094 unit_test_cmp('6-[02]-[02]-no_rotate',idx(:,[1,4]), [4,10,16;2,8,14]');
0095
0096
0097
0098
0099
0100
0101
0102
0103 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'meas_current','rotate_meas'},1);
0104 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0105 unit_test_cmp('6-[02]-[02]-mc-rotate',idx(:,[1,4]), ...
0106 [ 1,12,17,22,27,32;19,30,35,4,9,14]');
0107
0108 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'meas_current','no_rotate_meas'},1);
0109 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0110 unit_test_cmp('6-[02]-[02]-mc-no_rotate',idx(:,[1,4]), ...
0111 [ 1,7,13,19,25,31; 4,10,16,22,28,34]');
0112
0113 tst.stimulation = mk_stim_patterns(6,1,[0,4],[0,4],{'meas_current','no_rotate_meas'},1);
0114 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0115 unit_test_cmp('6-[04]-[04]-mc-no_rotate',idx(:,[1,4]), ...
0116 [ 1,7,13,19,25,31; 4,10,16,22,28,34]');