%Purpose:Reconstruct the object wave from the phase-shifting interferograms;
%Input parameters:'I1','I2','I3','I4'Phase-shifting interferograms;
                  %'ph1','ph2','ph3', phase shifts in 'I2','I3' and 'I4' with respect to'I1';
%Output parameters;Complex_Amp, complex amplitude of the reconstructed object wave; 
                   %'Amp_R','Amp_O', The amplitude of the%object and reference wave;
function [Complex_Amp,Amp_R,Amp_O]=Four_Step_PSI_Reconstruction(I1,I2,I3,I4,ph1,ph2,ph3),
  Q1=I3-I1; 
  Q2=I4-I2; 
  Numerator=Q1.*(exp(j*ph3)-exp(j*ph1))-Q2.*(exp(j*ph2)-1);                                     %Numerator of 'OR*';
  Denominator=(exp(-j*ph2)-1)*(exp(j*ph3)-exp(j*ph1))-(exp(-j*ph3)-exp(-j*ph1))*(exp(j*ph2)-1); %Denominator of 'OR*';
  Complex_Amp=Numerator./Denominator;                                                           %Reconstructed 'OR*';

  a=I1-2*real(Complex_Amp)+2*abs(Complex_Amp); %(|O|+|R|)^2; 
  b=I1-2*real(Complex_Amp)-2*abs(Complex_Amp); %(|O|-|R|)^2; 
  Amp_R=( sqrt(abs(a))-sqrt(abs(b)) )/2;       %Reconstructed Amplitude of Reference wave; 
  Amp_O=( sqrt(abs(a))+sqrt(abs(b)) )/2;       %Reconstructed Amplitude of Object wave; 
 
end
%Reference: OPTICS LETTERS,34(22),3553-3555; 