Question
MATLAB HELP PLEASE art 1: Create a motion perception experiment % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %We are going to create a short experiment where participants will observe %a
MATLAB HELP PLEASE
art 1: Create a motion perception experiment %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%We are going to create a short experiment where participants will observe
%a series of ambiguous "apparent motion quartets" (or AMQs) and report if
%they see the dots moving vertically (i.e. up-down) or horizontally
%(i.e. left-right).
%
%This is the basic layout of the AMQs over time:
%
% Frame 1 --> Frame 2 --> Frame 3 ... etc.
%
% * * *
%
% * * *
%
%
%To see an AMQ in action, uncomment the code below and run it:
%
% figure(1); clf; set(gcf,'color','w'); axis off equal; axis([-3 3 -3 3]);
% dot_lu = [-.75 1.5]; %x-y coordinates of the left-up dot
% dot_rd = [.75 -1.5]; %x-y cooridnates of the right-down dot; these two make frame 1
%
% dot_ru = [.75 1.5]; %x-y coordinates of the right-up dot
% dot_ld = [-.75 -1.5]; %x-y coordinates of the left-down dot
%
% %loop through four frames. in odd frames show the lu and rd dots; in even
% %frames show the ru and ld dots. pause for 0.5 sec between frames
% for f=1:4 %loop through 4 frames, indexed by f
% if mod(f,2)==1 %odd frame
% plot([dot_lu(1) dot_rd(1)], [dot_lu(2) dot_rd(2)], '.r', 'markersize', 60);
% else %even frame
% plot([dot_ru(1) dot_ld(1)], [dot_ru(2) dot_ld(2)], '.r', 'markersize', 60);
% end
% axis off equal; axis([-3 3 -3 3]);
% pause(.5)
% end
%The goal of the study is to test how the *aspect ratio* of an AMQ affects
%whether the motion is perceived as vertical or horizontal. In the example
%above, the aspect ratio is .75:1.5, and you may perceive the dots moving
%horizontally, but at other aspect ratios, you may perceive vertical motion
%The study should present 25 randomly ordered trials, with 5 trials at
%each of the following aspect ratios for the AMQ:
% 0.5:2 .75:1.5 1:1 1.5:.75 2:0.5
%Hint: these will correspond to the coordinates when defining the 5
%different AMQs, like in the example above with dot_lu, etc.
%In each trial, the observer sees a short 4-frame AMQ movie with a particular
%aspect ratio, and they are then prompted to report whether they saw vertical or
%horizontal motion (can be via key-press or mouse-click)
%You can use the completed code examples from the Week 6 lecture and group
%exercises to structure the study, but note one important difference:
%
% The main variable manipulated in this study (aspect ratio) has 5
% values, not 2 (as in the lexical decision where strings were either
% words or nonwords, or in the face perception task where faces were either
% neutral or smiling). This means that there are 5 conditions to randomize
%Finally, we are not interested in reaction time here, so we won't be
%collecting that.
%1.1 Set up the experiment: obtain participant initials and create an
%output filename
%1.2 Randomize the order of 25 trials so the 5 different aspect ratios are
%shown randomly interspersed.
%1.3 Initialize an empty trial_matrix to be 25 rows by 4 columns:
%Note: the 3 columns are what we want to store from each trial:
%- trial number
%- aspect ratio (can be coded as 1-5, with 1=0.5:2, 2=.75:1.5, etc.
%- participant's response (vertical or horizontal, coded as 1 or 0)
%
%Also define column_names to reflect this organization
%1.4 Present instructions to participants (specifically which keys they
%should press to indicate vertical or horizontal)
%1.5 Start the experiment (main loop) going through the 25 trials
% In each trial:
%
% 1.6 - present the 4-frame movie in a for-loop with the particular
% aspect ratio corresponding to this trial.
% Hint: use if-else to determine which aspect ratio to show
%
% 1.7 - obtain a response (using ginput)
%
% 1.8 - organize the data into a row of the trial matrix
%
% 1.9 - save the trial_matrix and column_names to the output file
%
% 1.10 - pause briefly before going on to the next trial
%1.11. Finish the study and thank the participant (and check that the output
%is correct)
%1.12. Once your study works, run it on yourself, and copy & paste the
%values of your completed trial_matrix below (it should be 25 rows by 3 columns)
%% %%%%%%%%%%%%%%%%%%%%%%
% Part 2: FFT analysis %
%%%%%%%%%%%%%%%%%%%%%%%%%
% The end goal of this section is to analyze intracranial EEG data from
% visual cortex in response to a visual stimulus using an FFT. We will
% correlate gamma power on each trial with alpha power on each trial to
% see if activity in the two frquency bands are correlated.
% 2.1 load ieeg_dat.mat (tha same data use in the lecture and group coding
% excersize). As a reminder, here are some key detials about the variables
%
% srate: the sampling rate of the data in Hz (i.e., the number of samples
% per second that the ECoG data were aqcuired at)
%
% dat: samples by trial matrix of intracranially recorded voltage from
% a single electrode implanted in visual cortex of a patient
%
% times: a vector of the time values (in seconds) corresponding to each
% sample number in dat, relative to stimulus onset
%
% events: a trials by variables matrix that records the session # (1 or 2)
% on each trial and the contrast of the stimulus on each trial ([1 2 4 8 16
% 32 64 or 100]
%
% header: a cell array reminding you what both columns in events
% represents
% 2.2 Extract only post-stimulus data from 'dat'. We want all trials
% corresponding to the timewindow from 50 ms to 500 ms after stimulus
% onset. Hint: the dsearchn function can be helpful in the first step of this process
% 2.3 compute the length (in samples) of the newely extracted data from 2.2
% 2.4 loop over trials and compute the fft of each trial of post-stimulus
% data. Remember to:
% 1) divide the FFT output by the signal legnth * 2 (to recover the original data units)
% 2) take the absolute value of the FFT output to get rid of phase information from the complex numbers
% 3) square the result to get power (instead of amplitude).
%
% If done correctly, you should have a 419-by-320 matrix (or the inverse),
% corresponding to power at each of 419 frequencies and 320 trials.
% 2.5 make a vector called 'Hz' that maps indicies in FFT output onto frequencies
% in Hz. Since we have not removed the negative frequencies from the FFT
% step just yet (that will be next), Hz should be about half as long as the
% number of frequencies in the 2d matrix from step 2.4
% 2.6 using the Hz vector from 2.5, cut out the negative freqiences from
% that matrix from 2.4. Once complete, you should have a 210-by-320 matrix
% of power at 210 frequencies and 320 trials (or the inverse shape).
% 2.7 now that we have power at all frequenices and trials, we want to just
% extract alpha and gamma power for each trial. To do this, first use the dsearchn
% function to find the indicies in Hz corresponding to 8 to 13 Hz (the
% 'alpha' frequency band) and the indicies corresponding to 50 to 70 Hz
% (the 'gamma' frequency band).
% 2.8 using the indicies from 2.7 create a vector of alpha power on each
% trial by log10 transforming pow and then averaging the power at all
% frequenices between 8 and 13 hz.
% 2.9 do the same thing as 2.8 but for the gamma frequency (i.e., log10
% transform power then average over all frequencies between 50 and 70 hz).
% The results of steps 2.8 and 2.9 should give you two vectors, each of
% them 320 elements long refleecting the average alpha power on each trial
% (2.8) and the average gamma power on each trial (2.9)
% 2.10 now let's plot the power spectrum avaraged over trials in one subplot and
% a scatter plot of alpha power by gamma power on each trial.
%
% For the power spectrum plot, log10 transform power before averaging over all trials and
% plot the x-axis range between 3 and 80 Hz to highlight the range of the data we are interested in.
% Do you see peaks between 8-13 hz and between 50 and 70 hz?
%
% For the scatter plot, add a line of best fit to the data - do alpha power and gamma power seem correlated on single trials?
% 2.11 compute the actual correlation (r and p-value) between alpha power
% and gamma power on each trial. Is there a relationship and how would you
% describe it?
% Extra credit #1: let's make one more scatter plot with an additional peice of info.
% Plot alpha power by gamma power as a scatter plot with the color of each
% dot determined by the stimulus contrast on that trial (hint - remember
% the 4th input to the scatter function). Also make each dot a size of 100
% and of you type 'filled' (in single quotes) as a fifth input it will make
% the dots filled instead of just outlines (easier to see IMHO). Label your
% axes, add a best fit line
% does anything jump out at you after color-coding each point by the
% stimulus contrast?
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Part 3: simulating SDT %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%the goal of this simulation is going to be to see how varying the
%criterion in signal detection theory changes the number of hits and false
%alarms
% 3.1 first define some parameters:
% 1) the "signal absent" distribution (i'll call this s0 for simplicity) is a normal distribution with a mean of -1 and an SD of 1
% 2) the 'signal present' distribution (s1) is normal with a mean of +1 and an SD of 1
% 3) the probability of stimulus absent is 0.5 (50% of trials from s0 distribution)
% 4) we will simulate behavior under 9 levels of criterion liniarly spaced -2 and +2
% 5) let's simulate 10,000 trials at each level of criterion (90,0000 trials in total)
%
% define the above parameters
%3.2 without runnung any simulations, what should d' be given the values we
%chose for the means and sd of the two distributions
%3.3 Start a nested for loop: first loop over criterion levels, and then
%over trials. In each loop:
%
% 1) check if we present a stimulus (only ~50% of the time this should be the case)
% 2) if we do present a stimulus, draw an internal response from the s1 distribution, otherwise, from s0
% 3) check if the internal response in the current trial is above or below the current criterion. If it is above, define the subject's response as 1, otherwise define the subject's response as 0
%
% make sure to record the following values as they are generated within the
% loop: wheter the stimulus was present on each trial and criterion level,
% what the internal response was for each trial and criterion level, and
% what the simulates subject's choice was for each trial and criterion
% level. (good practice to defined these as empty variables before running
% the loop, or even better, pre-allocate than as NaN matricies)
%3.4 now compute the following values for each criterion level:
% 1) how many trials were from s0 (stim absent) hint: (should be close to 5,000 for each crit level)
% 2) of those trials from s0, how many were false alarms?
% 3) how many trials were form s1 (stim pres) hint: (should be close to 5,000 for each crit level)
% 4) of those trials, how mant were hits?
% 5) what is the hit rate and false alarm rate for each criterion level (reminder: the hit rate is the number of hit / number of stim present trials, the false alarm rate is the number of false alarms / number of stim absent trials)
%
% there are multiple ways of solving the abolve (e.g., can be in a loop, but doesn't need to be)
% 3.5 if 3.3 was done correctly, you should have a vector of 9 hit rates
% and a vector of 9 false alarm rates, with each pair of hits and false
% alarms coming from a different simulated criterion. Let's plot the vector of false
% alarm rates (x-axis) by the vector of hit rate (y-axis). PLot the data as
% dots connected by a line and label the axes. If done correctly, you have
% just plotted what is called a "receiver operating characteristic curve"
% or ROC curve. It should look like a bow shape bending up towards the top
% left corner of the plot. Each point describes the hit rate and false
% alarm rate expected at a certain criterion level. (the area under this
% curve is proportional to d', which we did not vary in this simulation)
% extra credit #2: plot histograms representing the internal response
% distributions for s0 and s1 trials with vertical lines representing the 9
% criterion levels used
% extra credit #3: compute d' for each criterion level from the vector of hit rates and false alarm
% rates. Does changing criteiron seem to impact d'? Does the d' values you
% get match what you predicted in 3.2?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started