WIP büro

This commit is contained in:
Silas Oettinghaus
2023-05-26 11:06:39 +02:00
parent 8b2129ac03
commit b640c013cb
20 changed files with 192 additions and 52 deletions

151
Classes/02_optical/EML.m Normal file
View File

@@ -0,0 +1,151 @@
classdef EML
%EML External Modulated Laser
% Detailed explanation goes here
properties
%class input objms
mode
fsimu %in Hz
lambda %in nm
power %in dBm
linewidth %in Hz
ampl_imbal
pha_imbal
bias
u_pi
randomkey
%on instance creation
field
noisefactor
phase %eigentlich nur wichtig wenn man mehrere blöcke durchsimuliert...
real_factor
imag_factor
%during simulation
signal_len
end
methods
function obj = EML(options)
%EML Construct an instance of this class
% Detailed explanation goes here
arguments
options.mode eml_mode = eml_mode.im_cosinus ;
options.fsimu;
options.lambda;
options.power;
options.linewidth = 0;
options.ampl_imbal = 0;
options.pha_imbal = 0;
options.bias;
options.u_pi;
options.randomkey = 2023;
end
fn = fieldnames(options);
for l = 1:numel(fn)
obj.(fn{l}) = options.(fn{l});
end
obj.field=sqrt(10^(obj.power/10-3)); %dbm to sqrt(mw)
obj.noisefactor=sqrt(2*pi*obj.linewidth/obj.fsimu);
obj.phase=0;
if obj.mode==4 || obj.mode==5
obj.real_factor=(1+obj.ampl_imbal/2)*exp(1i*obj.pha_imbal/2);
obj.imag_factor=(1-obj.ampl_imbal/2)*exp(1i*(pi/2-obj.pha_imbal/2));
end
end
function signalclass_out = process(obj,signalclass_in)
% actual processing of the signal (steps 1. - 3.)
signalclass_in.signal = obj.process_(signalclass_in.signal);
% cast the inform. signal to electrical signal
signalclass_in = Opticalsignal(signalclass_in,"fs",obj.fsimu,"logbook",signalclass_in.logbook,"lambda",obj.lambda*1e-9,"nase",0);
% append to logbook
lbdesc = [num2str(obj.lambda),' nm Laser with ',num2str(obj.power),' dBm P_out. Linew.=',num2str(obj.linewidth*1e-6),' MHz. Modulation mode: ',char(obj.mode) ];
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output
signalclass_out = signalclass_in;
end
function [opt_out,obj] = process_(obj,elec_in)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
%needed later
obj.signal_len = length(elec_in);
% generate phase noise of laser
% scale with signal energy in sqrt(mw)
if obj.linewidth ~= 0
ph_noi = obj.createPhaseNoise;
laserfield = obj.field.*exp(1i*ph_noi);
%remember phase (! you need to receive the altered eml object in you sim program !)
obj.phase = ph_noi(end);
else
laserfield = obj.field;
end
%modulate the laserfield with the electrical signal
opt_out = obj.externalmodulation(laserfield,elec_in);
end
function noi = createPhaseNoise(obj)
%create random vector
noi = randn(obj.signal_len,1);
%scale with noisefactor
noi = noi * obj.noisefactor;
%cumsum to accumulate noise over time vector
noi = cumsum(noi);
%add phase from previous block/ loop of simulation
noi = noi + obj.phase;
end
function modulated_laserfield = externalmodulation(obj,laserfield,electrical_in)
switch obj.mode
case 1 % linear IM
modulated_laserfield = laserfield.*sqrt(real(electrical_in + obj.bias)/obj.u_pi);
case 2 % IM with hMZM function
modulated_laserfield = laserfield.*cos(pi/2*(real(electrical_in)+obj.bias)/obj.u_pi);
case 3 % PMsi
modulated_laserfield = laserfield.*exp(1i*pi*real(electrical_in)/obj.u_pi);
case 4 % linear IQ-Modulator
if obj.ampl_imbal ==0 && obj.pha_imbal == 0
% No IQ Imbalance
modulated_laserfield=laserfield.*electrical_in/obj.u_pi;
else
% with IQ Imbalance
modulated_laserfield = laserfield.*(real(electrical_in)*obj.real_factor/obj.u_pi...
+imag(electrical_in)*obj.imag_factor/obj.u_pi);
end
case 5 % IQ-Modulator with cosine function
modulated_laserfield = laserfield/sqrt(2).*(cos(pi/2*(real(electrical_in)+obj.bias)/obj.u_pi)*obj.real_factor...
+cos(pi/2*(imag(electrical_in)+obj.bias)/obj.u_pi)*obj.imag_factor);
end
end
end
end

169
Classes/02_optical/Fiber.m Normal file
View File

@@ -0,0 +1,169 @@
classdef Fiber
%FIBER Summary of this class goes here
% Detailed explanation goes here
properties
fsimu
fiber_length
alpha
D
Dslope
lambda0
gamma
dphimax
b2
b3
alpha_lin
linstep
end
methods
function obj = Fiber(options)
%FIBER Construct an instance of this class
% Detailed explanation goes here
arguments
options.fsimu
options.fiber_length = 0
options.alpha = 0.2
options.D = 17
options.Dslope = 0.06
options.lambda0 = 1550
options.gamma = 0.0013
options.dphimax = 5e-3
end
obj.fsimu = options.fsimu;
obj.fiber_length = options.fiber_length*1000; %km
obj.alpha = options.alpha;
obj.D = options.D*1e-6;
obj.Dslope = options.Dslope*1e3;
obj.lambda0 = options.lambda0*1e-9;
obj.gamma = options.gamma;
obj.dphimax = options.dphimax;
obj.b2 = -obj.D*obj.lambda0^2/(2*pi*Constant.LightSpeed);
obj.b3 = ((obj.lambda0.^2/(2*pi*Constant.LightSpeed)).^2*obj.Dslope);
obj.alpha_lin = obj.alpha/10*log(10)/1000;
end
function signalclass_out = process(obj,signalclass_in)
% actual processing of the signal (steps 1. - 3.)
signalclass_in.signal = obj.process_(signalclass_in.signal);
% append to logbook
lbdesc = 'Fiber ';
signalclass_in = signalclass_in.logbookentry(lbdesc);
% write to output
signalclass_out = signalclass_in;
end
function opt_out = process_(obj,opt_in)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
N = length(opt_in);
faxis = linspace(-obj.fsimu/2,obj.fsimu/2,N+1);
faxis = ifftshift(faxis(:,1:end-1));
faxis = faxis';
obj.linstep = -obj.alpha_lin/2 - 2*1j*pi^2*obj.b2*faxis.^2 - 4/3*1j*pi^3*obj.b3*faxis.^3;
if obj.gamma ~= 0
opt_out = obj.NLSE(opt_in);
else
opt_out = ifft(fft(opt_in).*exp(obj.linstep*obj.fiber_length)); % only one linear step
end
%attenuate nase
end
function [yout] = NLSE(obj, xin)
maxPow = obj.gamma.*max(abs(xin).^2);
Leff = obj.dphimax / maxPow ;
dz = Leff;
z_prop = 0;
yout = fft(xin);
yout = ((yout).*exp(obj.linstep*dz/2));
while true
yout = ifft(yout);
Leff = dz;
power = abs(yout).^2;
Hnl = exp( -1j*obj.gamma*power*Leff);
yout = yout .* Hnl;
z_prop = z_prop + dz;
maxPow = obj.gamma*max(abs(yout).^2);
Leff = obj.dphimax/maxPow;
dz_new = Leff;
if z_prop + dz_new > obj.fiber_length
dz_new = obj.fiber_length - z_prop;
break
end
yout = fft(yout);
yout = ((yout).*exp(obj.linstep*(dz/2+dz_new/2)));
dz = dz_new;
end
yout = fft(yout);
yout = ((yout).*exp(obj.linstep*(dz/2+dz_new/2)));
yout = ifft(yout);
Leff = dz;
power = abs(yout).^2;
Hnl = exp( -1j*obj.gamma*power*Leff);
yout = yout .* Hnl;
yout = fft(yout);
yout = ((yout).*exp(obj.linstep*(dz/2)));
yout = ifft(yout);
end
end
end