Files
imdd_silas/Tests/01_transmit/PAMmapper_test.m
2026-03-24 17:23:02 +01:00

70 lines
2.2 KiB
Matlab

classdef PAMmapper_test < IMDDTestCase
methods (Test, TestTags = {'unit', 'fast', 'transmit', 'pammapper'})
function roundTripBitMappingForSupportedPamOrders(testCase)
modulationOrders = [2, 4, 8];
for M = modulationOrders
txBits = Informationsignal(allBitPatternsForOrder(M));
mapper = PAMmapper(M, 0);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
testCase.verifyEqual(double(demapped.signal), double(txBits.signal), ...
sprintf("Roundtrip mapping failed for PAM-%d.", M));
end
end
function roundTripPam6ClassicMapping(testCase)
txBits = Informationsignal(pam6BitStream());
mapper = PAMmapper(6, 0);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
testCase.verifyEqual(demapped.signal, txBits.signal, ...
"PAM-6 classic mapping should be lossless for aligned inputs.");
end
function roundTripPam6EthMapping(testCase)
txBits = Informationsignal(pam6BitStream());
mapper = PAMmapper(6, 0, "eth_style", 1);
mapped = mapper.map(txBits);
demapped = mapper.demap(mapped);
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