1 function [map,demap] = constmap(consttype,M,maptype,usermap)
2 % CONSTMAP Generates constellation mappings.
4 % MAP = CONSTMAP(CONSTTYPE,M,MAPTYPE[,USERMAP])
6 % CONSTTYPE - constellation type (check types supported by constref)
7 % M - constellation order
8 % MAPTYPE - constellation map type; available:
10 %
'user' User-defined mapping (used to generate demapping map)
11 % USERMAP - user-provided map with M elements
13 % Base-1 index is used
for maps to simplify MATLAB code.
14 % Example of use is in constutils_example.m
18 % This
function requires grays
function from
'Gray Code Manipulation' 19 %
package available at http:
21 % Robert Borkowski, rbor@fotonik.dtu.dk
22 % Technical University of Denmark
23 % v1.0, 15 August 2014
26 case {'linear', 'lin', 'binary', 'bin'}
30 map = bitxor(seq,bitshift(seq,-1))+1; % Generate Gray code 31 if strcmpi(consttype,'qam
') 35 map(i+(1:log2M)) = map(i+(log2M:-1:1)); 38 error('Gray mapping
for constellations with M~=2^k is undefined. Please work on 8-QAM.
'); 44 error('For type
''custom
'', a custom map has to be provided.
'); 45 elseif numel(usermap)~=M 48 map = uint16(usermap(:)); 52 [~,demap] = sort(map); 53 demap = uint16(demap); 56 switch lower(consttype) 59 demap(:,end+1) = [1:1:M]; % This is not a Gray code! This change make this code compatible with TxSymbolsGen_v1. 63 demap(:,end+1) = reshape(rot90(reshape(demap_,2^(log2M/2),2^(log2M/2)),i),M,1); 68 demap(:,end+1) = circshift(demap_,i); 72 if ~rem(M,sqrt(M)) && M>1 % square constellation 73 demap(:,end+1) = reshape(reshape(demap_,log2(M),log2(M)).',M,1);
74 elseif M==8 %couldn
't figure out how to do this elegantly, sorry Robert 75 demap(:,end+1) = demap_([1, 5, 3, 7, 2, 6, 4, 8]); 87 case 'dpask-experimental
' 96 % demap = [demap [flipud(demap(1:4,:)); demap(5:8,:)]]; 99 warning('No demapping permutations generated.
');