# Sf, tf, and speed of grating stim

**URL:** https://discourse.psychopy.org/t/sf-tf-and-speed-of-grating-stim/2095
**Category:** Coding
**Created:** [March 9, 2017, 6:24pm UTC](https://discourse.psychopy.org/t/sf-tf-and-speed-of-grating-stim/2095 "2017-03-09T18:24:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alex\_p](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@alex\_p](https://discourse.psychopy.org/u/alex_p)
#### Post date: [March 9, 2017, 6:24pm UTC](https://discourse.psychopy.org/t/sf-tf-and-speed-of-grating-stim/2095/1 "2017-03-09T18:24:23Z")

</div>

Hello,

I wanted to verify that I understood the parameters of drifting grating stim correctly.  
If I have monitor refresh rate 60 Hz, then:  
**temporal\_frequency (Hz) = phase\_advance \* 30, because 0.5 phase corresponds to 1 cycle (psychopy docs)**  
\*_speed = temporal\_frequency / spatial\_frequency (degrees/sec) or linear\_speed = tf\*d(monitor distance)cot(sf) (cm/s)_

**Is that correct or I am missing smth?**

Thanks,

Code to present 0.2s drifting:  
tf = 2 # Hz  
spatial\_freq=0.05 # cyc/deg  
phase\_advance= tf/30.0 # monitor refresh rate 60 Hz, 0.5 phase = 1 cycle  
angle\_iteration=30  
orientation\_latency=12 # units are in frames? 1/60 = duration of 1 frame. (1/60)12 = 0.2s = 200ms.  
speed = tf/sf # degrees/s, cycle - constant; linear\_speed = tf\*d(monitor distance)\*cot(sf) = cm/s

```
    for frameN in range(orientation_latency):
        grating2.setPhase(phase_advance, '+')#advance phase by 0.05 of a cycle
        grating2.draw()
        mywin.flip()
```

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [March 15, 2017, 10:14am UTC](https://discourse.psychopy.org/t/sf-tf-and-speed-of-grating-stim/2095/2 "2017-03-15T10:14:10Z")

</div>

No phase of 0.5 is not 1 cycle. PsychoPy’s phase setting has units of cycles 1=1. The beauty is that you can set  
`phase = t*tf`  
or  
`phase_advance = tf/frame_rate`  
(but make sure that you do the `from __future__ import division` line and/or make sure that your `tf` of `frame_rate` is a float.

(You might benefit from one of our programming workshops - check them out)

I don’t know what your orientation latnecy thing is about so can’t comment on that

---

<div class="post-metadata">

### Author: ![alex\_p](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@alex\_p](https://discourse.psychopy.org/u/alex_p)
#### Post date: [March 17, 2017, 2:15am UTC](https://discourse.psychopy.org/t/sf-tf-and-speed-of-grating-stim/2095/3 "2017-03-17T02:15:15Z")

</div>

Thanks for your reply. Now it makes sense.
