109 lines
3.6 KiB
Matlab
109 lines
3.6 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,'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)
|
|
% 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
|