MONO2SIM transform monopolar stimulation into another stim pattern S = MONO2STIM(M, STIM) is the measurement corresponding to a stimulation and measurement pattern STIM, as created with e.g. MK_STIM_PATTERNS, obtained from a transformation of the monopolar measurments M. The monopolar stimulation pattern with which M was calculated must be MSP = mk_stim_patterns(E,R,'{mono}','{mono}', {'meas_current'},1); where E is the number of electrodes per ring and R is the number of rings. STIM must use the same set of electrodes as MSP. M can be an EIDORS data struct with a 'meas' field, a Jacobian matrix, or a matrix of voltages. See also MK_STIM_PATTERNS, STIM_MEAS_LIST, FWD_SOLVE, CALC_JACOBIAN
0001 function out = mono2stim(mat, stim) 0002 % MONO2SIM transform monopolar stimulation into another stim pattern 0003 % S = MONO2STIM(M, STIM) is the measurement corresponding to a 0004 % stimulation and measurement pattern STIM, as created with e.g. 0005 % MK_STIM_PATTERNS, obtained from a transformation of the monopolar 0006 % measurments M. The monopolar stimulation pattern with which M was 0007 % calculated must be 0008 % MSP = mk_stim_patterns(E,R,'{mono}','{mono}', {'meas_current'},1); 0009 % where E is the number of electrodes per ring and R is the number of 0010 % rings. 0011 % 0012 % STIM must use the same set of electrodes as MSP. 0013 % 0014 % M can be an EIDORS data struct with a 'meas' field, a Jacobian matrix, 0015 % or a matrix of voltages. 0016 % 0017 % See also MK_STIM_PATTERNS, STIM_MEAS_LIST, FWD_SOLVE, CALC_JACOBIAN 0018 0019 % (C) 2022 Bartek Grychtol. License: GPL version 2 or 3 0020 % $Id: mono2stim.m 6316 2022-04-21 11:14:35Z aadler $ 0021 0022 if nargin==1 && ischar(mat) && strcmp(mat, 'UNIT_TEST') 0023 do_unit_test; return 0024 end 0025 0026 m2s = []; 0027 for i = 1:numel(stim) 0028 m2s = [m2s ; kron(stim(i).stim_pattern', stim(i).meas_pattern)]; 0029 end 0030 if isstruct(mat) && isfield(mat, 'meas') 0031 out = mat; 0032 out.meas = m2s * mat.meas; 0033 else 0034 out = m2s * mat; 0035 end 0036 end 0037 0038 function do_unit_test 0039 th= linspace(0,360,8+1); th(end)=[]; zz=0*th; 0040 epos = [th; zz+0.5]'; 0041 fmdl = ng_mk_cyl_models(1,epos,0.1); 0042 fmdl.stimulation = mk_stim_patterns(8,1,'{mono}','{mono}', {'meas_current'},1); 0043 Jm= calc_jacobian(mk_image(fmdl,1)); 0044 vm = fwd_solve(mk_image(fmdl,1)); 0045 for SP=1:3 0046 for MP=1:3 0047 fprintf('SP=%d MP=%d\n',SP,MP); 0048 fmdl.stimulation = mk_stim_patterns(8,1,[0,SP],[0,MP],{'no_meas_current','rotate_meas'},1); 0049 Jo= calc_jacobian(mk_image(fmdl,1)); 0050 Jx = mono2stim(Jm, fmdl.stimulation); 0051 unit_test_cmp('Equal',Jo,Jx, 10*eps); 0052 img = mk_image(fmdl,1); 0053 vo = fwd_solve(img); 0054 vx = mono2stim(vm, fmdl.stimulation); 0055 unit_test_cmp('Equal',vo.meas,vx.meas, 50*eps); 0056 end 0057 end 0058 end