# Stimulus advice and some drifting grating questions

**URL:** <https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400>\
**Category:** Support\
**Created:** [June 27, 2016, 1:59pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400 "2016-06-27T13:59:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 27, 2016, 1:59pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/1 "2016-06-27T13:59:56Z")

</div>

Hi Chris,

I’m hoping you could give me some advice on the best way to generate a particular stimulus in MWorks. Basically, what I want is a stimulus with a Gaussian luminance profile whose peak luminance is modulated over time according to a sinusoid. How would you try to generate this stimulus?

The approach I’ve used thus far is to attempt to generate a “counterphase” grating (that is a grating that does not drift, but the brightness at a given point is modulated according to a given temporal frequency). This can, theoretically, be achieved by the sum of two identical gratings that drift in opposite directions. However, in practice, I’m having some difficulty achieving the desired effect. I queue two gratings that drift in opposite directions, but there seems to be a small offset between the actual start time of the drifting of each grating, with the grating that is cued first also starting first. Is there a way to start both simultaneously? I’ve tried a frame-list but that creates an undesirable flicker…

In addition, I have some basic questions about how to specify the drifting grating stimuli:  
spatial frequency - units? cyc/deg?  
speed - units? deg/s?  
Mask - I have Gaussian, but it doesn’t look like there is a Gaussian mask; instead I see a square.  
std\_dev - Based on the name, I would think it controls the size of the mask; instead it looks like it controls the contrast. Is that true?

Thanks!  
Seth

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2016, 2:25pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/2 "2016-06-29T14:25:51Z")

</div>

Hi Seth,

Sorry for the delay in replying.

> This can, theoretically, be achieved by the sum of two identical gratings that drift in opposite directions. However, in practice, I’m having some difficulty achieving the desired effect.

I’m having trouble getting this to work, too, but I’m not sure we’re seeing the same issue. Can you send me an example experiment that demonstrates your problem?

> I have some basic questions about how to specify the drifting grating stimuli

You’re correct on the units: `spatial_frequency` is cycles/degree, and `speed` is degrees/second.

> Mask - I have Gaussian, but it doesn’t look like there is a Gaussian mask; instead I see a square.
> 
> std\_dev - Based on the name, I would think it controls the size of the mask; instead it looks like it controls the contrast. Is that true?

The Gaussian mask is computed using the [Gaussian function](http://mathworld.wolfram.com/GaussianFunction.html) (eq. 1), where `mean` is 휇, `std_dev` is 휎, and the distance from the center of the grating is 푥. As `std_dev` gets larger, the maximum amplitude decreases, and the decay becomes less steep.

Irrespective of the mask, the extent of the grating is limited to the rectangle defined by `x_size` and `y_size`. So, if `std_dev` is large, then the grating will look like a low-contrast rectangle, as the edges of the Gaussian are cut off. If you use a smaller value (say, 0.3), then you should get something that actually looks Gaussian.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2016, 3:41pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/3 "2016-06-29T15:41:17Z")

</div>

Hi Chris,

No worries! Attached is a simple experiment that will produce the _near_  
counter-phase grating. If you want to confirm it is the timing of the start  
of each stimulus, just switch which grating is cued first and you should  
see stuff move in the opposite direction. Let me know if it doesn’t work  
for you.

Thanks for clarifying some of the options on the Gabor stimuli. I’m  
surprised the amplitude of the Gaussian is specified as part of the spatial  
mask; imagine you’d like to create two Gabors with identical contrast,  
spatial and temporal frequencies but with differing visual extents. Its  
unclear how one could accomplish this with the current version of the  
stimuli. If, instead, the amplitude and width of the Gaussian were  
independently controlled, this type of stimulus would be easy to implement.

Cheers,  
Seth

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [June 29, 2016, 3:41pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/4 "2016-06-29T15:41:17Z")

</div>

Attachment: [MWGratingTest.xml](https://mworks.discourse.group/uploads/short-url/olOB0ipOjVNtTRAWxW0NcgVq2ES.xml) (2.87 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 5, 2016, 1:48pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/5 "2016-07-05T13:48:21Z")

</div>

Hi Seth,

Thanks for the example. I think we are seeing the same issue, although I don’t yet know what the cause is. I’ll continue to investigate.

> I’m surprised the amplitude of the Gaussian is specified as part of the spatial mask

Yeah, there are many aspects of MWorks’ drifting grating stimulus that are surprising and/or just plain dumb. I’ve wanted to replace it for a while now, but it hasn’t been a high-priority item.

Returning to your original question:

> Basically, what I want is a stimulus with a Gaussian luminance profile whose peak luminance is modulated over time according to a sinusoid. How would you try to generate this stimulus?

At the moment, finagling the grating is probably the only way to do this. In the future, I could see adding general support for stimulus masks, so that you could take a simple circle stimulus and apply a generic Gaussian mask (with the amplitude specified as a time-varying expression) to get your desired stimulus. It seems like that could be a useful feature.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 7, 2017, 3:07pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/6 "2017-08-07T15:07:19Z")

</div>

Hi Seth,

> Basically, what I want is a stimulus with a Gaussian luminance profile whose peak luminance is modulated over time according to a sinusoid.

In case it’s still relevant, the current MWorks [nightly build](https://mworks.github.io/downloads/) has some new features that let you create this type of stimulus.

First, the drifting grating stimulus has a new parameter: [normalized](https://mworks.github.io/documentation/0.8/components/drifting_grating_stimulus.html#normalized). If set to `NO`, the normalization term (`1/(std_dev*sqrt(2*pi))`) is omitted from the Gaussian mask, thereby decoupling the spatial extent of the mask from its peak luminance.

Second, the grating now has a [color](https://mworks.github.io/documentation/0.8/components/drifting_grating_stimulus.html#color) parameter, each component of which can be an arbitrary expression. If you make those expressions time dependent and live queue the stimulus, then the luminance (and also the hue, if you want) will vary in time.

I’ve attached an example experiment, which I believe demonstrates the type of stimulus you wanted. You’ll need the current nightly build to run it. (Also, the experiment is written in [MWEL](https://mworks.github.io/documentation/0.8/mwel/index.html), which is a new, non-XML format for writing MWorks experiments. To view/modify it, open it in any text editor.)

If you have any questions, please let me know.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [August 7, 2017, 3:07pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/7 "2017-08-07T15:07:19Z")

</div>

Attachment: [time\_varying\_gaussian.mwel.txt](https://mworks.discourse.group/uploads/short-url/cIqkvwj22N6O8OTJPKH4fVAnYzd.txt) (773 Bytes)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 9:55pm UTC](https://mworks.discourse.group/t/stimulus-advice-and-some-drifting-grating-questions/400/8 "2022-07-19T21:55:32Z")

</div>


