Spatial_Contrast_Adaptation_Stimulus.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function stimulus = Spatial_Contrast_Adaptation_Stimulus(seed, numframes,switchframe, Nrepeats, meanIntensity)
  2. %
  3. %
  4. %%% Spatial_Contrast_Adaptation_Stimulus %%%
  5. %
  6. %
  7. % This function generate the stimulus that was used to study spatial contrast
  8. % adaptation accompanying dataset of Khani and Gollisch (2017). The dataset is available at:
  9. % https://gin.g-node.org/gollischlab/Khani_and_Gollisch_2017_RGC_spiketrains_for_spatial_contrast_adaptation
  10. %
  11. %
  12. % ===============================Inputs====================================
  13. %
  14. % seed : starting seed for generating random number sequences.
  15. % numframes : number of displayed stimulus frames.
  16. % switchframe : time point of contrast change from high to low and vice versa.
  17. % Nrepeats : number of stimulus trials.
  18. % meanIntensity : mean intensity during the experiment (between 0-1, usually 0.5).
  19. %
  20. %================================Output====================================
  21. %
  22. % stimulus : high and low contrast stimulus sequences for locations X and Y.
  23. % first get the sequence of random numbers
  24. screenstimulus = ran1(seed,2*numframes); % 2 times number of frame for locations X and Y
  25. % convert the values to binary.
  26. % values > meanintensity are set to 1 (100% contrast).
  27. % values < meanintensity are set to -1 (-100% contrast).
  28. screenstimulus = 2*single(screenstimulus>meanIntensity)-1;
  29. % reshape to separate the values for locations X and Y.
  30. screenstimulus = reshape(screenstimulus,2,[]);
  31. % get screen stimulus per trial
  32. stim_locX = reshape(screenstimulus(1,:),switchframe,Nrepeats)';
  33. stim_locY = reshape(screenstimulus(2,:),switchframe,Nrepeats)'; % location Y is the second seed series
  34. % separate high and low contrast for locations X and Y
  35. stimulus.locX_high = stim_locX(2:2:end,:); % location X, high contrast
  36. stimulus.locX_low = stim_locX(1:2:end,:); % location X, low contrast
  37. stimulus.locY_high = stim_locY(2:2:end,:); % location Y, high contrast
  38. stimulus.locY_low = stim_locY(1:2:end,:); % location Y, low contrast
  39. % match the stimuli sizes
  40. s = min([size(stimulus.locX_high,1),size(stimulus.locX_low,1),size(stimulus.locY_high,1),size(stimulus.locY_low,1)]);
  41. stimulus.locX_high = stimulus.locX_high(1:s,:);
  42. stimulus.locX_low = stimulus.locX_low(1:s,:);
  43. stimulus.locY_high = stimulus.locY_high(1:s,:);
  44. stimulus.locY_low = stimulus.locY_low(1:s,:);
  45. end