├── About.pdf ├── MatlabGS_BinarySLM.m ├── PythonCodes ├── Readme.md └── axicon.py └── README.md /About.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harshjn/SpatialLightModulators/4d435458c729a8821f4f1275bde8fa486a8d26c1/About.pdf -------------------------------------------------------------------------------- /MatlabGS_BinarySLM.m: -------------------------------------------------------------------------------- 1 | %% Algorithm to generate Pattern for projection onto Spatial Light Modulators 2 | 3 | % Resolution of the SLM 4 | ResX=1380 5 | ResY=2048 6 | 7 | %------------- We start with all black image and generate a target field intensity 8 | 9 | % Generating all black image 10 | E_target=zeros(ResX,ResY); 11 | 12 | % E_target(300-100,396+60)=255; 13 | % E_target(300-100,396+40)=255; 14 | 15 | 16 | %% Generate the image of the required pattern 17 | % We wish to generate a circle, with center (a,b) and radius r 18 | 19 | a=ResX/2; 20 | b=ResY/2; 21 | 22 | r=1000.0; 23 | delta=500; 24 | 25 | % to generate a circle: 26 | % for i=1:1:4*a 27 | % for j=1:1:4*b 28 | % if( ((a-i)^2 +(b-j)^2>r) && ( (a-i)^2 +(b-j)^2<(r+delta) ) ) 29 | % E_target(uint16(i),uint16(j))=255; 30 | % sprintf('%d %d',i,j) 31 | % 32 | % end 33 | % end 34 | % end 35 | 36 | % To generate a single spot 37 | E_target(a+100,b)=255; 38 | 39 | imshow(E_target) 40 | title('target Pattern') 41 | % target pattern 42 | 43 | 44 | %% 45 | %--------------- We generate a 256 bit phase distribution 46 | E_target=fftshift(E_target); 47 | 48 | Phase=rand(ResX,ResY)*(2*pi); 49 | Phase_image=exp(-1i*Phase); 50 | for j=1:1:10 51 | 52 | holo=ifftshift(ifft2(E_target.*Phase_image)); 53 | 54 | Phase_holo=exp(-1i*angle(holo)); 55 | 56 | E_focus=fft2(Phase_holo); 57 | Phase_image=exp(-1i*angle(E_focus)); 58 | end 59 | 60 | Phase=angle(holo); 61 | 62 | % For a general 256 bit SLM 63 | Phase=uint8(mod(Phase+2*pi,2*pi)/(2*pi)*255); 64 | imshow(Phase) 65 | title('256 bit phase distribution pattern') 66 | 67 | %% 68 | % ----------- We convert the generated phase distribution to binary 69 | %for the forthdd SLM which is binary 70 | PhaseMat= angle(holo)>0; 71 | Phase= uint8(PhaseMat*255); 72 | 73 | % addSave='' 74 | imshow(ifftshift(Phase)) 75 | title('Generated 2 bit pattern') 76 | imwrite(ifftshift(Phase),'GS_generated.bmp') 77 | %This is the final generated image 78 | -------------------------------------------------------------------------------- /PythonCodes/Readme.md: -------------------------------------------------------------------------------- 1 | Introduction: 2 | In this experiment, we are trying to align incoming beam with the axicon pattern of our SLM. 3 | We are setting up a n=10 circular trap using the code axicon.py 4 | We have to experiment and try to make the trap perfect circular Laguerre Gaussian beam. 5 | 6 | 7 | ![image](https://github.com/harshjn/SpatialLightModulators/assets/6217880/dbf19bb4-6330-4e62-9e7d-06c4fa65fddd) 8 | 9 | 10 | ![image](https://github.com/harshjn/SpatialLightModulators/assets/6217880/9c77eee0-37a8-4595-a966-f60b08fff08c) 11 | 12 | ![image](https://github.com/harshjn/SpatialLightModulators/assets/6217880/82ae3704-f015-4bb2-bf55-cad6f19021a4) 13 | 14 | ![image](https://github.com/harshjn/SpatialLightModulators/assets/6217880/df26e4da-e7d4-48d1-a05e-913082006e38) 15 | 16 | Finally, I did achieve a quite good circle with the values in axicon.py, although it still can be optimized, is a 2d search problem. Must be noted, what I’m trying to do here is orient the center of the spiral with the incoming beam. This will give a good cylindrical beam. 17 | ![image](https://github.com/harshjn/SpatialLightModulators/assets/6217880/2f853ce4-91a3-448e-81c9-e81834bda7b1) 18 | -------------------------------------------------------------------------------- /PythonCodes/axicon.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Aug 18 22:16:52 2017 4 | 5 | @author: Admin 6 | """ 7 | #import slmpy 8 | import time 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | from PIL import Image 12 | 13 | M_x=792; # x-resolution of SLM 14 | M_y=600; # y-resolution of SLM 15 | A=np.zeros([M_x,M_y]) 16 | pi=np.pi; 17 | 18 | Cx=400; # x-Center of axicon pattern 19 | Cy=210; 20 | 21 | def phase2hamamatsu(Phase_xy): # Hamamatsu SLM phase bit varies from 0 to 224 22 | for p in range(M_x): 23 | for q in range(M_y): 24 | Phase_xy[p][q]=np.mod(Phase_xy[p][q],2*pi)*224/(2*pi) 25 | return Phase_xy 26 | 27 | 28 | # Generating image for the pattern around center (Cx,Cy) 29 | for i in range(792): 30 | for j in range(600): 31 | n=20 32 | r_o=1e4; 33 | r=(i-Cx)**2+(j-Cy)**2 34 | theta=np.arctan((j-Cy)/(i-Cx+1e-6)) 35 | A[i,j]=np.mod(n*theta-2*pi*r/r_o,2*pi) 36 | 37 | im=A; # 8-bit Image from 0 to 255 (uint8) 38 | im=phase2hamamatsu(im) 39 | im=np.transpose(im) 40 | im=im.astype(np.uint8) 41 | image=Image.fromarray(im) 42 | image.save('Axicon.bmp') 43 | 44 | 45 | 46 | #%% 47 | import slmpy 48 | import time 49 | import numpy as np 50 | from PIL import Image 51 | slm = slmpy.SLMdisplay(isImageLock = True) 52 | resX, resY = slm.getSize() 53 | # We use images twice smaller than the resolution of the slm 54 | i=0 55 | 56 | testIMG = np.asarray(Image.open('Axicon.bmp')) 57 | slm.updateArray(testIMG) 58 | time.sleep(500) 59 | slm.close() 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Optical patterns calculated for SpatialLightModulators 2 | Various codes for projecting phase distributions on to a phase-controlling spatial light modulator such as the Hamamatsu LCOS - SLM. (https://www.hamamatsu.com/us/en/product/optical-components/lcos-slm.html) 3 | To get a target pattern such as an optical tweezers trap, the projection pattern for the SLM needs to be back calculated using algorithms such as GS Algorithm. 4 | Here, we present MATLAB and PYTHON codes for calculating and projecting such patterns for an SLM recognized as an extended display. 5 | --------------------------------------------------------------------------------