Monday, November 14, 2011

Zemax POP macro: normalized plot and calculation of beam size

Zemax Physical Optics Propagation (POP) generates cross-sectional beam profile.  Two functions are lacking that are useful to me:
1. An irradiance-normalized plot. (The absolute "watts-per-sq-millimeter" value does not matter to me almost all the time).
2. Zemax gives "second-moment" beam diameter but again, almost all the time I just need a simple 1/e^2 diameter regardless of perfect Gaussian beam or not. (The second-moment beam diameter definition heavily weighs the tails or outer wings of the intensity profile. Therefore beams with side-lobes will have second-moment width substantially larger than their central lobe widths. [1])

So I wrote a macro file to do these two tasks:

!-----------------------------------------------------------
!FIRST, SAVE SETTINGS IN POP WINDOW. 
!The "Show As" in "Display" tab must be set as "Cross X (or Y)".
!----------------------------------------------------------- 
!Input POP parameters saved in POP window:
!-----------------------------------------------------------
sampling = 512
zoom = 8

AA$ = $TEMPFILENAME()
GETTEXTFILE AA$, POP    # Import POP text data file
OPEN AA$

!-----------------------------------------------------------
! Create a loop to read POP data
!-----------------------------------------------------------
invalid_row = 13        # The first 13 rows are text, not data
For i,1,invalid_row,1
    READ a,b
Next i

Grid_size = sampling/zoom        # POP grid size (=Sampling/zoom)
DECLARE xx, DOUBLE, 1, Grid_size+1                   
DECLARE Irrad, DOUBLE, 1, Grid_size+1
For i,1,Grid_size+1,1
    READ a,b
    xx(i) = a
    Irrad(i) = b
    print xx(i), ", ", Irrad(i)
Next i
CLOSE

!-----------------------------------------------------------
! Find peak
!-----------------------------------------------------------
Max_i = 1
For j,2,Grid_size+1,1
!    PRINT "j=",j,"xx=",xx(j),"Irrad=",Irrad(j)
    IF ( Irrad(j)>Irrad(j-1) ) & ( Irrad(j)>Irrad(Max_i) ) THEN Max_i = j
Next j

!-----------------------------------------------------------
! Normalize lineshape
!-----------------------------------------------------------
DECLARE Irrad_norm, DOUBLE, 1, Grid_size+1
For j,1,Grid_size+1,1
    Irrad_norm(j) = Irrad(j)/Irrad(Max_i)
    PRINT "j=",j," xx=",xx(j)," Irrad_norm=",Irrad_norm(j)
Next j
!-----------------------------------------------------------
! Find 1/e^2 radius at extreme left (linear interpolation)
!-----------------------------------------------------------
Radius_Li = 1
For j,1,Max_i,1
    IF ( Irrad_norm(j)<=0.135 ) & ( Irrad_norm(j+1)>=0.135 ) THEN GOTO 1    #once the condition is met, jump out loop.
Next j
LABEL 1
Radius_Li = j
R_L1 = xx(Radius_Li)
R_L2 = xx(Radius_Li+1)
Irrad_L1 = Irrad_norm(Radius_Li)
Irrad_L2 = Irrad_norm(Radius_Li+1)
R_L = (0.135-Irrad_L1)*(R_L1-R_L2)/(Irrad_L1-Irrad_L2) + R_L1
PRINT "At ", R_L, " Irradiance = 0.135"
!-----------------------------------------------------------
! Find 1/e^2 radius at extreme right (linear interpolation)
!-----------------------------------------------------------
Radius_Ri = 1
For j,Max_i,Grid_size,1
    IF ( Irrad_norm(j)>=0.135 ) & ( Irrad_norm(j+1)<=0.135 ) THEN Radius_Ri = j+1
Next j
R_R1 = xx(Radius_Ri)
R_R2 = xx(Radius_Ri-1)
Irrad_R1 = Irrad_norm(Radius_Ri)
Irrad_R2 = Irrad_norm(Radius_Ri-1)
R_R = (0.135-Irrad_R1)*(R_R1-R_R2)/(Irrad_R1-Irrad_R2) + R_R1
PRINT "At ", R_R, " Irradiance = 0.135"
!-----------------------------------------------------------
! Calculate 1/e^2 beam diameter
!-----------------------------------------------------------
dia = R_R - R_L
PRINT "Beam Diameter = ", dia
!-----------------------------------------------------------
! Plot normalized lineshape
!-----------------------------------------------------------
PLOT NEW
PLOT DATA, xx,Irrad_norm,Grid_size+1,0,0,0
PLOT BANNER, "Normalized POP beam profile"
PLOT RANGEX, xx(1), xx(Grid_size+1)
PLOT RANGEY, 0, 1
PLOT COMM1, $DATE()
PLOT COMM2, $FILEPATH()
PLOT COMM3, "1/e^2 Gaussian Diameter = ", $STR(dia)
PLOT GO


Save the above text as a "xxx.zpl" file in Zemax's ZPL folder (the folder path can be viewed/changed in File -> Preferences). To run this macro, press F9, choose this file and click "Execute".

Here is an example. The POP window generated by Zemax shows an aberrated beam profile:


My macro generates a plot shown below.  First, it is normalized.  Second, the 1/e^2 beam diameter is given.



Compare three beam sizes:
1. POP pilot beam radius (paraxial 1/e^2) = 0.0070
2. POP "second moment" beam radius = 0.0071
3. Simple 1/e^2 radius calculated by my POP macro = 0.0024
The three sizes are different. Most often I just need know the 3rd value.

Next: It would be nice to also generate a Gaussian-fit curve.  I will perhaps write a MATLab-linked code to do this task.

Reference
[1] A.E.Siegman, "How to measure laser beam quality". PDF available on web by googling it.

Monday, September 12, 2011

Zemax as Gaussian beam calculator

This is version 2 of the last note on this subject.

Example 1: Given an input Gaussian beam of waist radius W01, a lens of focal length f, what is the output beam's waist radius W02 and waist location z2?
To quickly calculate the paraxial result, a simple Zemax model can be created as follows. In this example, W01 = 0.5 mm, z1 = 10 mm, f = 50 mm and wavelength = 640 nm.
The aperture and field settings are irrelevant to Gaussian calculation; they are set for making the optical layout look good:
Pressing [Ctrl]+[b] opens the Paraxial Gaussian Beam Data window. Right-click mouse opens the setting window:
So the waist radius (1/e^2 value) is set to 0.5 mm at the surface 1. Press OK the paraxial Gaussian beam results are given:
Notice that the image plane, the geometrical focus, is not exactly at the Gaussian beam waist. So a simple Merit Function can be used to move the image plane to the waist:
Optimize it and the image plane is adjusted to be at the waist. As the result, the Gaussian beam focus is about 66 um in front of the geometrical focus:

Example 2: We still have the same input Gaussian beam W01 = 0.5 mm and the lens f = 50 mm, but we want the focused beam waist radius to be 5 um. To do this, another lens is needed to expand the input beam first; say we have a f = -10 mm lens in hand. Where does this lens need to be? (d = ?)
To solve this, simply insert the lens f1 = -10 mm into the Zemax model:
Add in a GBPW operand into the Merit Function to calculate Gaussian waist. The target value is 5 um:
After optimization, Zemax gives the correct thickness of lens 1 to be 80.74 mm and the Paraxial Gaussian result shows that the beam is focused to 5 um radius:

Note that these are the first-order, paraxial calculations. Real lenses have aberrations and usually cannot give exactly the same results and will usually yield strong side-lobes. The next step should be to replace with the real lens models and use POP for actual beam evaluation.

Tuesday, July 5, 2011

Some Zemax tips and tricks

1. A few useful shortcut keys:

[Ctrl] + z: toggle between turning on and off as a variable.
F3: undo
[Ctrl] + F3: redo
[Ctrl] + a: toggle between multiple configurations.

2. How to show enough digits in the Lens Data Editor:
I prefer to set up at "Compact" mode:
File -> Preferences -> Editors -> Decimals -> Compact.
Or it can be set up to 14 digits.

3. When opening a new window in Zemax, I like to set the window size bigger than Zemax's default:
File -> Preferences -> Graphics -> Window X Size -> 800.
-> Window Y Size -> 600.

4. Add buttons to the tool bar:
File -> Preferences -> Buttons 17-32 (or 33-48)
I added the following which I frequently use:
Qfo (Quick Focus)
Qad (Quick Adjust)
Pop (Physical Optics Propagation)
Gbs (Skew Gaussian Beam)

(Click "Save" button in Preference window to save these custom settings to myZEMAX.CFG).

5. In 3D layout settings, check "Hide Lens Edges" to get the cleaner cross-sectional view (similar to the 2D layout).

6. Never set the # of CPU higher than your PC's actual CPU # (it won't increase Zemax calculation speed).

Thursday, April 28, 2011

Gaussian Beam Apodization in Zemax

When the light source in a Zemax model is a Gaussian laser beam, the apodization setting is important.

1. Definition.
From Zemax manual, light amplitude is


A(ρ) = exp(-2)


Here both A and ρ are the normalized parameters, i.e., they both equal to 0~1 within their full range. G is the apodization factor. If G = 1, the amplitude at the edge of the entrance pupil falls to 1/e of the center value (intensity falls to 1/e2).

2. Determine G value.
From equation:


I(ρ) = exp(-22) = 1/exp[2(√ G ρ)2]


It is not difficult to see that entrance pupil (system's clear aperture) radius is G times the Gaussian beam's 1/e2 radius.

For example, let's plot intensity I vs. ρ at different G values:

From this plot,
(1, blue curve) If G = 1, the Gaussian laser beam is clipped by the system clear aperture right at 13.5% (1/e2) of the peak value. For coherent sources like laser, diffraction will occur significantly.
(2, green curve) If G = 4, the system aperture is twice the size of the beam 1/e2 width. This aperture will clip only 0.03% (1/e8) of the peak power and should suffice for most laser system.
(3, red curve) If G = 9, the system aperture is three times the size of the beam 1/e2 width.

So, the apodization factor determines the Gaussian beam size relative to the system aperture size. If the designer knows both sizes, then setting the G value is easy. For example, for a simple system with a single-mode fiber source and a collimating lens, we know the NA of both. Then the apodization factor should be:








G = NAlens2

NAfiber2

(1)

Note that the fiber NA in this equation is the 1/e2 value. Fiber manufacturers define/measure their NA differently. For example, Corning datasheets give the NA at 1% value, which is 1.517 times larger.

References:
1. http://www.zemax.com/kb/articles/164/1/What-Does-the-Term-Apodization-Mean/Page1.html

Thursday, December 9, 2010

Lightroom is limited on color management

Adobe's Lightroom is really great. I now use LR for my 97% of time processing and printing photos. (The remaining 2% time uses Photoshop and 1% uses Silverfast).

However, LR is limited on color management and many times it causes annoying inconvenience:

(1) No soft proofing in LR's print module. For critical printing work, one has to open the file in Photoshop for soft proofing. My 16-bit color images scanned from 8x10 film are 1.5 GB and opening them in both LR and PS can be really slow, if not crashing my computer.

(2) The rendering color profile used in LR's Develop module is ProPhoto RGB but in Library and Print module it is Adobe RGB (1998). Because of this, I have seen some color inconsistency when the image is seen at different LR modules. For example, some deep reds cannot be shown in Adobe RGB color space.

I guess Adobe does not want LR to reduce too much users from PS so they purposely make the LR imperfect... sigh.