How to get MTF from PSF

  • 17 May 2023
  • 7 replies

HI everyone

How do I use PSF to plot MTF in MATLAB?

The resulting plot may differ from the commonly used MTF plot.


How to plot the MTF with separate tangential (TAN) and sagittal (SAG) components?



Best answer by Jeff.Wilde 20 May 2023, 21:41

View original

7 replies

Userlevel 1
Badge +2


I strongly recommend you use the API to collect the MTF directly from your model.  It looks like you already know how to interface Matlab to OpticStudio.  This code snippet should help:

analysisCurrent = TheApplication.PrimarySystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.FftMtf);
settingsCurrent = analysisCurrent.Settings;

settingsCurrent.SampleSize = ZOSAPI.Analysis.SampleSizes.S_128x128;

resultsCurrent = analysisCurrent.GetResults;
dataSeriesCurrent = resultsCurrent.GetDataSeries(0);
frequencySpatial = dataSeriesCurrent.XData.Data.double;
mtfNominal = dataSeriesCurrent.YData.Data.double;


r.frequency = frequencySpatial;
r.mtfNominal = mtfNominal;


Thanks for your help

But what I am currently doing is adding the PSFs of three different wavelengths and plotting the MTF to match Zemax. Is it possible to achieve this with the API?




Userlevel 1
Badge +2

The MTF analysis in OpticStudio performs a weighted average of the MTFs at several wavelengths.  So you can configure your wavelengths in your OpticStudio model with equal or specific weighting to achieve the aggregate wavelength weighted MTF. 

Alternatively, you can get the (x3) MTFs at separate wavelengths and then combine then yourself outside of OpticStudio.

If you want to generate an MTF from PSFs, I recommend Goodman’s Introduction to Fourier Optics.  Following the math in that textbook leads you to a 2-D convolution that produces MTFs directly from PSFs.

Userlevel 6
Badge +3

Hi Shun,

Yes, it’s fairly straightforward to use the API to extract the intensity PSF and then apply an FFT in Matlab to calculate the OTF.

Here’s what I find using the lens model you attached:

In this case I simply used the polychromatic PSF from OpticStudio, but it’s not much harder to extract the individual monochromatic PSF’s, then combine them in Matlab and take an FFT.





hi Jeff

I'm sorry for taking so long to get back to you, and thank you for providing me with this method.

It was my fault for not describing my situation properly.

At filed2, I need to move the red and blue lights in the y-direction because the system has lateral color, and only by superimposing them can I obtain a similar  PSF.

Therefore, I need to import each psf.txt file into Excel, combine them with weights, and then import them into MATLAB to convert them into  MTF.




Hi Jeff


I made some slight modifications to the code you provided in order to achieve my goal. However, the resulting MTF image doesn't match yours. Is it possible that I made an error?





Userlevel 6
Badge +3

Hi Shun,

Check your x & f vectors.  They should be consistent with the PSF sample spacing, which in your file dx = 1 um.  Otherwise, it looks okay.