order (int, {7, 9, 11, 15, 20, 23, 31}) – degree of the generating pseudorandom polynomial
len (int, optional) – lenght of output binary sequence
seed (int, optional) – seed of the generator (initial state of the LFSR).
It must be provided if you want to continue the sequence.
Default is 2**order-1.
return_seed (bool, optional) – If True, the last state of LFSR is returned. Default is False.
Returns:
out – generated pseudorandom binary sequence
Return type:
binary_sequence
Raises:
ValueError – If order is not in [7, 9, 11, 15, 20, 23, 31].
TypeError – If len is not an integer.
Warns:
UserWarning – If the seed is 0 or a multiple of 2**order.
Examples
You can generate a PRBS sequence using the following code:
Converts a binary sequence into an electrical signal, sampled at a frequency gv.fs.
Warning
Parameter value pulse_shape='rect' is equivalent to pulse_shape='nrz'. It is recommended to use pulse_shape='nrz', 'rect' will be removed in futures versions.
bias (float) – DC bias of the output signal. Default: 0.0
Vout (float) – Output signal amplitude. Should be in the range [-48, 48] Volts. Default: 1.0
pulse_shape (str, {‘nrz’, ‘rect’, ‘gaussian’}) – Pulse shape at the output. Default: ‘nrz’
BW (float) – Bandwidth of DAC. If None bandwidth is not limited. Default: None
c (float) – Chirp of the Gaussian pulse. Only applicable if pulse_shape='gaussian'. Default: 0.0
m (int) – Order of the super-Gaussian pulse. Only applicable if pulse_shape='gaussian'. Default: 1
T (int) – Pulse width at half maximum in number of samples. Only applicable if pulse_shape='gaussian'. Default: gv.sps
Returns:
The converted electrical signal.
Return type:
electrical_signal
Raises:
ValueError – If pulse_shape is not 'rect' or 'gaussian'.
If Vout is not between -48 and 48 Volts.
If bias is not between -48 and 48 Volts.
If T is <=0 or greater than 2 times the samples per bit.
If m is not a positive integer.
TypeError – If Vout is not a scalar value.
If bias is not a scalar value.
If c is not a scalar value.
If m is not an integer value.
If T is not an integer value.
Examples
fromopticomlib.devicesimportDACfromopticomlibimportgvgv(sps=32)# set samples per bitDAC('0 0 1 0 0',Vout=5,pulse_shape='gaussian',m=2).plot('r',lw=3,grid=True).show()
Modulate the phase of the input optical signal through input electrical signal.
Parameters:
op_input (optical_signal) – Optical signal to be modulated.
el_input (float, ndarray, or electrical_signal) – Driver voltage. It can be an integer value, in which case the phase modulation is constant, or an electrical signal of the same length as the optical signal.
Vpi (float) – Voltage at which the device achieves a phase shift of \(\pi\). Default value is 5.0.
Returns:
op_output – Modulated optical signal.
Return type:
optical_signal
Raises:
TypeError – If op_input type is not [optical_signal].
If el_input type is not in [float, ndarray, electrical_signal].
ValueError – If el_input is [ndarray] or [electrical_signal] but, length is not equal to op_input length.
Asymmetric coupler and opposite driving voltages model (\(u_1(t)=-u_2(t)=u(t)\) Push-Pull configuration).
The input and output are polarization maintained. Internally, the modulator can select the polarization
to be modulated by setting the parameter pol to 'x' or 'y'. If one of them is selected, the other is
strongly attenuated (set to zeros).
Parameters:
op_input (optical_signal) – Optical signal to be modulated. This optical signal must contain only one polarization op_input.n_pol=1. Otherwise
it remove the second polarization.
el_input (Number, ndarray, or electrical_signal) – Driver voltage, with zero bias.
bias (float, optional) – Modulator bias voltage. Default is 0.0.
Vpi (float, optional) – Voltage at which the device switches from on-state to off-state. Default is 5.0 V.
loss_dB (float, optional) – Propagation or insertion losses in the modulator, value in dB. Default is 0.0 dB.
ER_dB (float, optional) – Extinction ratio of the modulator, in dB. Default is 26 dB.
pol (str, {‘x’, ‘y’} optional) – Polarization of the modulator. Default is 'x'.
BW (float, optional) – Modulator bandwidth in Hz. If not provided, the bandwidth is not limited.
Returns:
Modulated optical signal.
Return type:
optical_signal
Raises:
TypeError – If op_input type is not [optical_signal].
If el_input type is not in [float, ndarray, electrical_signal].
ValueError – If el_input is [ndarray] or [electrical_signal] but, length is not equal to op_input length.
Amplifies the optical signal at the input, adding amplified spontaneous emission (ASE) noise in two polarizations at the output.
Simplest model (no saturation output power).
Parameters:
input (optical_signal) – The optical signal to be amplified.
G (float) – The gain of the amplifier, in dB.
NF (float) – The noise figure of the amplifier, in dB.
BW (float, optional) – The bandwidth of the amplifier, in Hz. If None bandwidth will be gv.fs.
where \(h\) is the Planck constant and \(f_0\) is the central frequency of communication
(by default gv.f0 is taken, if you wish change this value, you can change wavelength
parameter in gv()). Noise is generated for two polarizations xy as a complex signal, with a
distribution \(\mathcal{N}(0, P_\text{ase}/4)\) for real and imaginary parts.
Examples
Following picture show the input-output of EDFA from a sinusoidal signal. For values of example, the output noise power
must be \(P_{ase} \approx -27\) dBm.
>>> fromopticomlibimportdbm>>> print(dbm(y.power('noise').sum()))# print sum of power of two polarizations-28.068263005828555
We can see that noise power is a little less than theoretical prediction, this is because
the filter used in the EDFA is not a rectangular response filter (it’s a 4th order Bessel filter).
Simulates the transmission through an optical fiber, solving Schrödinger’s equation numerically,
by using split-step Fourier method with adaptive step (method based on limiting the nonlinear phase rotation) [2].
Polarization mode dispersion (PMD) is not considered in this model.
TypeError – If input is not of type ndarray or electrical_signal.
Example
fromopticomlib.devicesimportLPFfromopticomlibimportgv,electrical_signalimportmatplotlib.pyplotaspltimportnumpyasnpgv(N=10,sps=128,R=1e9)t=gv.tc=20e9/t[-1]# frequency chirp from 0 to 20 GHzinput=electrical_signal(np.sin(np.pi*c*t**2))output=LPF(input,10e9)input.psd('r',label='input',lw=2)output.psd('b',label='output',lw=2)plt.xlim(-30,30)plt.ylim(-20,5)plt.annotate('-6 dB',xy=(10,-5),xytext=(10,2),c='r',arrowprops=dict(arrowstyle='<->'),fontsize=12,ha='center',va='center')plt.show()
where \(\mathcal{R}\) is the responsivity of the photodetector, \(P_{in}\) is the input power, \(i_{th}\) and \(i_{sh}\) are thermal and shot noise
respectively and \(i_{dark}\) is the dark current of photodetector.
where \(E_x\) and \(E_y\) are the amplitudes of x-polarization and y-polarization modes respectively
and \(n_x\) and \(n_y\) are the noise of x-polarization and y-polarization modes respectively.
The thermal and shot noises are random variables with normal distribution and variance given by [Agrawal]:
where \(k_B\) is the Boltzmann constant, \(T\) is the temperature of the photodetector, \(R_L\) is the load resistance,
\(F_n\) is the noise figure of the photodetector, \(\Delta f\) is the bandwidth of the photodetector, \(e\) is the electron charge.
This function numerically calculates the reflectivity (transfer function \(H(f)\) in reflection) of the grating by
solving the coupled-wave equations using Runge-Kutta method with help of signal.integrate.solve_ivp() function. See Notes
section for more details.
In order to design the grating, combination of the following parameters can be used:
neff, v, fc, (dneff or vdneff), (N or kL or L)
neff, v, landaD, (dneff or vdneff), (N or kL or L)
neff, v, landaD, kL, (N or L)
Bandwidth is governed essentially by three parameters:
Bragg wavelength (\(\lambda_D\)). Bandwidth is proportional to \(\lambda_D\).
Product of visibility and effective index change (\(v\delta n_{eff}\)). If \(v\delta n_{eff}\) is small, the bandwidth is small.
Length of the grating (\(L\)). Bandwidth is inversely proportional to \(L\).
On the other hand, chirp parameter \(F\) can increase the bandwidth of the grating as well.
Parameters:
input (optical_signal) – The input optical signal.
neff (float, optional) – Effective refractive index of core fiber. Default is 1.45.
v (float, optional) – Visibility of the grating. Default is 1.
If a custom function is used, it must be a function of the form f(z)
where z is the position along the grating length normalized by L (i.e. z=z/L),
and the function must be defined in the range -0.5<=z<=0.5.
F (float, optional) – Chirp parameter. Default is 0.
filtfilt (bool, optional) – If True, group delay will be corrected in output signal. Default is True.
retH (bool, optional) – If True, the function will return the reflectivity (H(w)) of the grating. Default is False.
Returns:
output (optical_signal) – The reflected optical signal
H (np.ndarray, optional) – Frequency response of grating fiber H(w), only returned if retH=True
Raises:
TypeError – If input is not an optical_signal.
ValueError – If the parameters are not correctly specified.
Warns:
UserWarning – If the apodization function is not recognized, a warning will be issued and the function will use uniform apodization.
UserWarning – If bandwith is too large, the function will issue a warning and will use a default bandwidth of fs.
Notes
Following coupled-wave theory, we assume a periodic, single-mode
waveguide with an electromagnetic field which can be represented by
two contradirectional coupled waves in the form [3]:
where A and B are slowly varying amplitudes of mode traveling in \(+z\) and math:-z directions, respectively
These amplitudes are linked by the standard coupled-wave equations:
\[\begin{split}R' &= j\hat{\sigma} R + j\kappa S \\
S' &= -j\hat{\sigma} S - j\kappa R\end{split}\]
where \(R\) and \(S\) are \(R(z) = A(z)e^{j\delta z - \phi/2}\) and \(S(z) = B(z)e^{-j\delta z + \phi/2}\).
In these equations \(\kappa\) is the “AC” coupling coefficient and \(\hat{\sigma}\) is a general “dc” self-coupling coefficient defined as
where \(\lambda_D = 2n_{eff}\Lambda\) is the “design wavelength” for Bragg scattering by an infinitesimally weak grating \((\delta n_{eff}\rightarrow 0)\) with
a period \(\Lambda\).
If the grating is uniform along \(z\), then \(\delta n_{eff}\) is a constant and \(\phi' = 0\),
and thus \(\kappa\), \(\sigma\), and \(\hat{\sigma}\) constants.
For apodized gratings, \(\delta n_{eff}\) is a function of \(z\), and therefore \(\kappa\), \(\sigma\), and \(\hat{\sigma}\) are also functions of \(z\).
If phase chirp is present, \(\phi\) and \(\phi'\) are also a function of \(z\). This implementation considers only linear chirp, so:
\[\phi'(z) = 2Fz/L^2\]
where \(F\) is a dimensionless “chirp parameter”, given by [4]: