DB and 400G and minor changes

This commit is contained in:
Silas Oettinghaus
2024-10-07 08:22:28 +02:00
parent 179a7f9682
commit da3be973e2
20 changed files with 578 additions and 142 deletions

View File

@@ -1,61 +1,68 @@
classdef PAMmapper_test < matlab.unittest.TestCase
properties
Digi_Mod
Tx_bits
Rx_bits
% M = 8; % Modulation order
fsym = 112e9; % Symbol rate
Tx_bits
PAMmapper
end
properties (MethodSetupParameter)
% Define method-level parameters for PRBS and bit pattern
useprbs = struct('false', 0, 'true', 1); % variations: {0, 1}
M = struct('M2', 2, 'M4', 4, 'M6', 6, 'M8', 8); % variations: {2, 4, 6, 8}
O = struct('O10', 10, 'O15', 15, 'O17', 17); % variations: {10, 15, 17}
end
properties (TestParameter)
M = {4,6,8};
% Define test-level parameters for M and O
end
methods (TestMethodSetup)
function setupModulation(testCase)
% Setup PRBS and bit pattern for the test case
O = 10; % Order of PRBS
function setupModulation(testCase, useprbs, M, O)
% Setup PRBS and bit pattern for the test case using parameters
% Setup PRBS parameters
N = 2^(O-1); % Length of PRBS
useprbs = 1; % Flag to use PRBS
randkey = 1; % Random key for random stream
[~, seed] = prbs(O, 1); % Initialize first seed of PRBS
bitpattern = [];
if useprbs
for i = 1:log2(testCase.M)
for i = 1:log2(M)
[bitpattern(:, i), seed] = prbs(O, N, seed);
end
else
s = RandStream('twister', 'Seed', randkey);
for i = 1:log2(testCase.M)
for i = 1:log2(M)
bitpattern(:, i) = randi(s, [0 1], N, 1);
end
end
if testCase.M == 6
if M == 6
bitpattern = reshape(bitpattern, [], 1);
bitpattern = bitpattern(1:end-mod(length(bitpattern), 5));
end
testCase.Tx_bits = Informationsignal(bitpattern);
testCase.Digi_Mod = PAMmapper(testCase.M, 0);
testCase.PAMmapper = PAMmapper(M, 0);
end
end
methods (Test)
function testBackToBackMapping(testCase)
methods (Test, ParameterCombination = 'sequential')
% Test with sequential combination of parameters
function testBackToBackMapping(testCase, M, useprbs, O)
% Test Bits -> Symbols -> Bits (Back-to-Back Mapping)
% Map bits to symbols
Symbols = testCase.Digi_Mod.map(testCase.Tx_bits);
Symbols = testCase.PAMmapper.map(testCase.Tx_bits);
% Demap symbols back to bits
testCase.Rx_bits = testCase.Digi_Mod.demap(Symbols);
Rx_bits = testCase.PAMmapper.demap(Symbols);
% Validate BER is zero
[~, error_num, ber, ~] = calc_ber(testCase.Tx_bits.signal, testCase.Rx_bits.signal, ...
[~, error_num, ber, ~] = calc_ber(testCase.Tx_bits.signal, Rx_bits.signal, ...
"skip_front", 0, "skip_end", 0, "returnErrorLocation", 1);
% Assert that BER is zero
@@ -63,5 +70,5 @@ classdef PAMmapper_test < matlab.unittest.TestCase
testCase.verifyEqual(error_num, 0, 'No errors should occur in the mapping process');
end
end
end

View File

@@ -1,11 +1,108 @@
classdef Duobinary_test < matlab.unittest.TestCase
% Test class for Duobinary
properties
%genereal properties of the test
ber
errors
errorIndice
numbits
numsymbols
end
properties (MethodSetupParameter)
% Define method-level parameters for PRBS and bit pattern
% i.e.: useprbs = {0,1};
useprbs = struct('true', 1,'false', 0); % variations: {0, 1}
M = struct('M2', 2, 'M4', 4, 'M6', 6, 'M8', 8); % variations: {2, 4, 6, 8}
O = struct('O10', 10,'O11', 11,'O12', 12,'O13', 13, 'O15', 15, 'O17', 17); % variations: {10, 15, 17}
end
properties (TestParameter)
% Define test-level parameters for M and O
end
methods (TestMethodSetup, ParameterCombination = 'pairwise')
function setupTest(testCase, useprbs, M, O)
randkey = 1;
datarate = 448e9;
fsym = round(datarate / log2(M)) ;
%%%%% PRBS Generation in correct shape for Modulation Format %%%%%%
N = 2^O; %length of prbs
[~,seed] = prbs(O,1); %initialize first seed of prbs
bitpattern=[];
if useprbs
for i = 1:log2(M)
[bitpattern(:,i),seed] = prbs(O,N,seed);
end
else
s = RandStream('twister','Seed',randkey);
for i = 1:log2(M)
bitpattern(:,i) = randi(s,[0 1], N, 1);
end
end
if M == 6
bitpattern = reshape(bitpattern,[],1);
bitpattern = bitpattern(1:end-mod(length(bitpattern),5));
end
testCase.numbits = length(bitpattern);
Tx_bits = Informationsignal(bitpattern);
Symbols_tx = PAMmapper(M,0).map(Tx_bits);
Symbols_tx.fs = fsym;
testCase.numsymbols = length(Symbols_tx);
Symbols_tx = PAMmapper(M,0).map(Tx_bits);
Symbols_tx.fs = fsym;
Symbols = Duobinary().precode(Symbols_tx);
Symbols = Duobinary().encode(Symbols);
Symbols = Duobinary().decode(Symbols);
Rx_bits = PAMmapper(M,0).demap(Symbols);
[bits,testCase.errors,testCase.ber,testCase.errorIndice] = calc_ber(Tx_bits.signal,Rx_bits.signal,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
end
end
methods (Test)
function testExample(testCase)
% Example test case for Duobinary
% Add your test code here
testCase.verifyTrue(true);
% Test with sequential combination of parameters
function checkBerZero(testCase, useprbs, M, O)
% Assert that BER is zero
testCase.verifyEqual(testCase.ber, 0, ['Numer of Errors is not zero, found ',num2str(testCase.errors), ' errors at position ', num2str(testCase.errorIndice),' out of ', num2str(2^O)]);
end
function checkBerCloseToZero(testCase, useprbs, M, O)
testCase.verifyLessThan(testCase.errors, 5, ['Found more than 5 errors. Found ',num2str(testCase.errors),' errors.']);
% if ~isempty(testCase.errorIndice)
% testCase.verifyEqual(testCase.errorIndice, 2^O , ['Error is NOT at the End but at: ', num2str(testCase.errorIndice),' of ', num2str(2^O)]);
% testCase.verifyEqual(testCase.errorIndice,1, ['Error is NOT at the Beginning but at: ', num2str(testCase.errorIndice),' of ', num2str(2^O)]);
% end
end
function checkSystemFailure(testCase, useprbs, M, O)
testCase.verifyLessThan(testCase.ber, 0.1, ['BER is higher than 10%. Soemthing is completely wrong! (BER is ',num2str(testCase.ber),')']);
end
end
end

View File

@@ -0,0 +1,50 @@
classdef Testclass_template < matlab.unittest.TestCase
properties
%genereal properties of the test
end
properties (MethodSetupParameter)
% Define method-level parameters for PRBS and bit pattern
% i.e.: useprbs = {0,1};
useprbs = {0,1};
M = {2,4,6};
end
properties (TestParameter)
% Define test-level parameters for M and O
end
methods (TestMethodSetup)
function setupTest(testCase, useprbs, M)
% Setup everything that is somehow reguired for the test,
% include the MethodSetupParameters here as arguments
end
end
methods (Test)
% Test with sequential combination of parameters
function myTest(testCase, M, useprbs)
% Write the actual test,
% include the MethodSetupParameters here as arguments
% Assert that BER is zero
testCase.verifyEqual(M, M, 'error message');
testCase.verifyEqual(useprbs, useprbs, 'error message');
end
% Test with sequential combination of parameters
function anotherTest(testCase, M)
% Write the actual test,
% include the MethodSetupParameters here as arguments
% Assert that BER is zero
testCase.verifyEqual(M, M, 'error message');
testCase.verifyClass(M,'double');
end
end
end