- Home
- Sequential Ray Tracing
- System Modeling
- How To Model a 'Black-Box' Optical System Using Zernike Coefficients
How To Model a 'Black-Box' Optical System Using Zernike Coefficients
- By Mark Nicholson
- Published 9 August 2007
- System Modeling
-
Rating:




Copying Zernike Data Between Lenses
Return to the 'Cooke One Field One Wavelength.zmx' file, and click on Analysis...Aberration Coefficients...Zernike Standard Coefficients. ZEMAX computes the wavefront of the system, and then fits a series of Zernike polynomials.

Both the sampling of the wavefront, and the number of Zernike terms, can be defined by the user via the Settings dialog. The key parameters in determining whether the wavefront is adequately sampled or the number of Zernike terms are the RMS fit error and the maximum fit error. Using the default parameters for both sampling and number of terms, this design delivers

Which means that when we subtract the real wavefront from one reconstructed from the Zernike coefficients, the errors are of the order of a millionth of a wave. That's close enough! However, in general you may need to adjust the wavefront sampling and maximum Zernike term in order to achieve an acceptable fit.
We now need to transfer the Zernike coefficient data out of this design and into the paraxial equivalent design. This could be done by printing the Zernike data out and re-typing it, but this is tedious. This is a good job for a macro.
The following macro (also included in the zip file at the end of the article), called Zernike Readout.zpl, gets the Zernike data from this lens and saves it to a file in the format that Tools...Import Data on the Extra Data Editor can read. The steps it goes through are as follows:
First it defines all the variables it will need.

(Note the editor used to write this macro was ConText. Note also that the sampling amd maximum Zernike terms should be set to the values you used for the Zernike Analysis above.) Then the macro gets the Exit Pupil Diameter and Zernike data:

Note that the normalization radius of the Zernike surafce is half the Exit Pupil Diameter. The macro then prints the data out to a .DAT file in the correct format for the Zernike Standard Phase surface to read it:

The Zernike data is entered into the Extra Data Parameter columns of the Zernike Standard Phase surface as follows:

Put this macro into the {zemaxroot}/macros folder, click on Macros...Refresh Macro List so that the macro appears in the menu listing, and then run it. It will create a file called 'zernike.dat' in the same folder as the original ZEMAX file. If you open this file in Notepad, you will see:

This file contains all the data the Zernike Standard Phase surface needs. The first number is the number of Zernike terms, then the normalization radius, then each Zernike term. The Extra Data Editor's Import tool can read this file directly.
Return to the paraxial equivalent lens file, and open the Extra Data Editor. On its Tools menu, select Import Data:

Press the 'Browse' button and navigate to the folder where zernike.dat is stored:

and import this to surface 2. The Extra Data Editor now shows:

and the Zernike data has been imported. The wavefront error shows:

and the spot diagram shows

This file produces identical ray-tracing results to the original file! In the attached zip, the file 'Zernike Equivalent.zmx' shows the finished system. Also, the file 'Direct Comparison.zmx' shows both the original and Zernike versions of the same file as two different configurations. This allows easy comparisons between the two versions of the file.


Both the sampling of the wavefront, and the number of Zernike terms, can be defined by the user via the Settings dialog. The key parameters in determining whether the wavefront is adequately sampled or the number of Zernike terms are the RMS fit error and the maximum fit error. Using the default parameters for both sampling and number of terms, this design delivers

Which means that when we subtract the real wavefront from one reconstructed from the Zernike coefficients, the errors are of the order of a millionth of a wave. That's close enough! However, in general you may need to adjust the wavefront sampling and maximum Zernike term in order to achieve an acceptable fit.
We now need to transfer the Zernike coefficient data out of this design and into the paraxial equivalent design. This could be done by printing the Zernike data out and re-typing it, but this is tedious. This is a good job for a macro.
The following macro (also included in the zip file at the end of the article), called Zernike Readout.zpl, gets the Zernike data from this lens and saves it to a file in the format that Tools...Import Data on the Extra Data Editor can read. The steps it goes through are as follows:
First it defines all the variables it will need.

(Note the editor used to write this macro was ConText. Note also that the sampling amd maximum Zernike terms should be set to the values you used for the Zernike Analysis above.) Then the macro gets the Exit Pupil Diameter and Zernike data:

Note that the normalization radius of the Zernike surafce is half the Exit Pupil Diameter. The macro then prints the data out to a .DAT file in the correct format for the Zernike Standard Phase surface to read it:

The Zernike data is entered into the Extra Data Parameter columns of the Zernike Standard Phase surface as follows:

Put this macro into the {zemaxroot}/macros folder, click on Macros...Refresh Macro List so that the macro appears in the menu listing, and then run it. It will create a file called 'zernike.dat' in the same folder as the original ZEMAX file. If you open this file in Notepad, you will see:

This file contains all the data the Zernike Standard Phase surface needs. The first number is the number of Zernike terms, then the normalization radius, then each Zernike term. The Extra Data Editor's Import tool can read this file directly.
Return to the paraxial equivalent lens file, and open the Extra Data Editor. On its Tools menu, select Import Data:

Press the 'Browse' button and navigate to the folder where zernike.dat is stored:

and import this to surface 2. The Extra Data Editor now shows:

and the Zernike data has been imported. The wavefront error shows:

and the spot diagram shows

This file produces identical ray-tracing results to the original file! In the attached zip, the file 'Zernike Equivalent.zmx' shows the finished system. Also, the file 'Direct Comparison.zmx' shows both the original and Zernike versions of the same file as two different configurations. This allows easy comparisons between the two versions of the file.
