Skip to content

odak.learn.wave.generate_complex_field

Definition to generate a complex field with a given amplitude and phase.

Parameters:

Name Type Description Default
amplitude ndarray or float

Amplitude of the field.

required
phase ndarray or float

Phase of the field.

required

Returns:

Type Description
ndarray

Complex field.

Source code in odak/learn/wave/util.py
def generate_complex_field(amplitude, phase):
    """
    Definition to generate a complex field with a given amplitude and phase.

    Parameters
    ----------
    amplitude         : ndarray or float
                        Amplitude of the field.
    phase             : ndarray or float
                        Phase of the field.

    Returns
    -------
    field             : ndarray
                        Complex field.
    """
    if type(phase) == 'torch.Tensor':
        phase = torch.tensor(phase, requires_grad=True)
    elif type(phase) == type(1.):
        phase = torch.tensor([phase], requires_grad=True)
    if type(amplitude) == 'torch.Tensor':
        amplitude = torch.tensor(amplitude, requires_grad=True)
    elif type(amplitude) == type(1.):
        amplitude = torch.tensor([amplitude], requires_grad=True)
    field = amplitude*torch.cos(phase)+1j*amplitude*torch.sin(phase)
    return field

Notes

Regarding usage of this definition, you can find use cases in the engineering notes, specifically at Optimizing holograms using Odak.

See also