Generating a drifting sinusoidal grating or drifting bar stimulus

This example shows how to use drifting psychophysics-based stimuli for a retinal implant.

Along with images, videos, and oter built-in stimuli, pulse2percept supports generating GratingStimulus and BarStimulus as stimuli that can be passed as percepts to implants.

Creating a Stimulus

First, create the stimuli:

Shape ((height, width) in pixels) is the only required parameter for creating these stimuli.

A drifting sinusoidal grating is represented by GratingStimulus. The following illustrates one frame of a grating stimulus.

import matplotlib.pyplot as plt
from pulse2percept.stimuli import GratingStimulus
stim = GratingStimulus((50, 50), spatial_freq=0.1, temporal_freq=0.1)
plt.imshow([:, 0].reshape(50, 50), cmap='gray')
plt.title("Grating Stimulus")
Grating Stimulus

You can view the entire stimulus over time using