NR - CSI Codebook

 

 

 

 

 

 

Followings are the code that I wrote in  Matlab 2019b and Phased Array System Toolbox  to creates all the plots shown in this page. You may copy these code and play with these codes. Change variables and try yourself until you get your own intuitive understanding.

 

It will be helpful for you to understand the code here if you take a look at this page and understand how the radiation daigram for ULA (Uniform Linear Array). Make some practice until you are able to draw a radiation pattern of linear array antenna on your own.

The highlighted part in the code is for drawing the radiation pattern, W_5_2_2_2_1_5() is to calculate the weight vector based on 3GPP NR Codebook Calculation Algorithm explained in this page.

 

 

< Code 1 >

 

function main

 

    c = 3e8;        % propagation speed

    fc = 26e9;      % carrier frequency

    lambda = c/fc;  % wavelength

    NoOfTxAntenna = 8;

 

    antennaElement = phased.CrossedDipoleAntennaElement;

    txarray = phased.ULA('NumElements',NoOfTxAntenna,'ElementSpacing',lambda/2,'Element',antennaElement);

    txmipos = getElementPosition(txarray)/lambda;

 

    txarraystv = phased.SteeringVector('SensorArray',txarray,'PropagationSpeed',c);

 

    P_CSIRS = 16;

    N1 = 8;

    N2 = 1;

    O1 = 4;

    O2 = 1;

    

    i2List = [0 1 2 3;4 5 6 7;8 9 10 11;12 13 14 15];

    

    fidx = 1;

    

    for i2si = 1:4

        for i11 = 0 : (N1*O1-1)  

            for i12 = 0 : (N2*O2-1)

               %for i2 = i2List(:,i2si)'   

               for i2 = i2List(i2si,:)     

                    i_11 = i11;

                    i_12 = i12;

                    i_2 = i2;

                    

                    W = W_5_2_2_2_1_5(2,P_CSIRS,N1,O1,N2,O2,i_11,i_12,i_2);

                    

                    tStr = sprintf('i_{11} = %d, i_{12} = %d, i_2 = %d',i_11,i_12,i_2);

                    wStr = sprintf('i_11 = %d, i_12 = %d, i_2 = %d',i_11,i_12,i_2);

                    for i = 1:15

                       wStr = sprintf('%s ,%0.4f+%0.4fi',wStr,real(W(i)),imag(W(i)));

                    end

                    wStr = sprintf('%s\r\n',wStr);

                    disp(wStr);

                    disp(W);

 

                    %wt = W.';

                    wt = W;

                    wt1 = wt(1:numel(wt)/2);

                    wt2 = wt(numel(wt)/2+1:end);

 

                    txbeam_ang = -90:90;

                    txbeam_ang_rad = (pi*txbeam_ang)/180;

 

                    txbeam1 = (wt1*steervec(txmipos,txbeam_ang));  

                    txbeamMag1 = abs(txbeam1)/max(abs(txbeam1));

                    txbeamArg1 = angle(txbeam1)/max(angle(txbeam1));

                    txbeam2 = (wt2*steervec(txmipos,txbeam_ang));  

                    txbeamMag2 = abs(txbeam2)/max(abs(txbeam2));

                    txbeamArg2 = angle(txbeam2)/max(angle(txbeam2));

                    

                    hFig = figure(1);

                    set(hFig, 'Position', [100 100 600 500]);

                    set(gcf,'color','w');

 

                    subplot(3,2,1);

                    polarplot(txbeam_ang_rad,txbeamMag1,'r');

                    set(gca,'RTickLabels',[]);

                    title(tStr);

 

                    subplot(3,2,2);  

                    polarplot(txbeam_ang_rad,txbeamMag2,'r');

                    set(gca,'RTickLabels',[]);

                    title(tStr);

                    

                    subplot(3,2,3);

                    polarplot(txbeam_ang_rad,txbeamArg1,'b');

                    set(gca,'RTickLabels',[]);

                    title('Phase');

 

                    subplot(3,2,4);  

                    polarplot(txbeam_ang_rad,txbeamArg2,'b');

                    set(gca,'RTickLabels',[]);

                    title('Phase');

 

                    subplot(3,2,5);

                    plot(real(wt1),imag(wt1),'ro');

                    axis([-1.0 1.0 -1.0 1.0]);

                    pbaspect([1 1 1]);

                    title("W - pol 1");

 

                    subplot(3,2,6);

                    plot(real(wt2),imag(wt2),'ro');

                    axis([-1.0 1.0 -1.0 1.0]);

                    pbaspect([1 1 1]);

                    title("W - pol 2");

 

                    pause(0.2);

 

                end

            end

        end

    end

    

    fclose(fileID);

 

end

 

function W = W_5_2_2_2_1_5(CBtype,P_CSIRS,N1,O1,N2,O2,i_11,i_12,i_2)

 

    if CBtype == 1

        l = i_11;

        m = i_12;

        n = i_2;

        

    elseif CBtype == 2 & N2 == 1

        if ismember(i_2, [0 1 2 3])

           l = 2 * i_11 + 0;

        elseif ismember(i_2, [4 5 6 7])

           l = 2 * i_11 + 1;

        elseif ismember(i_2, [8 9 10 11])

           l = 2 * i_11 + 2;   

        elseif ismember(i_2, [12 13 14 15])

           l = 2 * i_11 + 3;

        end   

           

        m = 0;

        n = mod(i_2,4);    

        %disp(n);

    elseif CBtype == 2 & N2 > 1

       % l = i_11;

       % m = i_12;

       % n = i_2;

    end

    

    Vlm = CalcVlm(l,N1,O1,m,N2,O2);

    Pn = PhiN(n);

    

    %W = (1/sqrt(P_CSIRS)) * [Vlm Pn*Vlm].';

    W = (1/sqrt(P_CSIRS)) * [Vlm Pn.*Vlm];

end

 

function Pn = PhiN(n)

     Pn = exp(j*pi*n/2);

end

 

function Vlm = CalcVlm(l,N1,O1,m,N2,O2)

 

    Vlm = [1];

    Um = CalcUm(m,N2,O2);

    for n = 1 : N1-1

        Vlm = [Vlm exp(j*(2*pi*l*n)/(O1*N1))*Um];  

    end

       

end

 

function Um = CalcUm(m,N2,O2)

 

    if N2 == 1

       Um = 1;

    else

       Um = [];

       for n = 0 : N2-1

           Um = [Um exp(j*(2*pi*m*n)/(O2*N2))];  

       end

    end   

 

end