Minimal Working - seems too good?!
This commit is contained in:
244
comm_tb.m
244
comm_tb.m
@@ -1,9 +1,11 @@
|
||||
O = 14; %order of prbs
|
||||
clear all
|
||||
|
||||
O = 17; %order of prbs
|
||||
N = 2^(O-1); %length of prbs
|
||||
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
||||
|
||||
% Modulation
|
||||
M = 4;
|
||||
M = 4; %PAM-M
|
||||
bitpattern = zeros(N,log2(M));
|
||||
|
||||
% Symbol Rate
|
||||
@@ -17,168 +19,152 @@ fadc = 256e9;
|
||||
% Simulation frequency in "analog domain"
|
||||
fsimu = kover * fdac ;
|
||||
|
||||
%SIMULATE
|
||||
[settings, button] = settingsdlg(...
|
||||
'Description' , ['This dialog will set the ', ...
|
||||
'parameters used by FMINCON()'], ...
|
||||
'title' , 'FMINCON() options', ...
|
||||
'separator' , 'Unconstrained/General', ...
|
||||
{'This is a checkbox'; 'Check'} , [false, false],...
|
||||
{'Tolerance X';'TolX'} , 1e-6, ...
|
||||
{'Tolerance on Function';'TolFun'} , 1e-6, ...
|
||||
'Algorithm' , {'active-set','interior-point'}, ...
|
||||
'separator' , 'Constrained', ...
|
||||
{'Tolerance on Constraints';'TolCon'}, 1e-6);
|
||||
|
||||
for i = 1:log2(M)
|
||||
[bitpattern(:,i),seed] = prbs(O,N,seed);
|
||||
end
|
||||
%CONSTRUCTION
|
||||
pam_mapper = PAMmapper(M,0);
|
||||
|
||||
Bits = Informationsignal(bitpattern);
|
||||
awg = AWG('preset','M8196A','fdac',fdac,'kover',kover,'lpf_active',0);
|
||||
|
||||
Bits.signal = pam_mapping(Bits.signal,M,0);
|
||||
|
||||
Bits.signal = applyPulseShaping(Bits.signal,fsym,fdac);
|
||||
|
||||
|
||||
awg = AWG('preset','M8196A','fdac',fdac,'kover',kover,'lpf_active',1);
|
||||
awgSignal = awg.process_channel(Bits.signal);
|
||||
|
||||
fil = Filter('filtdegree',4,"f_cutoff",50e9,"fsamp",fdac,"filterType",filtertypes.bessel_bilin);
|
||||
filtered = fil.process(awgSignal);
|
||||
fil_tx = Filter('filtdegree',1,"f_cutoff",50e9,"fsamp",fdac,"filterType",filtertypes.bessel_bilin);
|
||||
|
||||
u_pi = 3.5;
|
||||
vbias = (0.5*u_pi)-u_pi;
|
||||
extmodlaser = EML("mode",emlmodes.im_cosinus,"power",10,"fsimu",fsimu,"lambda",1550,"bias",vbias,"u_pi",u_pi,"linewidth",1000000);
|
||||
laserfield = extmodlaser.process(filtered);
|
||||
extmodlaser = EML("mode",emlmodes.im_cosinus,"power",10,"fsimu",fsimu,"lambda",1550,"bias",vbias,"u_pi",u_pi,"linewidth",0);
|
||||
|
||||
att = Amplifier("amplification_db",10,"amp_mode","gain","type","ideal","saturation_mode",0,'saturation_power',10);
|
||||
att_out = att.process(laserfield);
|
||||
amp = Amplifier("amplification_db",10,"amp_mode","gain","type","ideal","saturation_mode",0,'saturation_power',10);
|
||||
|
||||
fib = Fiber("fsimu",fdac*kover,"fiber_length",0,"alpha",0.2,"D",17,"lambda0",1550);
|
||||
fib_out = fib.process(att_out);
|
||||
fib = Fiber("fsimu",fdac*kover,"fiber_length",2,"alpha",0.2,"D",17,"lambda0",1550);
|
||||
|
||||
phdiode = Photodiode("fsimu",fdac*kover,"dark_current",2e-08,"responsivity",1,"temperature",20);
|
||||
phdiod_out = phdiode.process(fib_out);
|
||||
|
||||
fil = Filter('filtdegree',4,"f_cutoff",70e9,"fsamp",fdac,"filterType",filtertypes.bessel_bilin);
|
||||
phdiod_out2 = fil.process(phdiod_out);
|
||||
|
||||
fil_diode = Filter('filtdegree',4,"f_cutoff",70e9,"fsamp",fdac,"filterType",filtertypes.bessel_bilin);
|
||||
|
||||
scp = Scope("fsimu",fdac*kover,"fadc",fadc,...
|
||||
"delay",0,"fixed_delay",0,"lpf_bw",120e9,"filtertype",filtertypes.bessel_inp,...
|
||||
"samplingdelay",0,"rand_samplingdelay",0,"freq_offset",0,"samp_jitter",0,...
|
||||
"adcresolution",6,"quantbuffer",0.1);
|
||||
|
||||
scope_out = scp.process(phdiod_out2);
|
||||
eq = EQ("K",2,"plottrain",0,"plotfinal",1,"training_length",2048,"Ne",[25,5,5],"Nb",[2,0,0],"training_loops",5,"DCmu",0.005,"DDmu",[0.0004 0.0004 0.0004 0.0004 ],"DFEmu",0.005,"FFEmu",0,"thres",[0.005 0.004 0.0005 ]);
|
||||
|
||||
resample_out = resample(scope_out,fsym,fadc);
|
||||
%SIMULATE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
figure;
|
||||
hold on
|
||||
plot( nmlze(resample(shapedData,fadc,fdac)),'DisplayName','shapedData Data');
|
||||
plot( nmlze(resample(awgSignal,fadc,fdac*kover)),'DisplayName','AWG Data');
|
||||
plot( nmlze(scope_out),'DisplayName','scope out out');
|
||||
hold off
|
||||
|
||||
|
||||
|
||||
|
||||
% figure;
|
||||
% hold on
|
||||
% plot(awgSignal,'DisplayName','skew 0');
|
||||
% plot(filtered,'DisplayName','filtered');
|
||||
% plot(abs(laserfield),'DisplayName','laser');
|
||||
% plot(abs(att_out),'DisplayName','att_out');
|
||||
% plot(abs(fib_out),'DisplayName','fiber_out');
|
||||
% plot(abs(phdiod_out),'DisplayName','photo diode out');
|
||||
% hold off
|
||||
|
||||
% figure;
|
||||
% hold on
|
||||
% plot(nmlze(pamData),'DisplayName','PAM Data');
|
||||
% plot(nmlze(resample_out),'DisplayName','system out');
|
||||
% hold off
|
||||
|
||||
|
||||
function y = nmlze(x)
|
||||
y = (x-min(x)) / max((x-min(x)));
|
||||
% INFORMATION SIGNAL
|
||||
for i = 1:log2(M)
|
||||
[bitpattern(:,i),seed] = prbs(O,N,seed);
|
||||
end
|
||||
|
||||
function pam_sig = pam_mapping(bitpattern, M, unipolar)
|
||||
X = Informationsignal(bitpattern);
|
||||
|
||||
switch log2(M)
|
||||
case 1
|
||||
% 2-ASK: BPSK / OOK
|
||||
pam_sig=bitpattern(:,1);
|
||||
PAMSIG = pam_mapper.map(X);
|
||||
|
||||
if unipolar==0
|
||||
pam_sig=2*pam_sig-1;
|
||||
end
|
||||
X.signal = applyPulseShaping(PAMSIG.signal,fsym,fdac);
|
||||
|
||||
case 2
|
||||
% 4-ASK:
|
||||
pam_sig=2*bitpattern(:,1)+(bitpattern(:,1)==bitpattern(:,2));
|
||||
% ELECTRICAL DOMAIN
|
||||
X = awg.process(X);
|
||||
|
||||
if unipolar==0
|
||||
pam_sig=2*pam_sig-3;
|
||||
end
|
||||
X = fil_tx.process(X);
|
||||
|
||||
% OPTICAL DOMAIN
|
||||
X = extmodlaser.process(X);
|
||||
|
||||
X = amp.process(X);
|
||||
|
||||
X = fib.process(X);
|
||||
|
||||
X = phdiode.process(X);
|
||||
|
||||
X = fil_diode.process(X);
|
||||
|
||||
% ELECTRICAL DOMAIN
|
||||
X = scp.process(X);
|
||||
|
||||
X = X.resample("fs_out",2*fsym,"fs_in",fadc);
|
||||
|
||||
|
||||
case 3
|
||||
% 8-ASK:
|
||||
x1 = bitpattern(:,1);
|
||||
x2 = (bitpattern(:,1)==bitpattern(:,3));
|
||||
x3 = x2~=bitpattern(:,2);
|
||||
% INFORMATION SIGNAL
|
||||
X = eq.process(X,PAMSIG);
|
||||
|
||||
pam_sig = 4*x1 + 2*x2 + x3;
|
||||
X = pam_mapper.demap(X);
|
||||
|
||||
if unipolar==0
|
||||
pam_sig=2*pam_sig-7;
|
||||
end
|
||||
% BER
|
||||
[bits,errors,BER] = calc_ber(X.signal(:,10000:end-20),bitpattern(10000:end-20,:)',0);
|
||||
|
||||
|
||||
case 4
|
||||
% 16-ASK:
|
||||
x1 = bitpattern(:,1);
|
||||
x2 = (bitpattern(:,1)==bitpattern(:,4));
|
||||
x3 = x2~=bitpattern(:,3);
|
||||
x4 = x3~=bitpattern(:,2);
|
||||
|
||||
pam_sig = 8*x1 + 4*x2 + 2*x3 + x4;
|
||||
|
||||
if unipolar==0
|
||||
pam_sig=2*pam_sig-15;
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
disp(['BER: ', sprintf('%2E',BER)]);
|
||||
disp(X.logbook);
|
||||
|
||||
function yout = applyPulseShaping(xin,fsym,fdac)
|
||||
|
||||
if ~rem(fdac,fsym)
|
||||
%ist ein Vielfaches
|
||||
sps = fdac / fsym;
|
||||
up = sps;
|
||||
dn = 1;
|
||||
else
|
||||
%ist kein Vielfaches
|
||||
up = fdac / gcd(fdac, fsym);
|
||||
dn = fsym / gcd(fdac, fsym);
|
||||
sps= up;
|
||||
end
|
||||
if ~rem(fdac,fsym)
|
||||
%ist ein Vielfaches
|
||||
sps = fdac / fsym;
|
||||
up = sps;
|
||||
dn = 1;
|
||||
else
|
||||
%ist kein Vielfaches
|
||||
up = fdac / gcd(fdac, fsym);
|
||||
dn = fsym / gcd(fdac, fsym);
|
||||
sps= up;
|
||||
end
|
||||
|
||||
%Bau das Filter (hier rrc)
|
||||
racos_len = 2048;
|
||||
alpha = 0.1;
|
||||
h = rcosdesign(alpha,racos_len,sps);
|
||||
|
||||
%Apply Filter using Matlab build in fctn.
|
||||
yout = upfirdn(xin,h,up,dn);
|
||||
|
||||
%cut signal, which is longer due to fir filter
|
||||
st = up/dn*racos_len/2; %we need to cut y_out
|
||||
en = st + (length(xin)*up/dn) -1;
|
||||
%Bau das Filter (hier rrc)
|
||||
racos_len = 2048;
|
||||
alpha = 0.1;
|
||||
h = rcosdesign(alpha,racos_len,sps);
|
||||
|
||||
yout = yout(st:en);
|
||||
%Apply Filter using Matlab build in fctn.
|
||||
yout = upfirdn(xin,h,up,dn);
|
||||
|
||||
%Check output integrity
|
||||
if (up/dn * length(xin)) ~= length(yout)
|
||||
warning('Check signal length after pulse shaping');
|
||||
end
|
||||
%cut signal, which is longer due to fir filter
|
||||
st = round(up/dn*racos_len/2); %we need to cut y_out
|
||||
en = round(st + (length(xin)*up/dn) -1);
|
||||
|
||||
yout = yout(st:en);
|
||||
|
||||
%Check output integrity
|
||||
if round(up/dn * length(xin)) ~= length(yout)
|
||||
warning('Check signal length after pulse shaping');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function [bits,errors,BER] = calc_ber(data_in,data_ref,skip)
|
||||
|
||||
data_ref=logical(data_ref);
|
||||
data_in = logical(data_in);
|
||||
bits = 0;
|
||||
errors=0;
|
||||
|
||||
data_ref_overlap=zeros(size(data_ref,1),skip+(length(data_ref)-size(data_in,2)));
|
||||
data_ref_pointer=0;
|
||||
% Determine BER
|
||||
|
||||
bits = bits+size(data_in,2)-skip;
|
||||
try
|
||||
errors = sum( data_in(:,skip+1:end,:) ~= data_ref(:,skip+1:end,:),2 );
|
||||
catch
|
||||
%warning('BER calculation not optimal: Arrays have incompatible sizes for this operation.')
|
||||
errors = NaN;
|
||||
end
|
||||
try
|
||||
errors = sum( data_in(:,skip+1:end,:) ~= data_ref(:,skip+1:end-1,:),2 );
|
||||
end
|
||||
try
|
||||
errors = sum( data_in(:,skip+1:end,:) ~= data_ref(:,skip+1:end-2,:),2 );
|
||||
end
|
||||
|
||||
BER = sum(errors)/sum(bits);
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user