Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arne Striegler
pypho
Commits
8f28018c
Commit
8f28018c
authored
Oct 05, 2018
by
Arne Striegler
😁
Browse files
v1.0.0
parent
18ced158
Changes
38
Hide whitespace changes
Inline
Side-by-side
examples/example_amplifier_osnr_8.py
0 → 100644
View file @
8f28018c
##!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Import functions and libraries
import
sys
sys
.
path
.
append
(
'../'
)
from
pypho_setup
import
pypho_setup
from
pypho_bits
import
pypho_bits
from
pypho_signalsrc
import
pypho_signalsrc
from
pypho_lasmod
import
pypho_lasmod
from
pypho_fiber
import
pypho_fiber
from
pypho_oamp
import
pypho_oamp
from
pypho_osnr
import
pypho_osnr
from
pypho_functions
import
*
import
numpy
as
np
import
matplotlib.pyplot
as
plt
# Define network elements
gp
=
pypho_setup
(
nos
=
128
,
sps
=
128
,
symbolrate
=
10e9
)
bitsrc
=
pypho_bits
(
glova
=
gp
,
nob
=
gp
.
nos
,
pattern
=
'random'
)
esigsrc
=
pypho_signalsrc
(
glova
=
gp
,
pulseshape
=
'gauss_rz'
,
fwhm
=
0.85
)
sig_1550
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
0.25
*
np
.
pi
)
SSMF
=
pypho_fiber
(
glova
=
gp
,
l
=
8.0e3
,
D
=
17
,
S
=
0
,
alpha
=
2.0
,
gamma
=
1.0e-12
,
phi_max
=
10.0
)
# High loss fiber, to speed up the simulation
amp
=
pypho_oamp
(
glova
=
gp
,
NF
=
6
)
osnr
=
pypho_osnr
(
glova
=
gp
)
# Simulation
bits
=
bitsrc
()
esig
=
esigsrc
(
bitsequence
=
bits
)
E
=
sig_1550
(
esig
=
esig
)
E
=
osnr
(
E
=
E
,
OSNR
=
58.0
)
# Set initial OSNR to 58 dB
P
=
3.0
# Signal power
plt
.
figure
(
1
);
plt
.
plot
(
0
,
osnr
(
E
=
E
),
'r*'
)
for
t
in
range
(
10
):
# Loop through 10 spans
E
=
SSMF
(
E
=
E
)
E
=
amp
(
E
=
E
,
Pmean
=
P
)
# Set mean power to 3 dBm
plt
.
plot
(
t
+
1
,
osnr
(
E
=
E
),
'r*'
)
plt
.
title
(
"OSNR as function of number of spans"
,
loc
=
'left'
);
plt
.
ylabel
(
'OSNR [dB]'
);
plt
.
xlabel
(
'Span number'
);
plt
.
grid
(
True
)
\ No newline at end of file
examples/example_ber_estimation_10.py
0 → 100644
View file @
8f28018c
##!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Import functions and libraries
import
sys
sys
.
path
.
append
(
'../'
)
from
pypho_setup
import
pypho_setup
from
pypho_bits
import
pypho_bits
from
pypho_signalsrc
import
pypho_signalsrc
from
pypho_lasmod
import
pypho_lasmod
from
pypho_fiber
import
pypho_fiber
from
pypho_fiber_birefringence
import
pypho_fiber_birefringence
from
pypho_arbmod
import
pypho_arbmod
from
pypho_oamp
import
pypho_oamp
from
pypho_osnr
import
pypho_osnr
from
pypho_sample
import
pypho_sample
from
pypho_optfi
import
pypho_optfi
from
pypho_cwlaser
import
pypho_cwlaser
from
pypho_functions
import
*
import
numpy
as
np
import
copy
import
matplotlib.pyplot
as
plt
from
matplotlib
import
colors
as
mcolors
colors
=
dict
(
mcolors
.
BASE_COLORS
,
**
mcolors
.
CSS4_COLORS
)
plt
.
close
(
'all'
)
# Define network elements
gp
=
pypho_setup
(
nos
=
512
,
sps
=
128
,
symbolrate
=
10e9
)
bitsrc
=
pypho_bits
(
glova
=
gp
,
nob
=
gp
.
nos
,
pattern
=
'ones'
)
esigsrc
=
pypho_signalsrc
(
glova
=
gp
,
pulseshape
=
'gauss_rz'
,
fwhm
=
0.25
)
sig_1550
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
np
.
pi
/
4.0
)
SSMF
=
pypho_fiber
(
glova
=
gp
,
l
=
80.0e3
,
D
=
17.0
,
S
=
0
,
alpha
=
0.3
,
gamma
=
1.14
,
phi_max
=
0.4
)
DCF
=
pypho_fiber
(
glova
=
gp
,
l
=
1.0e3
,
D
=
-
SSMF
.
D
*
SSMF
.
l
,
S
=
0
,
alpha
=
0.2e-12
,
gamma
=
1.0e-12
,
phi_max
=
10.0
)
amp
=
pypho_oamp
(
glova
=
gp
,
Pmean
=
3.0
,
NF
=
5
)
osnr
=
pypho_osnr
(
glova
=
gp
)
modulator
=
pypho_arbmod
(
glova
=
gp
)
sigsampler
=
pypho_sample
(
glova
=
gp
)
cw_src
=
pypho_cwlaser
(
glova
=
gp
,
power
=
3
,
Df
=
0
,
teta
=
np
.
pi
/
4.0
)
filter_f0
=
pypho_optfi
(
glova
=
gp
,
Df
=
0
,
B
=
50
)
# Simulation
# Create bitpattern
bits_x
=
np
.
append
(
bitsrc
(
pattern
=
'random'
),
[
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
)])
bits_y
=
np
.
append
(
bitsrc
(
pattern
=
'random'
),
[
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
)])
# Create pulsetrain
onebits
=
bitsrc
(
pattern
=
'ones'
)
esig
=
esigsrc
(
bitsequence
=
onebits
)
E_Tx
=
sig_1550
(
esig
=
esig
)
# Define constellation points: 16-QAM
alpha
=
np
.
arctan
(
np
.
sqrt
(
1.0
)
/
3.0
)
constpts_x
=
[(
[
np
.
sqrt
(
3.0
**
2
+
1.0
)]
*
8
+
[
np
.
sqrt
(
2.0
)]
*
4
+
[
np
.
sqrt
(
2
*
3.0
**
2
)]
*
4
),
(
[
2.0
*
np
.
pi
*
x
/
4.0
+
alpha
for
x
in
range
(
0
,
4
)]
+
[
2.0
*
np
.
pi
*
x
/
4.0
+
np
.
pi
-
alpha
for
x
in
range
(
0
,
4
)]
+
[
2.0
*
np
.
pi
*
x
/
4.0
+
np
.
pi
/
4
for
x
in
range
(
0
,
8
)]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
16
)]),
(
[
x
for
x
in
range
(
0
,
16
)]),
([(
0
),(
0
),(
0
),(
0
)],
[(
0
),(
0
),(
0
),(
1
)],
[(
0
),(
0
),(
1
),(
0
)],
[(
0
),(
0
),(
1
),(
1
)],
[(
0
),(
1
),(
0
),(
0
)],
[(
0
),(
1
),(
0
),(
1
)],
[(
0
),(
1
),(
1
),(
0
)],
[(
0
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
0
)],
[(
1
),(
1
),(
0
),(
1
)],
[(
1
),(
1
),(
0
),(
0
)],
[(
1
),(
0
),(
1
),(
1
)],
[(
1
),(
0
),(
1
),(
0
)],
[(
1
),(
0
),(
0
),(
1
)],
[(
1
),(
0
),(
0
),(
0
)]
)]
# codes not optimized!
constpts_y
=
constpts_x
# Constellation
E
=
modulator
(
E
=
E_Tx
,
constpoints
=
[
constpts_x
,
constpts_y
],
bits
=
[
bits_x
,
bits_y
])
# Modulate
P0
=
0.0
E
=
amp
(
E
=
E
,
Pmean
=
0
)
LO
=
cw_src
(
power
=
10.0
*
np
.
log10
(
1e5
*
np
.
mean
(
np
.
abs
(
E
[
0
][
'E'
][
0
])
**
2
)
))
# Local oscillator
E
=
amp
(
E
=
E
,
Pmean
=
P0
)
E
=
osnr
(
E
=
E
,
OSNR
=
15.0
)
# Set initial OSNR to bad 20 dB
for
c
in
range
(
0
,
10
):
print
(
'Span: '
,
c
)
fibres
=
pypho_fiber_birefringence
.
create_pmd_fibre
(
SSMF
.
l
,
1e3
,
0.00
)
E
=
SSMF
(
E
=
E
,
birefarray
=
fibres
)
E
=
DCF
(
E
=
E
,
l
=
1.0
)
E
=
amp
(
E
=
E
,
Pmean
=
P0
)
print
(
'OSNR = '
,
osnr
(
E
=
E
))
############################
# Calculate decision matrix
############################
E
=
amp
(
E
=
E
,
Pmean
=
0
)
#Ein = copy.deepcopy(E)
plt
.
figure
(
1
)
# Get decision matrix
Dec_x
,
Esx_re_ax
,
Esx_im_ax
,
Dec_y
,
Esy_re_ax
,
Esy_im_ax
=
get_decision_matrix
(
gp
,
E
,
[
constpts_x
,
constpts_y
],
[
bits_x
,
bits_y
],
LO
,
filter_f0
,
sigsampler
)
# Plot decision matrix
plt
.
figure
(
1
)
plt
.
subplot
(
2
,
1
,
1
);
h
=
plt
.
contourf
(
Esx_re_ax
,
Esx_im_ax
,
Dec_x
,
32
,
cmap
=
plt
.
cm
.
bone
)
plt
.
subplot
(
2
,
1
,
2
);
h
=
plt
.
contourf
(
Esy_re_ax
,
Esy_im_ax
,
Dec_y
,
32
,
cmap
=
plt
.
cm
.
bone
)
############################
# Calculate BER
############################
BER
=
calc_BER
(
gp
,
E
,
[
constpts_x
,
constpts_y
],
osnr
(
E
=
E
),
Dec_x
,
Dec_y
,
Esx_re_ax
,
Esx_im_ax
,
Esy_re_ax
,
Esy_im_ax
,
5
,
LO
,
filter_f0
,
sigsampler
)
print
(
BER
)
\ No newline at end of file
examples/example_dispersion_1.py
View file @
8f28018c
...
...
@@ -30,7 +30,7 @@ E_Tx = sig_1550(esig = esig)
# Define your parameters here
T_0
=
25.0e-12
z
=
100.0e3
z
=
SSMF
.
l
D
=
17.0
beta_2
,
beta_3
=
DS2beta
(
17.0
,
0
,
gp
.
lambda0
)
...
...
@@ -45,7 +45,7 @@ E = SSMF(E = E, D = D, l = z)
# Plot Input and Output signal
plt
.
figure
(
1
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
abs
(
E_Tx
[
0
][
'E'
][
0
]),
'r'
,
label
=
'$E(0, t)$'
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
abs
(
E
[
0
][
'E'
][
0
]),
'g'
,
label
=
'$E(z=
100$
km
$
, t)
$
'
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
abs
(
E
[
0
][
'E'
][
0
]),
'g'
,
label
=
'$E(z=
'
+
SSMF
.
l
/
1e3
+
'
km, t)'
)
# Get FWHM of the input signal E_Tx
...
...
@@ -64,11 +64,11 @@ plt.annotate(s='', xy=(r1,np.max(np.abs(E[0]['E'][0]))/2), xytext=(r2,np.max(np.
plt
.
text
(
r1
+
(
r2
-
r1
)
/
2.0
,
0.01
+
np
.
max
(
np
.
abs
(
E
[
0
][
'E'
][
0
]))
/
2
,
'$T_{FWHM,1}$ = '
+
str
(
np
.
round
(
r2
-
r1
,
2
))
+
' ps'
,
fontsize
=
12
,
horizontalalignment
=
'center'
)
T_FWHM_1
=
(
r2
-
r1
)
*
1e-12
plt
.
ylabel
(
'$|E|$ a.u.'
);
plt
.
xlabel
(
'Time $t$ [ps]'
);
legend
=
plt
.
legend
(
loc
=
'upper right'
)
plt
.
show
()
L_D
=
(
T_0_plot
)
**
2
/
np
.
abs
(
beta_2
)
# Print the results
print
'Input signal 1/e-pulse width by definition : T_0 = '
,
T_0
*
1e12
,
' ps'
print
'Input signal 1/e-pulse width from plot : T_0 = '
,
T_0_plot
*
1e12
,
' ps'
print
'Input signal FWHM-pulse width from plot : T_FWHM,0 = '
,
T_FWHM_0
*
1e12
,
' ps'
print
'Output signal FWHM-pulse width from plot : T_FWHM,1 = '
,
T_FWHM_1
*
1e12
,
' ps'
print
'Calculated output FWHM-pulse width : T_FWHM,1 = '
,
T_FWHM_0
*
np
.
sqrt
(
1
+
(
z
/
L_D
)
**
2
)
*
1e12
,
' ps'
\ No newline at end of file
print
(
'Input signal 1/e-pulse width by definition : T_0 = '
,
T_0
*
1e12
,
' ps'
)
print
(
'Input signal 1/e-pulse width from plot : T_0 = '
,
T_0_plot
*
1e12
,
' ps'
)
print
(
'Input signal FWHM-pulse width from plot : T_FWHM,0 = '
,
T_FWHM_0
*
1e12
,
' ps'
)
print
(
'Output signal FWHM-pulse width from plot : T_FWHM,1 = '
,
T_FWHM_1
*
1e12
,
' ps'
)
print
(
'Calculated output FWHM-pulse width : T_FWHM,1 = '
,
T_FWHM_0
*
np
.
sqrt
(
1
+
(
z
/
L_D
)
**
2
)
*
1e12
,
' ps'
)
\ No newline at end of file
examples/example_dispersion_3.py
View file @
8f28018c
...
...
@@ -60,7 +60,7 @@ E = copy.deepcopy(E_Tx)
# Fiber transmission
E
=
SSMF
(
E
=
E
,
l
=
100e3
,
D
=
16.8
,
S
=
0.058
)
E
=
DCF
(
E
=
E
,
l
=
16.8e3
,
D
=
-
100
,
S
=
-
0.058
/
16.8
*
100
)
# For full dispersion compenstion set S = -0.058/16.8 * 100
E
=
DCF
(
E
=
E
,
l
=
16.8e3
,
D
=
-
100
,
S
=
-
0.058
/
16.8
*
100
)
# For full dispersion compens
a
tion set S = -0.058/16.8 * 100
# Filter out the channels
...
...
examples/example_filter_9.py
0 → 100644
View file @
8f28018c
##!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Import functions and libraries
import
sys
sys
.
path
.
append
(
'../'
)
from
pypho_setup
import
pypho_setup
from
pypho_bits
import
pypho_bits
from
pypho_signalsrc
import
pypho_signalsrc
from
pypho_lasmod
import
pypho_lasmod
from
pypho_oamp
import
pypho_oamp
from
pypho_osnr
import
pypho_osnr
from
pypho_functions
import
*
from
pypho_optfi
import
*
import
numpy
as
np
import
copy
import
matplotlib.pyplot
as
plt
from
scipy.interpolate
import
UnivariateSpline
# Define network elements
gp
=
pypho_setup
(
nos
=
128
,
sps
=
128
,
symbolrate
=
10e9
)
bitsrc
=
pypho_bits
(
glova
=
gp
,
nob
=
gp
.
nos
,
pattern
=
'random'
)
esigsrc
=
pypho_signalsrc
(
glova
=
gp
,
pulseshape
=
'gauss_rz'
,
fwhm
=
0.85
)
sig_1550
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
0.25
*
np
.
pi
)
osnr
=
pypho_osnr
(
glova
=
gp
)
opfilter
=
pypho_optfi
(
glova
=
gp
,
Df
=
0
,
B
=
50
,
filtype
=
'cosrolloff'
,
alpha
=
0.8
,
loss
=
0.0
)
amp
=
pypho_oamp
(
glova
=
gp
,
NF
=
6
)
# Simulation
bits
=
bitsrc
()
esig
=
esigsrc
(
bitsequence
=
bits
)
E
=
sig_1550
(
esig
=
esig
)
E
=
amp
(
E
=
E
,
Pmean
=
0
)
# Set mean power to 0 dBm
E
=
osnr
(
E
=
E
,
OSNR
=
30.0
)
# Set initial OSNR to 30 dB
E_Tx
=
copy
.
deepcopy
(
E
)
plt
.
figure
(
1
)
plt
.
plot
((
gp
.
freqax
-
gp
.
f0
)
*
1.0e-9
,
10.0
*
np
.
log10
(
E
[
0
][
'noise'
]
*
1e3
),
'r'
,
label
=
'White gaussian noise'
)
E
=
copy
.
deepcopy
(
E_Tx
)
E
=
opfilter
(
E
=
E
,
filtype
=
'cosrolloff'
)
plt
.
plot
((
gp
.
freqax
-
gp
.
f0
)
*
1.0e-9
,
10.0
*
np
.
log10
(
E
[
0
][
'noise'
]
*
1e3
),
'g'
,
label
=
'cosrolloff'
)
E
=
copy
.
deepcopy
(
E_Tx
)
E
=
opfilter
(
E
=
E
,
filtype
=
'gauss'
)
plt
.
plot
((
gp
.
freqax
-
gp
.
f0
)
*
1.0e-9
,
10.0
*
np
.
log10
(
E
[
0
][
'noise'
]
*
1e3
),
'b'
,
label
=
'gauss'
)
E
=
copy
.
deepcopy
(
E_Tx
)
E
=
opfilter
(
E
=
E
,
filtype
=
'rect'
)
plt
.
plot
((
gp
.
freqax
-
gp
.
f0
)
*
1.0e-9
,
10.0
*
np
.
log10
(
E
[
0
][
'noise'
]
*
1e3
),
'k'
,
label
=
'rect'
)
E
=
copy
.
deepcopy
(
E_Tx
)
E
=
opfilter
(
E
=
E
,
filtype
=
'gaussrolloff'
)
plt
.
plot
((
gp
.
freqax
-
gp
.
f0
)
*
1.0e-9
,
10.0
*
np
.
log10
(
E
[
0
][
'noise'
]
*
1e3
),
'm'
,
label
=
'gaussrolloff'
)
plt
.
ylabel
(
"Spectral power density [dBm/( "
+
str
(
gp
.
fres
*
1.0e-9
)
+
" GHz)]"
);
plt
.
xlabel
(
'Frequency deviation in GHz'
);
plt
.
grid
(
True
)
plt
.
legend
()
\ No newline at end of file
examples/example_generic_modulator_9.py
0 → 100644
View file @
8f28018c
##!/usr/bin/env python2
# -*- coding: utf-8 -*-
#Import functions and libraries
import
sys
sys
.
path
.
append
(
'../'
)
from
pypho_setup
import
pypho_setup
from
pypho_bits
import
pypho_bits
from
pypho_signalsrc
import
pypho_signalsrc
from
pypho_lasmod
import
pypho_lasmod
from
pypho_fiber
import
pypho_fiber
from
pypho_fiber_birefringence
import
pypho_fiber_birefringence
from
pypho_arbmod
import
pypho_arbmod
from
pypho_oamp
import
pypho_oamp
from
pypho_osnr
import
pypho_osnr
from
pypho_sample
import
pypho_sample
from
pypho_functions
import
*
import
numpy
as
np
import
copy
import
matplotlib.pyplot
as
plt
from
matplotlib
import
colors
as
mcolors
colors
=
dict
(
mcolors
.
BASE_COLORS
,
**
mcolors
.
CSS4_COLORS
)
plt
.
close
(
'all'
)
# Define network elements
gp
=
pypho_setup
(
nos
=
4
*
128
,
sps
=
128
,
symbolrate
=
10e9
)
bitsrc
=
pypho_bits
(
glova
=
gp
,
nob
=
gp
.
nos
,
pattern
=
'ones'
)
esigsrc
=
pypho_signalsrc
(
glova
=
gp
,
pulseshape
=
'gauss_rz'
,
fwhm
=
0.33
)
sig_1550
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
np
.
pi
/
4.0
)
SSMF
=
pypho_fiber
(
glova
=
gp
,
l
=
80.0e3
,
D
=
17.0
,
S
=
0
,
alpha
=
0.2
,
gamma
=
1.14
,
phi_max
=
0.01
)
DCF
=
pypho_fiber
(
glova
=
gp
,
l
=
1.0e3
,
D
=
-
SSMF
.
D
*
SSMF
.
l
*
1.0e-3
,
S
=
0
,
alpha
=
0.2e-12
,
gamma
=
1.0e-9
,
phi_max
=
10.0
)
amp
=
pypho_oamp
(
glova
=
gp
,
Pmean
=
3.0
,
NF
=
5
)
osnr
=
pypho_osnr
(
glova
=
gp
)
modulator
=
pypho_arbmod
(
glova
=
gp
)
cstdgr
=
pypho_sample
(
glova
=
gp
)
# Simulation
# Create bitpattern (enough up to 4 bits per symbol)
bits_x
=
np
.
append
(
bitsrc
(
pattern
=
'random'
),
[
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
)])
bits_y
=
np
.
append
(
bitsrc
(
pattern
=
'random'
),
[
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
),
bitsrc
(
pattern
=
'random'
)])
# Create pulsetrain
onebits
=
bitsrc
(
pattern
=
'ones'
)
esig
=
esigsrc
(
bitsequence
=
onebits
)
E_Tx
=
sig_1550
(
esig
=
esig
)
# OOK
constpts_ook
=
[(
[
0.001
,
1.0
]),
(
[
0.0
,
0.0
]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
2
)]),
(
[
x
for
x
in
range
(
0
,
2
)]),
(
[(
0
)],
[(
1
)]
)]
# 8-PSK
constpts_8psk
=
[(
[
1.0
]
*
8
),
(
[
2.0
*
np
.
pi
*
x
/
8.0
for
x
in
range
(
0
,
8
)]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
8
)]),
(
[
x
for
x
in
range
(
0
,
8
)]),
([(
0
),(
0
),(
0
)],
[(
0
),(
0
),(
1
)],
[(
0
),(
1
),(
0
)],
[(
0
),(
1
),(
1
)],
[(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
0
)],
[(
1
),(
0
),(
1
)],
[(
1
),(
0
),(
0
)],
)]
# 16-PSK
constpts_16psk
=
[(
[
1.0
]
*
16
),
(
[
2.0
*
np
.
pi
*
x
/
16.0
for
x
in
range
(
0
,
16
)]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
16
)]),
(
[
x
for
x
in
range
(
0
,
16
)]),
([(
0
),(
0
),(
0
),(
0
)],
[(
0
),(
0
),(
0
),(
1
)],
[(
0
),(
0
),(
1
),(
0
)],
[(
0
),(
0
),(
1
),(
1
)],
[(
0
),(
1
),(
0
),(
0
)],
[(
0
),(
1
),(
0
),(
1
)],
[(
0
),(
1
),(
1
),(
0
)],
[(
0
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
0
)],
[(
1
),(
1
),(
0
),(
1
)],
[(
1
),(
1
),(
0
),(
0
)],
[(
1
),(
0
),(
1
),(
1
)],
[(
1
),(
0
),(
1
),(
0
)],
[(
1
),(
0
),(
0
),(
1
)],
[(
1
),(
0
),(
0
),(
0
)]
)]
# 4-QAM
constpts_4qam
=
[(
[
1.0
]
*
4
),
(
[
2.0
*
np
.
pi
*
x
/
4.0
+
np
.
pi
/
4
for
x
in
range
(
0
,
4
)]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
4
)]),
(
[
x
for
x
in
range
(
0
,
4
)]),
(
[(
0
),(
0
)],
[(
0
),(
1
)],
[(
1
),(
1
)],
[(
1
),(
0
)]
)]
# 16-QAM
alpha
=
np
.
arctan
(
np
.
sqrt
(
1.0
)
/
3.0
)
constpts_16qam
=
[(
[
np
.
sqrt
(
3.0
**
2
+
1.0
)]
*
8
+
[
np
.
sqrt
(
2.0
)]
*
4
+
[
np
.
sqrt
(
2
*
3.0
**
2
)]
*
4
),
(
[
2.0
*
np
.
pi
*
x
/
4.0
+
alpha
for
x
in
range
(
0
,
4
)]
+
[
2.0
*
np
.
pi
*
x
/
4.0
+
np
.
pi
-
alpha
for
x
in
range
(
0
,
4
)]
+
[
2.0
*
np
.
pi
*
x
/
4.0
+
np
.
pi
/
4
for
x
in
range
(
0
,
8
)]
),
(
[
colors
.
values
()[
x
]
for
x
in
range
(
0
,
16
)]),
(
[
x
for
x
in
range
(
0
,
16
)]),
([(
0
),(
0
),(
0
),(
0
)],
[(
0
),(
0
),(
0
),(
1
)],
[(
0
),(
0
),(
1
),(
0
)],
[(
0
),(
0
),(
1
),(
1
)],
[(
0
),(
1
),(
0
),(
0
)],
[(
0
),(
1
),(
0
),(
1
)],
[(
0
),(
1
),(
1
),(
0
)],
[(
0
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
1
)],
[(
1
),(
1
),(
1
),(
0
)],
[(
1
),(
1
),(
0
),(
1
)],
[(
1
),(
1
),(
0
),(
0
)],
[(
1
),(
0
),(
1
),(
1
)],
[(
1
),(
0
),(
1
),(
0
)],
[(
1
),(
0
),(
0
),(
1
)],
[(
1
),(
0
),(
0
),(
0
)]
)]
# codes not optimized!
constpts
=
constpts_4qam
E
=
modulator
(
E
=
E_Tx
,
constpoints
=
[
constpts
,
constpts
],
bits
=
[
bits_x
,
bits_y
])
# Modulate
P0
=
4
E
=
amp
(
E
=
E
,
Pmean
=
P0
)
E
=
osnr
(
E
=
E
,
OSNR
=
58.0
)
# Set initial OSNR to 58 dB
plt
.
figure
(
1
)
cstdgr
(
E
=
E
,
constpoints
=
[
constpts
,
constpts
],
bits
=
[
bits_x
,
bits_y
],
style
=
'o,o'
)
# Plot constallation diagramme
E_Tx
=
copy
.
deepcopy
(
E
)
n_span
=
10
E
=
amp
(
E
=
E
,
Pmean
=
P0
)
for
c
in
range
(
0
,
n_span
):
# Transmission fiber
print
(
'Span: '
,
c
)
fibres
=
pypho_fiber_birefringence
.
create_pmd_fibre
(
SSMF
.
l
,
1.0e3
,
0.00
)
E
=
SSMF
(
E
=
E
,
birefarray
=
fibres
)
E
=
amp
(
E
=
E
,
Pmean
=
P0
)
for
c
in
range
(
0
,
n_span
):
# Dispersion compensation
E
=
DCF
(
E
=
E
)
plt
.
figure
(
2
)
cstdgr
(
E
=
E
,
sampletime
=
gp
.
sps
/
2
,
constpoints
=
[
constpts
,
constpts
],
bits
=
[
bits_x
,
bits_y
],
style
=
'o,o'
)
# Plot constallation diagramme
plt
.
subplot
(
2
,
1
,
1
);
plt
.
grid
(
True
);
plt
.
title
(
"Output signal"
,
loc
=
'left'
);
plt
.
subplot
(
2
,
1
,
2
);
plt
.
grid
(
True
);
plt
.
show
()
# Plot power and phase of the signal
plt
.
figure
(
3
)
plt
.
subplot
(
2
,
1
,
1
)
plt
.
title
(
"Input signal"
,
loc
=
'left'
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
abs
(
E
[
0
][
'E'
][
0
])
**
2
,
'r'
,
label
=
'$E_x(0, t)$'
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
abs
(
E
[
0
][
'E'
][
1
])
**
2
,
'g'
,
label
=
'$E_y(0, t)$'
)
plt
.
ylabel
(
'$10log |E_{x,y}|^2$'
);
plt
.
xlabel
(
'Time [ps]'
);
plt
.
grid
(
True
)
plt
.
subplot
(
2
,
1
,
2
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
angle
(
E
[
0
][
'E'
][
0
]),
'r'
)
plt
.
plot
(
gp
.
timeax
*
1.0e12
,
np
.
angle
(
E
[
0
][
'E'
][
1
]),
'g'
)
plt
.
ylabel
(
'$ \phi_{x,y} $'
);
plt
.
xlabel
(
'Time [ps]'
);
plt
.
grid
(
True
);
plt
.
legend
();
plt
.
show
()
\ No newline at end of file
examples/example_selfphasemodulation_5.py
View file @
8f28018c
...
...
@@ -20,8 +20,8 @@ import matplotlib.pyplot as plt
gp
=
pypho_setup
(
nos
=
16
,
sps
=
1
*
128
,
symbolrate
=
10e9
)
bitsrc
=
pypho_bits
(
glova
=
gp
,
nob
=
gp
.
nos
,
pattern
=
'ones'
)
esigsrc
=
pypho_signalsrc
(
glova
=
gp
,
pulseshape
=
'gauss_rz'
,
fwhm
=
0.33
)
sig
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
np
.
pi
/
8
)
SSMF
=
pypho_fiber
(
glova
=
gp
,
l
=
80e3
,
D
=
0.0
,
S
=
0.0
,
alpha
=
0.2
,
gamma
=
1.4
,
phi_max
=
.
1
)
sig
=
pypho_lasmod
(
glova
=
gp
,
power
=
0
,
Df
=
0
,
teta
=
np
.
pi
/
8
)
SSMF
=
pypho_fiber
(
glova
=
gp
,
l
=
80e3
,
D
=
0.0
,
S
=
0.0
,
alpha
=
0.2
,
gamma
=
1.4
,
phi_max
=
.
0
1
)
# Simulation
...
...
pyclo_functions.py
0 → 100644
View file @
8f28018c
#!/usr/bin/env pytsftp://104.199.77.123/var/www/html/ul/upload.php
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 2 21:26:04 2017
@author: arne
"""
import
MySQLdb
import
numpy
as
np
import
pycurl
from
StringIO
import
StringIO
########################################################################
def
mysql_get
(
sql
):
"Read data from DB"
db
=
MySQLdb
.
connect
(
host
=
"130.211.56.253"
,
user
=
"root"
,
passwd
=
"pyphodb"
,
db
=
"pypho"
)
cur
=
db
.
cursor
()
cur
.
execute
(
sql
)
db
.
close
()
return
cur
.
fetchall
()
########################################################################
def
mysql_set
(
sql
):
"Write data to DB"
db
=
MySQLdb
.
connect
(
host
=
"130.211.56.253"
,
user
=
"root"
,
passwd
=
"pyphodb"
,
db
=
"pypho"
)
cur
=
db
.
cursor
()
number_of_rows
=
cur
.
execute
(
sql
)
db
.
commit
(
)
db
.
close
()
return
number_of_rows
########################################################################
def
cloud_LoadFiles
():
"Save, zip and send all files for cloude computing"
import
json
Etmp
=
np
.
loadtxt
(
'E.txt'
).
view
(
complex
)
with
open
(
'glova.json'
)
as
json_data
:
glova
=
json
.
load
(
json_data
)
with
open
(
'link.json'
)
as
json_data
:
link
=
json
.
load
(
json_data
)
return
Etmp
,
glova
,
link
########################################################################
def
local_SaveFiles
(
filename
,
E
):
np
.
savetxt
(
filename
+
'.txt'
,
E
[
0
][
'E'
].
view
(
float
)
)
try
:
import
zlib
import
zipfile
compression
=
zipfile
.
ZIP_DEFLATED
except
:
compression
=
zipfile
.
ZIP_STORED
zf
=
zipfile
.
ZipFile
(
filename
+
".zip"
,
mode
=
'w'
)
try
:
zf
.
write
(
filename
+
'.txt'
,
compress_type
=
compression
)
finally
:
zf
.
close
()
########################################################################
def
cloud_SaveFiles
(
cid
,
filename
):
# Send files to cloud
print
(
'Sending files to master!'
)
c
=
pycurl
.
Curl
()
buffer1
=
StringIO
()
c
.
setopt
(
c
.
URL
,
'https://optical-fiber-transmission-simulation.com/ul/upload.php'
)
c
.
setopt
(
c
.
POST
,
1
)
c
.
setopt
(
c
.
HTTPPOST
,
[(
"sim_ticket"
,
cid
),
(
"filecontents"
,
(
c
.
FORM_FILE
,
filename
))])
c
.
setopt
(
c
.
WRITEDATA
,
buffer1
)
c
.
perform
()
c
.
close
()
body1
=
buffer1
.
getvalue
()
return
body1
[
0
:
74
]
\ No newline at end of file
pypho_arbmod.py
0 → 100644
View file @
8f28018c
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# pypho_arbmod.py
#
# Copyright 2018 Arne Striegler (arne.striegler@hm.edu)
#
#
#
# Modulates in arbitray constellation points
#
#
########################################################################
import
numpy
as
np
import
sys
from
pypho_functions
import
*
########################################################################
class
pypho_arbmod
(
object
):
def
__init__
(
self
,
glova
=
None
):
if
glova
==
None
:
print
(
"ERROR: pypho_armod: You must define the global variables"
)
sys
.
exit
(
"PyPho stopped!"
)
self
.
glova
=
glova
########################################################################
def
__call__
(
self
,
glova
=
None
,
E
=
None
,
constpoints
=
None
,
bits
=
None
):
if
E
==
None
:
print
(
"ERROR: pypho_armod: You must define an optical signal E"
)
sys
.
exit
(
"PyPho stopped!"
)
self
.
set
(
E
,
constpoints
,
bits
)
return
self
.
out
(
E
)
########################################################################
def
out
(
self
,
E
=
[]):
const_dec
=
[];
for
const_bin
in
np
.
asarray
(
self
.
constpoints
[
0
][
4
]
)
:
const_dec
.
append
(
const_bin
.
dot
(
2
**
np
.
arange
(
const_bin
.
size
)[::
-
1
])
)
for
symbol
in
range
(
0
,
self
.
glova
.
nos
):
b
=
self
.
bits
[
0
][
symbol
*
self
.
M
:
symbol
*
self
.
M
+
self
.
M
]
const_num
=
b
.
dot
(
2
**
np
.
arange
(
b
.
size
)[::
-
1
])
E
[
0
][
'E'
][
0
][
symbol
*
self
.
glova
.
sps
:(
symbol
+
1
)
*
self
.
glova
.
sps
]
*=
self
.
constpoints
[
0
][
0
][
const_dec
.
index
(
const_num
)]
*
np
.
exp
(
1.0j
*
self
.
constpoints
[
0
][
1
][
const_dec
.
index
(
const_num
)])
b
=
self
.
bits
[
1
][
symbol
*
self
.
M
:
symbol
*
self
.
M
+
self
.
M
]
const_num
=
b
.
dot
(
2
**
np
.
arange
(
b
.
size
)[::
-
1
])
E
[
0
][
'E'
][
1
][
symbol
*
self
.
glova
.
sps
:(
symbol
+
1
)
*
self
.
glova
.
sps
]
*=
self
.
constpoints
[
1
][
0
][
const_dec
.
index
(
const_num
)]
*
np
.
exp
(
1.0j
*
self
.
constpoints
[
1
][
1
][
const_dec
.
index
(
const_num
)])
return
E
########################################################################
def
set
(
self
,
E
=
[],
constpoints
=
None
,
bits
=
None
):
if
constpoints
==
None
and
self
.
constpoints
==
None
:
print
(
"ERROR: pypho_armod: No constellation points definded"
)
sys
.
exit
(
"PyPho stopped!"
)
elif
constpoints
!=
None
: