lte_layer_mapper_dl.m 7.17 KB
Newer Older
Ben Wojtowicz's avatar
Ben Wojtowicz committed
1
%
2
% Copyright 2011-2012, 2014 Ben Wojtowicz
Ben Wojtowicz's avatar
Ben Wojtowicz committed
3 4
%
%    This program is free software: you can redistribute it and/or modify
5
%    it under the terms of the GNU Affero General Public License as published by
Ben Wojtowicz's avatar
Ben Wojtowicz committed
6 7 8 9 10 11
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
%    GNU Affero General Public License for more details.
Ben Wojtowicz's avatar
Ben Wojtowicz committed
13
%
14
%    You should have received a copy of the GNU Affero General Public License
Ben Wojtowicz's avatar
Ben Wojtowicz committed
15 16
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
17
% Function:    lte_layer_mapper_dl
Ben Wojtowicz's avatar
Ben Wojtowicz committed
18
% Description: Maps complex-valued modulation symbols onto one
19
%              or several downlink layers
Ben Wojtowicz's avatar
Ben Wojtowicz committed
20 21 22 23 24 25 26 27 28
% Inputs:      d            - Complex valued modulation symbols
%              v            - Number of layers
%              style        - Style of mapping (tx_diversity or
%                             spatial_multiplex)
% Outputs:     x            - Mapped complex valued modulation
%                             symbols
% Spec:        3GPP TS 36.211 section 6.3.3 v10.1.0
% Notes:       None
% Rev History: Ben Wojtowicz 10/28/2011 Created
29
%              Ben Wojtowicz 01/29/2012 Fixed license statement
30
%              Ben Wojtowicz 02/19/2012 Added newline to EOF
Ben Wojtowicz's avatar
Ben Wojtowicz committed
31 32
%              Ben Wojtowicz 03/28/2012 Fixed a bug in 3 antenna spatial
%                                       multiplexing
33
%              Ben Wojtowicz 03/26/2014 Changed name to lte_layer_mapper_dl
Ben Wojtowicz's avatar
Ben Wojtowicz committed
34
%
35
function [x] = lte_layer_mapper_dl(d, v, style)
Ben Wojtowicz's avatar
Ben Wojtowicz committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

    [N_cw, M_symb] = size(d);

    if(v == 1 && N_cw == 1)
        % 36.211 Section 6.3.3.1 v10.1.0
        M_layer_symb = M_symb;
        for(n=0:M_layer_symb-1)
            x(0+1, n+1) = d(0+1, n+1);
        endfor
    else
        if(style == "tx_diversity")
            % 36.211 section 6.3.3.3 v10.1.0
            if(v == 2 && N_cw == 1)
                M_layer_symb = M_symb/2;
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d(0+1, 2*n+0+1);
                    x(1+1, n+1) = d(0+1, 2*n+1+1);
                endfor
            elseif(v == 4 && N_cw == 1)
                if(mod(M_symb, 4) == 0)
                    M_layer_symb = M_symb/4;
                    d_prime      = d;
                else
                    M_layer_symb = (M_symb+2)/4;
                    d_prime      = [d, 10, 10];
                endif
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d_prime(0+1, 4*n+1);
                    x(1+1, n+1) = d_prime(0+1, 4*n+1+1);
                    x(2+1, n+1) = d_prime(0+1, 4*n+2+1);
                    x(3+1, n+1) = d_prime(0+1, 4*n+3+1);
                endfor
            else
                printf("ERROR: Invalid v (%u) or N_cw (%u)\n", v, N_cw);
                x = 0;
                return;
            endif
        elseif(style == "spatial_multiplex")
            % 36.211 section 6.3.3.2 v10.1.0
            if(v == 2 && (N_cw == 1 || N_cw == 2))
                if(N_cw == 1)
                    M_layer_symb = M_symb/2;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1, 2*n+0+1);
                        x(1+1, n+1) = d(0+1, 2*n+1+1);
                    endfor
                else
                    M_layer_symb = M_symb;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1, n+1);
                        x(1+1, n+1) = d(1+1, n+1);
                    endfor
                endif
            elseif(v == 3 && (N_cw == 1 || N_cw == 2))
                if(N_cw == 1)
                    M_layer_symb = M_symb/3;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1, 3*n+0+1);
                        x(1+1, n+1) = d(0+1, 3*n+1+1);
                        x(2+1, n+1) = d(0+1, 3*n+2+1);
                    endfor
                else
                    M_layer_symb = M_symb/2;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1,     n+1);
                        x(1+1, n+1) = d(1+1, 2*n+0+1);
Ben Wojtowicz's avatar
Ben Wojtowicz committed
102
                        x(2+1, n+1) = d(1+1, 2*n+1+1);
Ben Wojtowicz's avatar
Ben Wojtowicz committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
                    endfor
                endif
            elseif(v == 4 && (N_cw == 1 || N_cw == 2))
                if(N_cw == 1)
                    M_layer_symb = M_symb/4;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1, 4*n+0+1);
                        x(1+1, n+1) = d(0+1, 4*n+1+1);
                        x(2+1, n+1) = d(0+1, 4*n+2+1);
                        x(3+1, n+1) = d(0+1, 4*n+3+1);
                    endfor
                else
                    M_layer_symb = M_symb/2;
                    for(n=0:M_layer_symb-1)
                        x(0+1, n+1) = d(0+1, 2*n+0+1);
                        x(1+1, n+1) = d(0+1, 2*n+1+1);
                        x(2+1, n+1) = d(1+1, 2*n+0+1);
                        x(3+1, n+1) = d(1+1, 2*n+1+1);
                    endfor
                endif
            elseif(v == 5 && N_cw == 2)
                M_layer_symb = M_symb/3;
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d(0+1, 2*n+0+1);
                    x(1+1, n+1) = d(0+1, 2*n+1+1);
                    x(2+1, n+1) = d(1+1, 3*n+0+1);
                    x(3+1, n+1) = d(1+1, 3*n+1+1);
                    x(4+1, n+1) = d(1+1, 3*n+2+1);
                endfor
            elseif(v == 6 && N_cw == 2)
                M_layer_symb = M_symb/3;
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d(0+1, 3*n+0+1);
                    x(1+1, n+1) = d(0+1, 3*n+1+1);
                    x(2+1, n+1) = d(0+1, 3*n+2+1);
                    x(3+1, n+1) = d(1+1, 3*n+0+1);
                    x(4+1, n+1) = d(1+1, 3*n+1+1);
                    x(5+1, n+1) = d(1+1, 3*n+2+1);
                endfor
            elseif(v == 7 && N_cw == 2)
                M_layer_symb = M_symb/4;
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d(0+1, 3*n+0+1);
                    x(1+1, n+1) = d(0+1, 3*n+1+1);
                    x(2+1, n+1) = d(0+1, 3*n+2+1);
                    x(3+1, n+1) = d(1+1, 4*n+0+1);
                    x(4+1, n+1) = d(1+1, 4*n+1+1);
                    x(5+1, n+1) = d(1+1, 4*n+2+1);
                    x(6+1, n+1) = d(1+1, 4*n+3+1);
                endfor
            elseif(v == 8 && N_cw == 2)
                M_layer_symb = M_symb/4;
                for(n=0:M_layer_symb-1)
                    x(0+1, n+1) = d(0+1, 4*n+0+1);
                    x(1+1, n+1) = d(0+1, 4*n+1+1);
                    x(2+1, n+1) = d(0+1, 4*n+2+1);
                    x(3+1, n+1) = d(0+1, 4*n+3+1);
                    x(4+1, n+1) = d(1+1, 4*n+0+1);
                    x(5+1, n+1) = d(1+1, 4*n+1+1);
                    x(6+1, n+1) = d(1+1, 4*n+2+1);
                    x(7+1, n+1) = d(1+1, 4*n+3+1);
                endfor
            else
                printf("ERROR: Invalid v (%u) or N_cw (%u)\n", v, N_cw);
                x = 0;
                return;
            endif
        else
            printf("ERROR: Invalid style (%s)\n", style);
            x = 0;
            return;
        endif
    endif
176
endfunction