Bahtinov mask simulated diffraction pattern

Diffraction Simulator

Diffraction Simulator is a computer program I wrote to simulate the diffraction pattern generated by a focusing mask or secondary mirror obstruction in telescopes. I was inspired to write it after attempting to design my own Bahtinov mask, when I realised I needed a method to simulate the diffraction pattern generated by the mask. You can read a brief overview on how to use it in the next section, or you can skip straight to the download. The source code is available on GitHub, feel free to contribute or make a suggestion.

Diffraction Simulator software screenshot
Screenshot of Diffraction Simulator.


Loading the file

First select the image file for your mask. This image represents the aperture that the light passes through, like a Bahtinov mask for example. White areas are completely transparent, while black areas are opaque. Grey can be used to represent areas with partial transparency. The image should be:

  • Square – If the image is not a square, it will be resized to a square ratio.
  • Greyscale – If a colour image is provided, it will be converted to greyscale.

There are several good online mask generators, such as the Bahtinov Mask Generator by Satoru Takagi.


These are the optical parameters of the telescope. In detail, they are:

  • Aperture – Telescope aperture diameter, in millimetres.
  • Focal Length – Telescope focal length, in millimetres.
  • Defocus – This is the defocus of the optical system, in millimetres. A value of zero corresponds to perfect focus. You can use the slider to change this, or enter a specific value.
Optics settings for Diffraction Simulator
The optical system settings.

Reference light

This is the light entering the telescope. White light is the superposition of light of many different wavelengths, so the program solves for a range of discrete wavelengths and then sums the result. A set of linearly spaced wavelengths are calculated, where the start and stop wavelengths are specified in nanometres. The number of points in the range must also be specified; a higher value will yield a smoother colour gradient in the final diffraction pattern, but will take longer to compute.

The amplitude of each wavelength can also be specified. Selecting Uniform will mean that each wavelength of light has the same amplitude. In white light, each wavelength does not have uniform amplitude, so this will result in a diffraction pattern with a yellow tint. Selecting D65 will scale each wavelength of light according to the D65 power spectrum, producing a diffraction pattern which appears white.

Reference light settings for Diffraction Simulator
The reference light settings.

Image settings

These are the settings for the output image.

  • Resolution – This is the resolution of the output image, in pixels. A higher resolution will take longer to compute.
  • Brightness – Use this to increase the brightness of the output image by a specified amount in decibels. This can reveal more details in darker areas, but may cause clipping to occur.
Output image settings for Diffraction Simulator
The output image settings.


Diffraction Simulator

2 thoughts on “Diffraction Simulator”

  1. I attempted to use the Diffraction Simulator to analyze a Bahtinov mask I generated with the Bahtinov Mask Drawings Generator. When I pushed the “Generate Image’ button it threw a “Out of memory’ error. Windows Task Manager shows its memory usage to be 80Mb and my total system usage is 51%. I’m not sure how to proceed from here.

    1. Hi John, try reducing the ‘Resolution’ under ‘Image Settings’, this should reduce the RAM requirement. Are you able to run the program with the default settings and Bahtinov mask file provided? If you still can’t get it to work let me know.

Leave a Comment

Your email address will not be published. Required fields are marked *