Dot motion energy

If this template helps then use it. If not then just delete and start from scratch.

OS: MacOS 12.6
PsychoPy version: 2022.2.3
Standard Standalone? (y/n) : y
What are you trying to achieve?:

I am trying to compute dot motion energy ([PDF] Spatiotemporal energy models for the perception of motion. | Semantic Scholar)

I found a bunch of matlab code (like: Matlab implementation of Energy Model)

I am unable to figure out how to compute this for each trial of the Dot Stimulus I use in psychopy builder.

Any help would be very useful!