Hi,
As I no longer use Matlab, I cannot help you with this software.
As for Python code, you need to understand that there is no code that you can simply copy and paste and would work out of the box, as part of the code depends on your hardware, in this case, mostly the camera.
However, I wrote some modules that can be useful for part of the code,
- If you use a phase-only SLM controlled as a secondary display, you can use SLMpy, see my tutorial and Github page
- To use macro-pixels (as used in the paper you referred to), you can use Layout (Github page)
- For the sequential algorithm, the best is to write it yourself as it is very simple, in pseudo-code it would look like:
import numpy as np
N_macropixels = ... # number of macro-pixels on your SLM
N_phases_to_test = ... # number of phases you want to test on each macropixel
phases_to_test = np.arange(0,2*mp.pi,N_phases_to_test)
phase_vector = [0]*N_macropixels #initial guess, phase = 0 on each macropixel
for i_pixel in range(N_macropixels):
best_value = None
for phase in phases_to_test:
# try a new phase value for the i_pixel-th pixel
phase_vector[i_pixel] = phase
# display the new SLM mask
display_phase_vector(phase_vector)
# get the value of the target intensity
value = get_target_intensity()
# if the value we get is the best so far, we store the value and the corresponding phase
if best_value is None or best_value < value:
best_value = value
best_phase = phase
# after trying all the phases for one macro-pixel, we keep the one corresponding to the best value
phase_vector[i_pixel] = best_phase
display_phase_vector()
is a function you have to write to display the image on the SLM you can use SLMpy and Layout for that, the idea is that you divide your SLM in macro-pixels and assign to each macro-pixel the phase corresponding to each value of phase_vector.
get_target_intensity()
is a function you have to write to get the intensity at the target location. The actual code depends on your camera but basically, you want to get an image, and sum the values of the intensity around a given target location and return this value.