ISP_MoBi.m 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. function ISP_MoBi(PTP_name, first_block, last_block, volume)
  2. %%
  3. % e.g. ISP_MoBi('S99_O1', 1, 14, 0)
  4. % call the function as
  5. % ISP_MoBi(PTP_name, number of the initial block, number of the last block, volume)
  6. % where...
  7. % PTP_name --> the participant code which has to be SXX_OXX i.e.
  8. % participant number followed by the block order
  9. % first_block and last_block --> first and last block you want to run
  10. % volume --> volume of the noise played in the earphones (it has been set to zero, since the volume was set manually)
  11. %%
  12. addpath('C:\Users\neuro\Desktop\script_mobi_da_commentare\arduino_for_MoBi');
  13. % initialize forces variable
  14. %forces = 0;
  15. % forces.max_force_left = 969.8065;
  16. % the original function for force estimation estiamted the maximal force for
  17. % both hands. In the present work we only needed the left one. However we
  18. % kept the original function as it was and set a mock value for the maximal right hand force.
  19. % So, within the ISP_MoBi_sequence_MEP and ISP_MoBi_sequence functions there
  20. % is still code for the right hand estimation which has not been used and does not affect the left hand maximal force estimation.
  21. % leftover from the original maximal_force script (in the present version
  22. % the maximal force has been estimated only for the left hand.
  23. % "forces.max_force_right = 900" works as a place holder).
  24. forces.max_force_right = 900;
  25. % from the first to the last block -->
  26. % set PTP data and file name to be saved after the block run
  27. % if the block is odd --> present instructions and set the force
  28. % threshold
  29. for bl = first_block:last_block
  30. [data_subject,R] = MoBi_save_settings();
  31. cd 'C:\Users\neuro\Desktop\script_mobi_da_commentare'
  32. % calculate the TMS thershold only in odd blocks
  33. if mod(bl,2) == 1
  34. % show instructions for the researcher (stimulation parameters: current orientation, pulsewave, muscular contraction)
  35. MoBi_instructions(R(bl,:), data_subject, volume, forces, bl);
  36. % TMS threshold estimation precedure
  37. TMS4Threshold_MoBi();
  38. % maximal force estimation of the left hand
  39. [forces] = ISP_MoBi_sequence_MEP(R(bl,:), data_subject, volume, forces, bl);
  40. end
  41. % actual code for experiment running
  42. [forces] = ISP_MoBi_sequence(R(bl,:), data_subject, volume, forces, bl);
  43. end
  44. %%
  45. % the function outputs the name of the next block and the structure of the
  46. % session
  47. function [data_subject,R] = MoBi_save_settings()
  48. % extract and separate both the name and the order of PTP_name
  49. order_tmp = strsplit(PTP_name, '_');
  50. % get only the order
  51. stim_order = order_tmp{2};
  52. % right hand instruction (always relaxed)
  53. istruzione_mano_dx = [{'Rilassata'};{'Rilassata'};...
  54. {'Rilassata'};{'Rilassata'};...
  55. {'Rilassata'};{'Rilassata'};...
  56. {'Rilassata'};{'Rilassata'};...
  57. {'Rilassata'};{'Rilassata'};...
  58. {'Rilassata'}; {'Rilassata'};...
  59. {'Rilassata'};{'Rilassata'}];
  60. switch stim_order
  61. % choose the paramters sequence for each order
  62. case {'O1'}
  63. stim = [{'Mono_PA'};{'Mono_PA'};...
  64. {'Mono_AP'};{'Mono_AP'};...
  65. {'Mono_LM'};{'Mono_LM'};...
  66. {'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  67. {'Bi_AP'}; {'Bi_AP'};...
  68. {'Bi_LM'};{'Bi_LM'};...
  69. {'Bi_PA'};{'Bi_PA'}];
  70. % choose the state of the left hand
  71. istruzione_mano_sx = [{'Rilassata'};{'Rilassata'};...
  72. {'Rilassata'};{'Rilassata'};...
  73. {'Rilassata'};{'Rilassata'};...
  74. {'Contratta'};{'Contratta'};...
  75. {'Rilassata'};{'Rilassata'};...
  76. {'Rilassata'}; {'Rilassata'};...
  77. {'Rilassata'};{'Rilassata'}];
  78. case {'O2'}
  79. stim = [{'Mono_AP'};{'Mono_AP'};...
  80. {'Mono_LM'};{'Mono_LM'};...
  81. {'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  82. {'Bi_AP'}; {'Bi_AP'};...
  83. {'Bi_LM'};{'Bi_LM'};...
  84. {'Bi_PA'};{'Bi_PA'};...
  85. {'Mono_PA'};{'Mono_PA'}];
  86. istruzione_mano_sx = [{'Rilassata'};{'Rilassata'};...
  87. {'Rilassata'};{'Rilassata'};...
  88. {'Contratta'};{'Contratta'};...
  89. {'Rilassata'};{'Rilassata'};...
  90. {'Rilassata'};{'Rilassata'};...
  91. {'Rilassata'}; {'Rilassata'};...
  92. {'Rilassata'};{'Rilassata'}];
  93. case {'O3'}
  94. stim = [{'Mono_LM'};{'Mono_LM'};...
  95. {'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  96. {'Bi_AP'}; {'Bi_AP'};...
  97. {'Bi_LM'};{'Bi_LM'};...
  98. {'Bi_PA'};{'Bi_PA'};...
  99. {'Mono_PA'};{'Mono_PA'};...
  100. {'Mono_AP'};{'Mono_AP'}];
  101. istruzione_mano_sx = [{'Rilassata'};{'Rilassata'};...
  102. {'Contratta'};{'Contratta'};...
  103. {'Rilassata'};{'Rilassata'};...
  104. {'Rilassata'};{'Rilassata'};...
  105. {'Rilassata'};{'Rilassata'};...
  106. {'Rilassata'}; {'Rilassata'};...
  107. {'Rilassata'};{'Rilassata'}];
  108. case {'O4'}
  109. stim = [{'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  110. {'Bi_AP'}; {'Bi_AP'};...
  111. {'Bi_LM'};{'Bi_LM'};...
  112. {'Bi_PA'};{'Bi_PA'};...
  113. {'Mono_PA'};{'Mono_PA'};...
  114. {'Mono_AP'};{'Mono_AP'};...
  115. {'Mono_LM'};{'Mono_LM'}];
  116. istruzione_mano_sx = [ {'Contratta'};{'Contratta'};...
  117. {'Rilassata'};{'Rilassata'};...
  118. {'Rilassata'};{'Rilassata'};...
  119. {'Rilassata'};{'Rilassata'};...
  120. {'Rilassata'};{'Rilassata'};...
  121. {'Rilassata'}; {'Rilassata'};...
  122. {'Rilassata'};{'Rilassata'}];
  123. case {'O5'}
  124. stim = [{'Bi_AP'}; {'Bi_AP'};...
  125. {'Bi_LM'};{'Bi_LM'};...
  126. {'Bi_PA'};{'Bi_PA'};...
  127. {'Mono_PA'};{'Mono_PA'};...
  128. {'Mono_AP'};{'Mono_AP'};...
  129. {'Mono_LM'};{'Mono_LM'};...
  130. {'Bi_PA_contracted'};{'Bi_PA_contracted'}];
  131. istruzione_mano_sx = [ {'Rilassata'};{'Rilassata'};...
  132. {'Rilassata'};{'Rilassata'};...
  133. {'Rilassata'};{'Rilassata'};...
  134. {'Rilassata'};{'Rilassata'};...
  135. {'Rilassata'}; {'Rilassata'};...
  136. {'Rilassata'};{'Rilassata'};...
  137. {'Contratta'};{'Contratta'}];
  138. case {'O6'}
  139. stim = [{'Bi_LM'};{'Bi_LM'};...
  140. {'Bi_PA'};{'Bi_PA'};...
  141. {'Mono_PA'};{'Mono_PA'};...
  142. {'Mono_AP'};{'Mono_AP'};...
  143. {'Mono_LM'};{'Mono_LM'};...
  144. {'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  145. {'Bi_AP'}; {'Bi_AP'}];
  146. istruzione_mano_sx = [ {'Rilassata'};{'Rilassata'};...
  147. {'Rilassata'};{'Rilassata'};...
  148. {'Rilassata'};{'Rilassata'};...
  149. {'Rilassata'};{'Rilassata'};...
  150. {'Rilassata'}; {'Rilassata'};...
  151. {'Contratta'};{'Contratta'};...
  152. {'Rilassata'};{'Rilassata'}];
  153. case {'O7'}
  154. stim = [{'Bi_PA'};{'Bi_PA'};...
  155. {'Mono_PA'};{'Mono_PA'};...
  156. {'Mono_AP'};{'Mono_AP'};...
  157. {'Mono_LM'};{'Mono_LM'};...
  158. {'Bi_PA_contracted'};{'Bi_PA_contracted'};...
  159. {'Bi_AP'}; {'Bi_AP'};...
  160. {'Bi_LM'};{'Bi_LM'}];
  161. istruzione_mano_sx = [ {'Rilassata'};{'Rilassata'};...
  162. {'Rilassata'};{'Rilassata'};...
  163. {'Rilassata'};{'Rilassata'};...
  164. {'Rilassata'};{'Rilassata'};...
  165. {'Contratta'};{'Contratta'};...
  166. {'Rilassata'}; {'Rilassata'};...
  167. {'Rilassata'};{'Rilassata'}];
  168. end
  169. % R is a table-like matrix containing
  170. % on the first column --> stimulation type
  171. % on the second column--> instructions for the left hand
  172. % relaxation/contraction
  173. % on the second column--> instructions for the right hand
  174. % relaxation/contraction (which is always relaxed)
  175. R = [stim istruzione_mano_sx istruzione_mano_dx];
  176. % get the date and time so that savings do not overwrite
  177. hour = clock;
  178. % put together into a string
  179. hour = strcat(num2str(hour(1)),...
  180. num2str(hour(2)),...
  181. num2str(hour(3)),'_',...
  182. num2str(hour(4)),...
  183. num2str(hour(5)),...
  184. num2str(round(hour(6))));
  185. % data_subject contains the string corresponding to the name of the block file .mat
  186. % this info will be used as input into the ISP_MoBi_sequence and MoBi_instructions
  187. % functions
  188. data_subject = strcat(PTP_name, '_', R{bl,1}, '_', R{bl,2}, '_', R{bl,3}, '_', num2str(bl), '_', hour, '.mat');
  189. end
  190. end