# Present two distinct stimuli at different frquencies using flip?

**URL:** <https://psychtoolbox.discourse.group/t/present-two-distinct-stimuli-at-different-frquencies-using-flip/1651>\
**Category:** Uncategorized\
**Created:** [October 31, 2007, 6:49pm UTC](https://psychtoolbox.discourse.group/t/present-two-distinct-stimuli-at-different-frquencies-using-flip/1651 "2007-10-31T18:49:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [October 31, 2007, 6:49pm UTC](https://psychtoolbox.discourse.group/t/present-two-distinct-stimuli-at-different-frquencies-using-flip/1651/1 "2007-10-31T18:49:37Z")

</div>

Hi there, the problem i have is that i need to present two (or more  
boxes) flickering at distinct frequencies, say 10hz and 25hz. on  
screen at the same time.  
  
However as a call to flip sleeps matlab how is this possible?  
  
eg psuedo code below  
  
openwindow1  
openwindow2  
  
%get timestamps  
vblwin1 = screen(flip, window1);  
vblwin2 = screen(flip, window2);  
  
  
%animation loop  
  
for i=1:100  
  
%draw boxes to buffer here  
  
flip every 0.04 secs / 25hz  
vblwin1 = screen(flip, window1, vblwin1 + 0.04 )  
  
flip every 0.1 secs / 10hz  
vblwin2 = screen(flip, window2, vblwin2 + 0.1 )  
  
end  
  
  
  
obviously the code sleeps at the call to flip window 2 for 1 second  
thus missing the second call to window 1 resulting in both windows  
flipping at 10hz.  
  
  
i have written if else code to make it work using getsecs() but the  
time stamps report that it is not very accurate   
  
  
ie if getsecs \>= vblwin1 + 0.04  
 flip  
else  
 do nothing  
end  
  
  
ie if getsecs \>= vblwin2 + 0.1  
 flip  
else  
 do nothing  
end  
  
  
but the timestamps report that the time between flips is not accurate  
  
eg 0.133 for 10hz  
  
and 0.066 for 25hz which is not accurate enough  
  
in the full code i am using priority(2) and drawing finished calls?  
  
to my mind it is a classic case for threads but matlab doesn't seem to  
support threads?  
  
any ideas?

---

<div class="post-metadata">

**Author:** ![xuu](https://avatars.discourse-cdn.com/v4/letter/x/8e7dd6/32.png) [@xuu](https://psychtoolbox.discourse.group/u/xuu)\
**Post date:** [April 25, 2023, 2:31pm UTC](https://psychtoolbox.discourse.group/t/present-two-distinct-stimuli-at-different-frquencies-using-flip/1651/2 "2023-04-25T14:31:24Z")

</div>

Hello, has the problem been solved? Can you share the complete code?

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [April 25, 2023, 4:36pm UTC](https://psychtoolbox.discourse.group/t/present-two-distinct-stimuli-at-different-frquencies-using-flip/1651/3 "2023-04-25T16:36:13Z")

</div>

`help MultiWindowLockStepTest`, in this case with two windows on two separate displays:  
`MultiWindowLockStepTest(2,1);` for a demo. Shows how to use asyncflips to do this stuff.
