Member
Joined:
Posts: 2

I want to reproduce the results of "focusing light in scattering media by using iterative algorithms, Ivo M. Vellekoop."
Another paper for reference " feedback-based wavefront shaping, Ivo M. Vellekoop."

Please help me to find a Matlab code for this, whether someone put it on GitHub?
Or does anyone know where else I can find Matlab or Python code for this?
Or please share the Matlab code if anyone here tried to reproduce this using any kind of iterative algorithm.

Administrator
Joined:
Posts: 73

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.

Member
Joined:
Posts: 2

Hi Sebastian,

Thank you for your kind reply. I have written code from your provided pseudo-code. It was very much helpful. I will modify this code for my binary FLCSLM.
I need one more help, I want to simulate and test this code on my computer before applying it to the experiment. For that, I need to simulate a light source matrix and medium matrix, which finally gives me a transmission matrix. Can you please suggest to me a method for getting a simulated transmission matrix? It will be very much helpful if you provide a pseudo-code for the same.

Administrator
Joined:
Posts: 73

Just use a random complex Gaussian matrix

TM = np.random.randn(N_out,N_in)+1j*np.random.randn(N_out,N_in)
Administrator
Joined:
Posts: 73

By the way, here a simple toolbox for iteration/partition algorithm: github.com/wavefrontshaping/EasyOptimization/