clear all;

%Test design
lambda_min=1.8e-6;    
lambda_max=2.3e-6;   
period=0.9e-6;      
R=38.7e-6;   
np = round(R/period);  
   
x_mask = period*(-np:1:np);    
y_mask = period*(-np:1:np);   
[X_mask,Y_mask] = meshgrid(x_mask,y_mask);

F=100e-6;              
phi_min=-(2*pi/lambda_min)*(sqrt(X_mask.^2+Y_mask.^2+F^2)-F);
phi_max=-(2*pi/lambda_max)*(sqrt(X_mask.^2+Y_mask.^2+F^2)-F);

kappa=min(min(phi_max))-min(min(phi_min));          
alpha=kappa*(lambda_max*lambda_min)/(lambda_max-lambda_min); 
beta=-kappa*lambda_min/(lambda_max-lambda_min);             

phi_min=phi_min+kappa; 
                      
phi_min=phi_min*180/pi;  
phi_max=phi_max*180/pi;  


phi_compensation=zeros(2*np+1,2*np+1);  
k=1/lambda_min;  
phi_shift = alpha*k+beta; 

gamma = 0.2; %0~1
for i=1:2*np+1     
    for j = 1:2*np+1
    x=x_mask(i);y=y_mask(j);
    phi_x=-(2*pi)*(sqrt(x^2+y^2+F^2)-F)*(k-1/lambda_max)+gamma*phi_shift;   
    phi_compensation(i,j)=phi_x;
    end
end

phi_compensation=phi_compensation*180/pi;  

%save('phi_phase_compensation','phi_compensation');
