Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions jupyter notebooks/1. Transmissores ópticos.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,20 @@ def genConst(M, constType, plotBits):
plt.ylim(1.25*min(symbTx.real),1.25*max(symbTx.real));
plt.vlines(0, 1.25*min(symbTx.real), 1.25*max(symbTx.real))
plt.hlines(0, 1.25*min(symbTx.real), 1.25*max(symbTx.real))

if M>64:
plt.plot(symbTx.real, symbTx.imag,'o', markersize=4);
else:
plt.plot(symbTx.real, symbTx.imag,'o', markersize=10);

plt.title('Constelação '+str(M)+'-'+constType.upper());

if plotBits:
if M>=64:
fontSize = 6
else:
fontSize = 12

plt.title(f'Constelação {str(M)}-' + constType.upper());

if plotBits:
fontSize = 6 if M>=64 else 12
for ind, symb in enumerate(constSymb):
bitMap[ind,:]
plt.annotate(str(bitMap[ind,:])[1:-1:2], xy = (symb.real-0.05, symb.imag+0.15), size=fontSize)

Comment on lines -176 to +189
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function genConst refactored with the following changes:

except:
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@
σ2_s = 2*q*(Ip + Id)*B # variância
μ = 0 # média

σ = np.sqrt(σ2_s)
σ = np.sqrt(σ2_s)
Is = normal(μ, σ, Namostras)

# plotas as primeiras 1000 amostras
plt.plot(Is[0:1000],linewidth = 0.8);
plt.plot(Is[:1000], linewidth = 0.8);
Comment on lines -157 to +161
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 157-161 refactored with the following changes:

plt.xlim(0,1000)
plt.ylabel('Is')
plt.xlabel('amostra')
Expand Down
20 changes: 8 additions & 12 deletions jupyter notebooks/Sistemas coerentes.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,15 @@ def hybrid_2x4_90(E1, E2):

M = Matrix([[C_3dB, zeros(2)],
[zeros(2), C_3dB]])

U = Matrix([[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, j]])

Ei = Matrix([[E1],[0],[0],[E2]]) # vetor 4x1

Eo = M*U*M*Ei

return Eo

return M*U*M*Ei
Comment on lines -301 to +309
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hybrid_2x4_90 refactored with the following changes:


# fotodetector balanceado
def bpd(E1, E2, R=1):
Expand Down Expand Up @@ -406,19 +404,17 @@ def hybrid_2x4_90deg(E1, E2):
:return: hybrid outputs
'''
assert E1.size == E2.size, 'E1 and E2 need to have the same size'

# optical hybrid transfer matrix
T = np.array([[ 1/2, 1j/2, 1j/2, -1/2],
[ 1j/2, -1/2, 1/2, 1j/2],
[ 1j/2, 1/2, -1j/2, -1/2],
[-1/2, 1j/2, -1/2, 1j/2]])

Ei = np.array([E1, np.zeros((E1.size,)),
np.zeros((E1.size,)), E2])

Eo = T@Ei

return Eo

return T@Ei
Comment on lines -409 to +417
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hybrid_2x4_90deg refactored with the following changes:


def coherentReceiver(Es, Elo, Rd=1):
'''
Expand Down
39 changes: 19 additions & 20 deletions jupyter notebooks/Split-Step Fourier Method (SSFM).py
Original file line number Diff line number Diff line change
Expand Up @@ -70,52 +70,51 @@ def manakovSSF(Ei, hz, Lspan, Ltotal, alpha, gamma, D, Fc, Fs):

Ex = Ei[:,0]
Ey = Ei[:,1]

c = 299792458 # speed of light (vacuum)
c_kms = c/1e3
λ = c_kms/Fc
α = alpha/(10*np.log10(np.exp(1)))
β2 = -(D*λ**2)/(2*np.pi*c_kms)
γ = gamma

Nfft = len(Ex)

ω = 2*np.pi*Fs*fftfreq(Nfft)

Nspans = int(np.floor(Ltotal/Lspan))
Nsteps = int(np.floor(Lspan/hz))

Ex = fft(Ex) #Pol. X
Ey = fft(Ey) #Pol. Y

linOperator = np.exp(-(α/2)*(hz/2) + 1j*(β2/2)*(ω**2)*(hz/2))

for spanN in tqdm(range(1, Nspans+1)):
for stepN in range(1, Nsteps+1):


for _ in tqdm(range(1, Nspans+1)):
for _ in range(1, Nsteps+1):
Comment on lines -73 to +94
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function manakovSSF refactored with the following changes:

# First linear step (frequency domain)
Ex = Ex*linOperator
Ey = Ey*linOperator

# Nonlinear step (time domain)
Ex = ifft(Ex);
Ey = ifft(Ey);

Ex = Ex*np.exp(1j*γ*8/9*(Ex*np.conj(Ex) + Ey*np.conj(Ey))*hz)
Ey = Ey*np.exp(1j*γ*8/9*(Ex*np.conj(Ex) + Ey*np.conj(Ey))*hz)

# Second linear step (frequency domain)
Ex = fft(Ex);
Ey = fft(Ey);
Ex = Ex*linOperator
Ey = Ey*linOperator

Ex = Ex*np.exp(α*Nsteps*hz)
Ey = Ey*np.exp(α*Nsteps*hz)

Ex = ifft(Ex)
Ey = ifft(Ey)

return Ex, Ey

def edfa_lin(signal, gain, nf, fc, fs):
Expand Down Expand Up @@ -207,7 +206,7 @@ def filterNoDelay(h, x):

# generate random bits
np.random.seed(33)
bits_x = np.random.randint(2, size=3*2**14)
bits_x = np.random.randint(2, size=3*2**14)
Comment on lines -210 to +209
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 210-323 refactored with the following changes:

np.random.seed(23)
bits_y = np.random.randint(2, size=3*2**14)

Expand All @@ -228,7 +227,7 @@ def filterNoDelay(h, x):

# pulse shaping
tindex, rrcFilter = rrcosfilter(N, alphaRRC, Ts, Fa)
sig_x = filterNoDelay(rrcFilter, symbolsUp_x)
sig_x = filterNoDelay(rrcFilter, symbolsUp_x)
sig_y = filterNoDelay(rrcFilter, symbolsUp_y)

sig_x = np.sqrt(P0/2)*sig_x/np.sqrt(signal_power(sig_x))
Expand Down Expand Up @@ -259,7 +258,7 @@ def filterNoDelay(h, x):
sigRx = sigRx/np.sqrt(signal_power(sigRx))

# matched filter
sigRx = filterNoDelay(rrcFilter, sigRx)
sigRx = filterNoDelay(rrcFilter, sigRx)
sigRx = sigRx/SpS

# downsampling to one sample per symbol
Expand Down Expand Up @@ -290,7 +289,7 @@ def filterNoDelay(h, x):
BERtheory = theoryBER(M, EbN0dB,'qam')

# print results
print('EbN0: %3.2f dB, EbN0_est: %3.2f dB,\nBERtheory: %3.1e, BER: %3.1e ' %(EbN0dB, EbN0dB_est, BERtheory, BER))
print('EbN0: %3.2f dB, EbN0_est: %3.2f dB,\nBERtheory: %3.1e, BER: %3.1e ' %(EbN0dB, EbN0dB_est, BERtheory, BER))
print('Total of bits counted: ', ERR.size)

# plot constellations
Expand All @@ -306,7 +305,7 @@ def filterNoDelay(h, x):
# +
from scipy.stats.kde import gaussian_kde

y = (sigRx[0:30000]).real
y = sigRx[:30000].real
x = np.arange(0,y.size,1) % 24

k = gaussian_kde(np.vstack([x, y]))
Expand All @@ -319,8 +318,8 @@ def filterNoDelay(h, x):
# +
from scipy.stats.kde import gaussian_kde

y = (symbRx[0:30000]).real
x = (symbRx[0:30000]).imag
y = symbRx[:30000].real
x = symbRx[:30000].imag

k = gaussian_kde(np.vstack([x, y]))
k.set_bandwidth(bw_method=k.factor/2)
Expand Down