slmsuite.holography.toolbox.phase.binary#

binary(grid, vector=(0, 0), shift=0, a=3.141592653589793, b=0, duty_cycle=0.5)[source]#

Returns a simple binary grating toward a given vector in \(k\)-space.

\[\begin{split}\phi(\vec{x}) = \left\{ \begin{array}{ll} a, & ( [2\pi \cdot \vec{k} \cdot \vec{x} + s] \,\,\,\,\text{mod}\,\,\,\, 2\pi ) < 2\pi*d \\ b, & \text{ otherwise}. \end{array} \right.\end{split}\]

To realize a binary grating with a given pixel period, either use convert_vector() with "freq" units or pass a vector with a coordinate larger than 1:

n_x = 4     # Period in pixels

# Option 1: convert
binary_integer_period = toolbox.phase.binary(
    grid=slm,
    vector=toolbox.convert_vector(
        (1./n_x, 0),
        from_units="freq",
        to_units="kxy",
        hardware=slm
    )
)

# Option 2: pass directly
binary_integer_period = toolbox.phase.binary(
    grid=slm,
    vector=(n_x, 0)
)

Note

When parameters are chosen to produce integer period, this function uses speed optimizations (implementation incomplete). Otherwise, this function uses np.mod on top of blaze() to compute gratings.

Parameters:
  • grid (Union[Tuple[ndarray, ndarray], object]) – \(\vec{x}\). Meshgrids of normalized \(\frac{x}{\lambda}\) coordinates corresponding to SLM pixels, in (x_grid, y_grid) form. These are precalculated and stored in any SLM, so such a class can be passed instead of the grids directly.

  • vector (Union[Tuple[float, float], Tuple[int, int]]) –

    \(\vec{k}\). Blaze vector in normalized \(\frac{k_x}{k}\) units. See convert_vector().

    If the user passes data greater than 1, this is interpreted as requesting a binary grating with the given period. This feature ignores whatever transformations might have been applied to grid.

  • shift (float) – Radians to laterally shift the period of the grating by.

  • a (float) – Value at one extreme of the binary grating.

  • b (float) – Value at the other extreme of the binary grating. Defaults to zero, in which case a is the amplitude.

  • duty_cycle (float) – The grating value is a for duty_cycle * period. Then the grating value is b for (1 - duty_cycle) * period.

Return type:

ndarray

Returns:

The phase for this function.