Build out MATLAB test framework and core integration coverage

This commit is contained in:
Silas Oettinghaus
2026-03-24 17:23:02 +01:00
parent 9446dfb888
commit a592ebefda
154 changed files with 2281 additions and 1305 deletions

View File

@@ -1,11 +1,10 @@
classdef AWG_test < matlab.unittest.TestCase
% Test class for AWG
classdef AWG_test < IMDDTestCase
% Auto-generated placeholder for AWG.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/AWG.m
methods (Test)
function testExample(testCase)
% Example test case for AWG
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for AWG are not implemented yet.");
end
end
end

View File

@@ -1,11 +1,10 @@
classdef ChannelFreqResp_test < matlab.unittest.TestCase
% Test class for ChannelFreqResp
classdef ChannelFreqResp_test < IMDDTestCase
% Auto-generated placeholder for ChannelFreqResp.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/ChannelFreqResp.m
methods (Test)
function testExample(testCase)
% Example test case for ChannelFreqResp
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for ChannelFreqResp are not implemented yet.");
end
end
end

View File

@@ -1,11 +1,10 @@
classdef M8196A_test < matlab.unittest.TestCase
% Test class for M8196A
classdef M8196A_test < IMDDTestCase
% Auto-generated placeholder for M8196A.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/M8196A.m
methods (Test)
function testExample(testCase)
% Example test case for M8196A
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for M8196A are not implemented yet.");
end
end
end

View File

@@ -1,11 +1,10 @@
classdef M8199A_test < matlab.unittest.TestCase
% Test class for M8199A
classdef M8199A_test < IMDDTestCase
% Auto-generated placeholder for M8199A.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/M8199A.m
methods (Test)
function testExample(testCase)
% Example test case for M8199A
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for M8199A are not implemented yet.");
end
end
end

View File

@@ -1,11 +1,10 @@
classdef M8199B_test < matlab.unittest.TestCase
% Test class for M8199B
classdef M8199B_test < IMDDTestCase
% Auto-generated placeholder for M8199B.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/M8199B.m
methods (Test)
function testExample(testCase)
% Example test case for M8199B
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for M8199B are not implemented yet.");
end
end
end

View File

@@ -1,74 +1,69 @@
classdef PAMmapper_test < matlab.unittest.TestCase
classdef PAMmapper_test < IMDDTestCase
methods (Test, TestTags = {'unit', 'fast', 'transmit', 'pammapper'})
properties
Tx_bits
PAMmapper
end
function roundTripBitMappingForSupportedPamOrders(testCase)
modulationOrders = [2, 4, 8];
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
for M = modulationOrders
txBits = Informationsignal(allBitPatternsForOrder(M));
properties (TestParameter)
% Define test-level parameters for M and O
mapper = PAMmapper(M, 0);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
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
testCase.verifyEqual(double(demapped.signal), double(txBits.signal), ...
sprintf("Roundtrip mapping failed for PAM-%d.", M));
end
if M == 6
bitpattern = reshape(bitpattern, [], 1);
bitpattern = bitpattern(1:end-mod(length(bitpattern), 5));
end
testCase.Tx_bits = Informationsignal(bitpattern);
testCase.PAMmapper = PAMmapper(M, 0);
end
end
function roundTripPam6ClassicMapping(testCase)
txBits = Informationsignal(pam6BitStream());
methods (Test, ParameterCombination = 'sequential')
% Test with sequential combination of parameters
function testBackToBackMapping(testCase, M, useprbs, O)
% Test Bits -> Symbols -> Bits (Back-to-Back Mapping)
mapper = PAMmapper(6, 0);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
% Map bits to symbols
Symbols = testCase.PAMmapper.map(testCase.Tx_bits);
testCase.verifyEqual(demapped.signal, txBits.signal, ...
"PAM-6 classic mapping should be lossless for aligned inputs.");
end
% Demap symbols back to bits
Rx_bits = testCase.PAMmapper.demap(Symbols);
function roundTripPam6EthMapping(testCase)
txBits = Informationsignal(pam6BitStream());
% Validate BER is zero
[~, error_num, ber, ~] = calc_ber(testCase.Tx_bits.signal, Rx_bits.signal, ...
"skip_front", 0, "skip_end", 0, "returnErrorLocation", 1);
mapper = PAMmapper(6, 0, "eth_style", 1);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
% 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');
expectedBits = txBits.signal(1:length(demapped.signal));
testCase.verifyEqual(demapped.signal, expectedBits, ...
"PAM-6 ETH mapping should be lossless for aligned inputs.");
end
function quantizeMapsToNearestConstellationLevel(testCase)
mapper = PAMmapper(4, 0);
signalIn = Electricalsignal([-4.0; -0.2; 0.4; 2.9], "fs", 1);
quantized = mapper.quantize(signalIn);
expected = [-3; -1; 1; 3] ./ sqrt(5);
testCase.verifyEqual(quantized.signal, expected, "AbsTol", 1e-12);
end
end
end
function bits = allBitPatternsForOrder(M)
bitWidth = log2(M);
symbols = (0:M-1).';
bits = zeros(M, bitWidth);
for bitIdx = 1:bitWidth
bits(:, bitIdx) = bitget(symbols, bitWidth - bitIdx + 1);
end
end
function bits = pam6BitStream()
combinations = dec2bin(0:31, 5) - '0';
bits = reshape(combinations.', [], 1);
end

View File

@@ -1,11 +1,104 @@
classdef PAMsource_test < matlab.unittest.TestCase
% Test class for PAMsource
classdef PAMsource_test < IMDDTestCase
methods (Test, TestTags = {'unit', 'fast', 'transmit', 'pamsource'})
function constructorStoresProvidedOptions(testCase)
src = PAMsource( ...
"order", 5, ...
"useprbs", false, ...
"M", 4, ...
"fsym", 8, ...
"randkey", 17, ...
"applypulseform", false, ...
"fs_out", 8, ...
"applyclipping", false);
methods (Test)
function testExample(testCase)
% Example test case for PAMsource
% Add your test code here
testCase.verifyTrue(true);
testCase.verifyEqual(src.order, 5);
testCase.verifyFalse(src.useprbs);
testCase.verifyEqual(src.M, 4);
testCase.verifyEqual(src.fsym, 8);
testCase.verifyEqual(src.randkey, 17);
testCase.verifyFalse(src.applypulseform);
testCase.verifyEqual(src.fs_out, 8);
testCase.verifyFalse(src.applyclipping);
testCase.verifyEmpty(src.pulseformer);
end
function deterministicProcessMatchesPamMapperAcrossOrders(testCase)
orders = [2, 4, 8];
sourceOrder = 5;
fs = 8;
seed = 17;
for M = orders
src = PAMsource( ...
"order", sourceOrder, ...
"useprbs", false, ...
"M", M, ...
"fsym", fs, ...
"randkey", seed, ...
"applypulseform", false, ...
"fs_out", fs, ...
"applyclipping", false);
[digiSig, symbols, bits] = src.process();
bitpattern = expectedBitpattern(M, sourceOrder, seed);
expectedBits = Informationsignal(bitpattern);
expectedSymbols = PAMmapper(M, 0).map(expectedBits);
testCase.verifyClass(digiSig, 'Informationsignal');
testCase.verifyClass(symbols, 'Informationsignal');
testCase.verifyClass(bits, 'Informationsignal');
testCase.verifyEqual(bits.signal, bitpattern);
testCase.verifyEqual(symbols.signal, expectedSymbols.signal);
testCase.verifyEqual(digiSig.signal, expectedSymbols.signal);
testCase.verifyEqual(digiSig.fs, fs);
end
end
function clippingLimitsAmplitudeToScaledConstellationRange(testCase)
M = 4;
sourceOrder = 5;
fs = 8;
seed = 3;
src = PAMsource( ...
"order", sourceOrder, ...
"useprbs", false, ...
"M", M, ...
"fsym", fs, ...
"randkey", seed, ...
"applypulseform", false, ...
"fs_out", fs, ...
"applyclipping", true, ...
"clipfactor", 0.5);
[digiSig, symbols, bits] = src.process();
expectedBits = expectedBitpattern(M, sourceOrder, seed);
expectedSymbols = PAMmapper(M, 0).map(Informationsignal(expectedBits));
lowerLimit = min(expectedSymbols.signal) * 0.5;
upperLimit = max(expectedSymbols.signal) * 0.5;
expectedClipped = expectedSymbols.signal;
expectedClipped(expectedClipped < lowerLimit) = lowerLimit;
expectedClipped(expectedClipped > upperLimit) = upperLimit;
testCase.verifyEqual(bits.signal, expectedBits);
testCase.verifyEqual(symbols.signal, expectedSymbols.signal);
testCase.verifyEqual(digiSig.signal, expectedClipped);
testCase.verifyEqual(digiSig.fs, fs);
testCase.verifyLessThanOrEqual(max(digiSig.signal), upperLimit);
testCase.verifyGreaterThanOrEqual(min(digiSig.signal), lowerLimit);
end
end
end
function bitpattern = expectedBitpattern(M, order, seed)
bitWidth = log2(M);
N = 2^(order - 1);
s = RandStream('twister', 'Seed', seed);
bitpattern = zeros(N, bitWidth);
for idx = 1:bitWidth
bitpattern(:, idx) = randi(s, [0 1], N, 1);
end
end

View File

@@ -1,11 +1,120 @@
classdef Pulseformer_test < matlab.unittest.TestCase
% Test class for Pulseformer
classdef Pulseformer_test < IMDDTestCase
methods (Test, TestTags = {'unit', 'fast', 'transmit', 'pulseformer'})
function constructorStoresConfiguredProperties(testCase)
pf = Pulseformer( ...
"fdac", 64e9, ...
"fsym", 16e9, ...
"pulse", pulseform.rrc, ...
"pulselength", 12, ...
"alpha", 0.2, ...
"matched", 1);
methods (Test)
function testExample(testCase)
% Example test case for Pulseformer
% Add your test code here
testCase.verifyTrue(true);
testCase.verifyEqual(pf.fdac, 64e9);
testCase.verifyEqual(pf.fsym, 16e9);
testCase.verifyEqual(pf.pulse, pulseform.rrc);
testCase.verifyEqual(pf.pulselength, 12);
testCase.verifyEqual(pf.alpha, 0.2);
testCase.verifyEqual(pf.matched, 1);
end
function processUsesSymbolRateFallbackAndUpdatesSignalMetadata(testCase)
fsym = 16e9;
fdac = 64e9;
tx = makeInformationsignal([1; 0; -1; 1; 1; 0], []);
pf = Pulseformer( ...
"fdac", fdac, ...
"fsym", fsym, ...
"pulse", pulseform.rc, ...
"pulselength", 8, ...
"alpha", 0.35, ...
"matched", 0);
rx = pf.process(tx);
expected = expectedPulseformerOutput(pf, tx);
testCase.verifyClass(rx, 'Informationsignal');
testCase.verifyEqual(rx.signal, expected, "AbsTol", 1e-12);
testCase.verifyEqual(rx.fs, fdac);
testCase.verifyEqual(height(rx.logbook), height(tx.logbook) + 1);
testCase.verifyEqual(string(rx.logbook.Description(end)), "Applied Pulseshaping");
end
function matchedAndUnmatchedProcessingPreserveTheSameRealWaveform(testCase)
tx = makeInformationsignal([1; 0; 0; -1; 1; -1; 0; 1], 16e9);
unmatched = Pulseformer( ...
"fdac", 32e9, ...
"fsym", 16e9, ...
"pulse", pulseform.rrc, ...
"pulselength", 10, ...
"alpha", 0.15, ...
"matched", 0);
matched = Pulseformer( ...
"fdac", 32e9, ...
"fsym", 16e9, ...
"pulse", pulseform.rrc, ...
"pulselength", 10, ...
"alpha", 0.15, ...
"matched", 1);
rxUnmatched = unmatched.process(tx);
rxMatched = matched.process(tx);
testCase.verifyEqual(length(rxUnmatched.signal), length(rxMatched.signal));
testCase.verifyEqual(rxUnmatched.signal, rxMatched.signal, "AbsTol", 1e-12);
testCase.verifyEqual(rxUnmatched.signal, expectedPulseformerOutput(unmatched, tx), "AbsTol", 1e-12);
testCase.verifyEqual(rxMatched.signal, expectedPulseformerOutput(matched, tx), "AbsTol", 1e-12);
end
function processPreservesLengthForIntegerRateConversion(testCase)
tx = makeInformationsignal((1:5).', []);
pf = Pulseformer( ...
"fdac", 20e9, ...
"fsym", 5e9, ...
"pulse", pulseform.rc, ...
"pulselength", 6, ...
"alpha", 0.25, ...
"matched", 0);
rx = pf.process(tx);
testCase.verifyEqual(length(rx.signal), 20);
testCase.verifyEqual(rx.fs, 20e9);
end
end
end
function sig = makeInformationsignal(values, fs)
base = Signal(values);
sig = Informationsignal(values, "fs", fs, "logbook", base.logbook);
end
function expected = expectedPulseformerOutput(pf, signalclass_in)
if isprop(signalclass_in, 'fs') && ~isempty(signalclass_in.fs)
f_in = signalclass_in.fs;
else
f_in = pf.fsym;
end
[p, q] = rat(pf.fdac / f_in);
fs_intermediate = f_in * p;
sps_filter = fs_intermediate / pf.fsym;
if pf.pulse == pulseform.rc
filtertype = 'normal';
else
filtertype = 'sqrt';
end
h = rcosdesign(pf.alpha, pf.pulselength, sps_filter, filtertype);
if pf.matched
h = conj(fliplr(h));
end
data_out_ = upfirdn(signalclass_in.signal, h, p, q);
delay_samples_intermediate = (length(h) - 1) / 2;
delay_samples_out = delay_samples_intermediate / q;
st = floor(delay_samples_out) + 1;
len_out = ceil(length(signalclass_in.signal) * p / q);
expected = data_out_(st : st + len_out - 1);
end

View File

@@ -1,11 +1,10 @@
classdef Signalgenerator_test < matlab.unittest.TestCase
% Test class for Signalgenerator
classdef Signalgenerator_test < IMDDTestCase
% Auto-generated placeholder for Signalgenerator.
% Target: C:/Users/Silas/Documents/MATLAB/imdd_simulation/Classes/01_transmit/Signalgenerator.m
methods (Test)
function testExample(testCase)
% Example test case for Signalgenerator
% Add your test code here
testCase.verifyTrue(true);
methods (Test, TestTags = {'placeholder', 'todo'})
function testNotImplemented(testCase)
testCase.assumeFail("Tests for Signalgenerator are not implemented yet.");
end
end
end