138 lines
4.4 KiB
Matlab
138 lines
4.4 KiB
Matlab
classdef Duobinary_test < matlab.unittest.TestCase
|
|
|
|
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); % 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, 'O18', 18, 'O19', 19); % 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-1); %length of prbs
|
|
[~,seed] = prbs(O,1); %initialize first seed of prbs
|
|
bitpattern=[];
|
|
|
|
if useprbs
|
|
%%%%% MOVE-IT PRMS %%%%
|
|
|
|
state = struct();
|
|
|
|
para = struct();
|
|
|
|
if M == 6
|
|
para.bl = 2^(O-2);
|
|
para.dimension = 5;
|
|
else
|
|
para.bl = 2^(O-1);
|
|
para.dimension = log2(M); %2.5bits/sym -> 2 bit/sym
|
|
end
|
|
|
|
para.rand = 0;
|
|
|
|
para.order = floor(O / log2(M));
|
|
para.skip =0;
|
|
para.bruijn = 0;
|
|
para.reset_prms = 0;
|
|
para.method = 1;
|
|
|
|
data_in = [];
|
|
global loop;
|
|
loop = 0;
|
|
[data_out,state_] = prms(data_in, state, para);
|
|
loop = 1;
|
|
[data_out,state_out] = prms(data_in, state_, para);
|
|
bitpattern = data_out';
|
|
|
|
%%%%% END MOVE-IT %%%%%%%
|
|
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)
|
|
% 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
|