Zernike polynomials
restedumonde
I have recently started to work with Zernike polynomials to simulate some optical aberrations.
Igor has the function ZernikeR(n, m, r) in it, but I cannot manage to use it properly. The help section on this topic is quite succint.
This is what I wrote:
Make/O/N=(1024,1024) test
SetScale/I x -511,512,"", test
SetScale/I y -511,512,"", test
Variable n=2
Variable m=1
test=ZernikeR(n,m,sqrt(x^2+y^2))
What would be the appropriate syntax to create a 2D wave of a Zernike polynomial with given n and m?
Thanks.
The main problem with your code is in your wave scaling. The radius should be normalized (0 to 1). Personally I'd do away with the wave scaling and modify your ZernikeR() arguments to the correct normalization.
A.G.
WaveMetrics, Inc.
July 23, 2013 at 11:36 am - Permalink
I had both a normalization problem, and an inversion between n and m.
Here is my new working code:
Make/O/N=(1024,1024) test
SetScale/I x -1,1,"", test
SetScale/I y -1,1,"", test
Variable n=1
Variable m=2
test=ZernikeR(n,m,sqrt(x^2+y^2))
July 24, 2013 at 09:31 am - Permalink
(1) don't forget to include the angular factor described in the Igor help file and B&W to get the full orthogonal circle polynomials.
(2) if you are applying the polynomials in calculations over a rectangular grid enclosing the unit circle, you will get a lot of NaNs for r>1 (this is what ZernikeR(n,m,r) returns). You can either use logic functions to exclude calculations for r>1, which will probably execute more slowly, or calculate everywhere and remove the NaNs if desired. I find
MatrixOP ReplaceNaNs
to be particularly useful for this.September 19, 2013 at 04:43 am - Permalink