4

I am trying to make a visual stimulus for an EEG study. The video is simply a flicker between a black frame and a white frame, and the alternation should occur at a range of rates: 12Hz, 24Hz, 48Hz, 72Hz.

Our monitors have a refresh rate of 144Hz and the computers are also fancy, and I am measuring the success of the videos with an oscilloscope to ensure accuracy. So, the hardware should not be an issue; theoretically, up to half the monitor's refresh rate should be possible. However, I have failed in both Java and MatLab.

I have tried using MatLab:

1) using imwrite() to make a gif

2) using the VideoWriter

3) using getframe() and movie2avi().

In all of these methods, the extra-high framerate is declared, and I can see in my command window that all the frames were inserted during the run. However, the final output file never exceeds 48Hz.

On top of that, the 48Hz as well as 24Hz and even 12Hz files also have serious timing issues with the frames.

I have also tried to make the files using Processing's MovieMaker: I set the framerate to 72Hz -- input a list of 72 .png files as frames -- and it should output a 1-second file that flickers at 72Hz.

However, the result only goes at 48Hz, and again the timing of the frames is not reliable.

I wouldn't be posting here if I hadn't exhausted my search; I'm really out of ideas. MatLab and Processing were both recommended ways of achieving this kind of high fps file, and both have big timing issues even with lower flicker frequencies. If anyone has any tips on increasing the temporal fidelity of the high-Hz flicker (graphics settings? codecs?), or of how to make it all the way to 72Hz, we'd greatly appreciate it!

As I said, I have only used Processing/Java and MatLab, so please feel free to recommend another platform.

stan
  • 41
  • 1
  • 1
    For fine control over video I think you're using the wrong language. You're looking for realtime control over a hardware resource. You should consider doing this in C. You should also mention what OS you're using on your fancy computers. – pburka Oct 23 '13 at 23:30
  • To display things in sync with the hardware you have to time your writes to very strict tolerances... You must have direct control of the hardware without a driver in the way (i.e. you must write your own driver or use a driver that allows you to time things correctly). This certainly won't happen from Java, and may or may not be possible depending on the OS, the display hardware and the driver. – Jim Garrison Oct 23 '13 at 23:33

2 Answers2

2

THis is not an answer. It needs more than the comment-box, though, so please bear with me.

There are fundamental issues involved:

  • Simply drawing to whatever facility your OS/Graphics combo exposes, does not at all guarantee the drawed element to be present starting from the next frame (in all systems I know of).
  • This simply stems from the fact, that all these combos were explicitly NOT ment for an EEG Stimulus, but for consumption by visual understanding
  • Many combos offer lower-level facilities (e.g. OpenGL), that do carry such a promise, but come with other sets of problems, one of which is the less comfortable programming environment
  • With most OS/Harware combos, it might be less than trivial to sustain this stimulus - 144 Hz translates to less than 7ms - a time slot, that might be missed by a single bad scheduling decision of the OS or a need for a double-read even on a fast spinning disk. You would need to aim for some realtime-oriented OS dialect.

EDIT

After re-reading your question, I see you use Java. Forget it. a single GC break can easily be more than 7 ms.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
2

There are a couple of free (as in beer and freedom) toolboxes for Matlab that wrap the low level openGL commands that you need in order to gain the type of control you want

MGL only runs on Mac but:

mgl is a set of matlab functions for displaying full screen visual stimuli from matlab. It is based on OpenGL functions, but abstracts these into more simple functions that can be used to code various kinds of visual stimuli.

Psychtoolbox runs on Mac, Windows, and Linux

The attraction of using computer displays for visual psychophysics is that they allow software specification of the stimulus. Programs to run experiments are often written in a low-level language (e.g. C or Pascal) to achieve full control of the hardware for precise stimulus display... The Psychophysics Toolbox is a software package that adds this capability to the Matlab and Octave application on Macintosh, Linux and Windows computers

It sounds like you are just starting out, in which case I would also suggest looking at the Python based PsychoPy

PsychoPy is an open-source package for running experiments in Python (a real and free alternative to Matlab). PsychoPy combines the graphical strengths of OpenGL with the easy Python syntax to give scientists a free and simple stimulus presentation and control package.

StrongBad
  • 869
  • 6
  • 16