DB and 400G and minor changes
This commit is contained in:
@@ -1,36 +1,74 @@
|
||||
classdef test_modulation < matlab.unittest.TestCase
|
||||
|
||||
properties
|
||||
Tx_bits
|
||||
Digi_Mod
|
||||
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)
|
||||
% Define test-level parameters for M and O
|
||||
|
||||
O = 10; %order of prbs
|
||||
N = 2^(O-1); %length of prbs
|
||||
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
||||
bitpattern=[];
|
||||
M=6;
|
||||
end
|
||||
|
||||
methods (TestMethodSetup)
|
||||
|
||||
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
|
||||
randkey = 1; % Random key for random stream
|
||||
|
||||
[~, 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.Tx_bits = Informationsignal(bitpattern);
|
||||
testCase.Digi_Mod = PAMmapper(M, 0);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
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);
|
||||
|
||||
% Demap symbols back to bits
|
||||
Rx_bits = testCase.Digi_Mod.demap(Symbols);
|
||||
|
||||
% Validate BER is zero
|
||||
[~, 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
|
||||
testCase.verifyEqual(ber, 0, 'BER should be zero');
|
||||
testCase.verifyEqual(error_num, 0, 'No errors should occur in the mapping process');
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1:log2(M)
|
||||
[bitpattern(:,i),seed] = prbs(O,N,seed);
|
||||
end
|
||||
|
||||
if M == 6
|
||||
bitpattern = reshape(bitpattern,[],1);
|
||||
end
|
||||
|
||||
% [bitpattern,seed] = prbs(O,N,seed);
|
||||
% %
|
||||
% bitpattern = bitpattern';
|
||||
|
||||
% 2 ) Build Inf. signal class
|
||||
bits = Informationsignal(bitpattern);
|
||||
|
||||
|
||||
% 3) Digi modulation -> PAM-M signal
|
||||
digimod_out = PAMmapper(M,0).map(bits);
|
||||
|
||||
Rx_Bits = PAMmapper(M,0).demap(digimod_out);
|
||||
|
||||
[~,errors_bm,BER,errors] = calc_ber(Rx_Bits.signal,bitpattern,"skip_front",0,"skip_end",0,"returnErrorLocation",1);
|
||||
|
||||
formatted_ber = sprintf('%.1e', BER);
|
||||
disp(['BER: ',formatted_ber]);
|
||||
|
||||
Reference in New Issue
Block a user