matlab生成10mhz参考信号,LTE定位参考信号生成程序

在定位参考信号映射到资源单元中时,频域上位置与LTE协议标准中的不一样,一直找不到原因,麻烦各路大神帮帮忙!

主程序:

%PRS定位参考信号

clc;

close all;

clear all;

%信道为20MHz系统的参数设置

N_fft=2048;   % FFT点数

N_used_subcarrier=1200;  %可用的子载波个数

fs=30.72e6;    %系统采样频率

Ts=1/fs;       %系统采样间隔

N_DL_RB=100;   %资源块数目(传输带宽18MHz)

N_PRS_RB=100;  %分配给PRS的资源块数

N_RB_SC=12;   %每个资源块的子载波数

% N_id_1 = 9;      %物理层小区ID组 0 <= N_ID_1<=167

% N_id_2 = 1;           %物理层小区ID组中的物理层ID 0 <= N_ID_2<=2

% N_cell_id = 3* N_id_1 + N_id_2;         % 物理层小区ID 0-503

N_cell_id=5;

subframe_index=1;  %子帧号0--9

PBCH_port=1;  %物理广播信道天线端口数:1、2或4

N_CP=1;       %常规循环前缀:1;扩展循环前缀:0

switch N_CP

case 0, N_DL_symb=6;

case 1, N_DL_symb=7;

otherwise N_DL_symb=7;

end

SNR=25; %信噪比

% 定位参考信号映射到资源单元上

recv_subframe = zeros(N_DL_RB*N_RB_SC,N_DL_symb*2);

recv_subframe = rs_mapping_to_subframe_PRS(recv_subframe,subframe_index,N_cell_id,PBCH_port,N_PRS_RB,N_CP,N_DL_RB);  %定位参考信号

recv_subframe = rs_mapping_to_subframe(recv_subframe,subframe_index,N_cell_id,0,N_DL_RB,N_CP);    %小区参考信号

% recv_subframe = rs_mapping_to_subframe(recv_subframe,subframe_index,N_cell_id,1,N_DL_RB,N_CP);    %小区参考信号

% recv_subframe = rs_mapping_to_subframe(recv_subframe,subframe_index,N_cell_id,2,N_DL_RB,N_CP);    %小区参考信号

% recv_subframe = rs_mapping_to_subframe(recv_subframe,subframe_index,N_cell_id,3,N_DL_RB,N_CP);    %小区参考信号

%---IFFT---

recv_subframe =[zeros((N_fft-N_used_subcarrier)/2,N_DL_symb*2);recv_subframe;zeros((N_fft-N_used_subcarrier)/2,N_DL_symb*2)];

IFFTed=zeros(N_fft,N_DL_symb*2);

for i=1:N_DL_symb*2

IFFTed(:,i)=sqrt(N_fft)*ifft(recv_subframe(:,i),N_fft);

end

%---加CP----

WithCP_sequence=zeros(2208,N_DL_symb*2);

for i=1:14

WithCP_sequence(:,i)=CP_Insert(IFFTed(:,i).',0);

end

send_signal=reshape(WithCP_sequence,1,length(WithCP_sequence)*size(WithCP_sequence,2));

%---信道---

%---AWGN---

recv_signal=awgn(send_signal,SNR);

%---去CP---

recv_WithCP_sequence=reshape(recv_signal,2208,N_DL_symb*2);

NoCP_sequence=zeros(N_DL_symb*2,N_fft);

for i=1:N_DL_symb*2

NoCP_sequence(i,:)=CP_Removal(recv_WithCP_sequence(:,i),0);

end

NoCP_sequence=NoCP_sequence.';

%----FFT-----

FFTed=zeros(N_fft,N_DL_symb*2);

for i=1:N_DL_symb*2

FFTed(:,i)=1/sqrt(N_fft)*fft(NoCP_sequence(:,i),N_fft);

end

%---去资源映射---

调用函数:

function subframe = rs_mapping_to_subframe (subframe,sub_index,N_cell_id,p,N_DL_RB,N_CP);

% *************************************************************************

% Function Description: (v1.0---20090513 by jiangyoubang)

%  This function is used for the progress of mapping the reference signals

%  to the relevant position in the radio subframe of antana port p in 3GPP LTE.

%

%  usage :

%        subframe = rs_mapping_to_subframe (subframe,sub_index,N_cell_id,p,N_DL_RB,N_CP);

%

%  input parameter :

%       "subframe" : the data subframe that reference signal needs to add into.

%       "sub_index" : the subframe index in a radio frame. range:0~9

%       "N_cell_id" : Physical layer cell identity.

%       "N_CP" : For normal CP,N_CP=1; for extended CP,N_CP=0;

%       "p" : The antena number

%       "N_DL_RB" : Downlink bandwidth configuration. it might be 6,25,50,100

%

%   note :

%       the generalization of the reference signal sequence

%           can be found in Ref.36.211.850

%**************************************************************************

% parameter that can be found in Ref.36.211-850

N_RB_DL_MAX = 110;

v_shift = mod(N_cell_id,6);

% For N_CP=1, means normal CP; For N_CP=0, means extended CP;

switch N_CP

case 0, N_DL_symb = 6;

case 1, N_DL_symb = 7;

otherwise  N_DL_symb = 7;

end

% different p means different antana port, and the mapping process is different

%参考于《移动宽带技术》----扇区参考信号定义(p79)

switch p

case 0, %the subframe will go to antana port 0

for ns= 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

l=0;%如果p=0且l=0时,v=0(参考移动宽带技术——扇区参考信号定义)

v=0;

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = (6 * m + mod((v + v_shift),6)) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1); %mapping rs to subframe

end

l=N_DL_symb - 3;%N_DL_symb=7

v=3;

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = 6 * m + mod((v + v_shift),6) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

end

end

case 1, %the subframe will go to antana port 1

for ns= 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

l=0;

v=3;

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = 6 * m + mod((v + v_shift),6) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

end

l=N_DL_symb - 3;

v=0;

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = 6 * m + mod((v + v_shift),6) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

end

end

case 2, %the subframe will go to antana port 2

for ns= 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

l=1;

v=3*mod(ns,2);

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = 6 * m + mod((v + v_shift),6) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

end

end

case 3, %the subframe will go to antana port 3

for ns= 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

l=1;

v=3+3*mod(ns,2);

%mod((v + v_shift),6)

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

for m = 0 : 2 * N_DL_RB - 1

m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

k = 6 * m + mod((v + v_shift),6) + 1;

subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

end

end

otherwise disp('illagal antana port number p .');

end

function subframe = rs_mapping_to_subframe_PRS (subframe,sub_index,N_cell_id,PBCH,N_PRS_RB,N_CP,N_DL_RB);

% *************************************************************************

%  This function is used for the progress of mapping the reference signals

%  to the relevant position in the radio subframe of antana port p in 3GPP LTE.

%

%  usage :

%        subframe = rs_mapping_to_subframe (subframe,sub_index,N_cell_id,p,N_DL_RB,N_CP);

%

%  input parameter :

%       "subframe" : the data subframe that reference signal needs to add into.

%       "sub_index" : the subframe index in a radio frame. range:0~9

%       "N_cell_id" : Physical layer cell identity.

%       "N_CP" : For normal CP,N_CP=1; for extended CP,N_CP=0;

%       "p" : The antena number

%       "N_DL_RB" : Downlink bandwidth configuration. it might be 6,25,50,100

%

%   note :

%   the generalization of the reference signal sequence

%   can be found in Ref.36.211.850

%**************************************************************************

N_RB_DL_MAX = 110;

v_shift = mod(N_cell_id,6);

% N_CP=1, 常规循环前缀P;N_CP=0, 扩展循环前缀;

switch N_CP

case 0, N_DL_symb = 6;

case 1, N_DL_symb = 7;

otherwise  N_DL_symb = 7;

end

% 定位参考信号映射到资源单元上

if N_CP==1    %常规循环前缀

for ns = 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

if kk==0

l=[3,5,6];       %OFDM符号的序号

elseif (kk==1)&&(PBCH==1||PBCH==2)  %kk=1且(1个或2个物理广播信道天线端口)

l=[1,2,3,5,6];   %OFDM符号的序号

elseif (kk==1)&&(PBCH==4)           %kk=1且(4个物理广播信道天线端口)

l=[2,3,5,6];     %OFDM符号的序号

end

for i=1:length(l)

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l(i));          % 产生定位参考信号序列

for m = 0: 2 * N_PRS_RB-1

m1 = m + N_RB_DL_MAX - N_PRS_RB+1;

k=6*(m+N_DL_RB-N_PRS_RB)+mod((6-l(i)+v_shift),6)+1;  %k为子载波序号

subframe(k,l(i)+N_DL_symb*kk+1) = r_l_ns(m1);      %参考信号序列映射到复值调制符号(天线端口6)

end

end

end

else %扩展循环前缀

for ns= 2 * sub_index : 2 * sub_index + 1

kk=mod(ns,2);

if kk==0  %l的取值

l=[4,5];

elseif (kk==1)&&(PBCH==1||PBCH==2)

l=[1,2,4,5];

elseif (kk==1)&&(PBCH==4)

l=[2,4,5];

end

for i=1:length(l)

r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l(i));  % 产生定位参考信号序列

for m = 0 : 2 * N_PRS_RB - 1

m1 = m + N_RB_DL_MAX - N_PRS_RB;

k=6*(m+N_DL_RB-N_PRS_RB)+mod((5-l(i)+v_shift),6)+1;

subframe(k,l(i)+N_DL_symb*kk+1) = r_l_ns(m1); %参考信号序列映射到复值调制符号(天线端口6)

end

end

end

end

% % different p means different antana port, and the mapping process is different

% %参考于《移动宽带技术》----扇区参考信号定义(p79)

% switch p

%     case 0, %the subframe will go to antana port 0

%         for ns= 2 * sub_index : 2 * sub_index + 1

%             kk=mod(ns,2);

%             l=0;%如果p=0且l=0时,v=0(参考移动宽带技术——扇区参考信号定义)

%             v=0;

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = (6 * m + mod((v + v_shift),6)) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1); %mapping rs to subframe

%             end

%

%             l=N_DL_symb - 3;%N_DL_symb=7

%             v=3;

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = 6 * m + mod((v + v_shift),6) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

%             end

%         end

%     case 1, %the subframe will go to antana port 1

%         for ns= 2 * sub_index : 2 * sub_index + 1

%             kk=mod(ns,2);

%             l=0;

%             v=3;

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = 6 * m + mod((v + v_shift),6) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

%             end

%

%             l=N_DL_symb - 3;

%             v=0;

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = 6 * m + mod((v + v_shift),6) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

%             end

%         end

%     case 2, %the subframe will go to antana port 2

%         for ns= 2 * sub_index : 2 * sub_index + 1

%             kk=mod(ns,2);

%             l=1;

%             v=3*mod(ns,2);

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = 6 * m + mod((v + v_shift),6) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

%             end

%         end

%     case 3, %the subframe will go to antana port 3

%         for ns= 2 * sub_index : 2 * sub_index + 1

%             kk=mod(ns,2);

%             l=1;

%             v=3+3*mod(ns,2);

%             %mod((v + v_shift),6)

%             r_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);% generate rs sequence

%             for m = 0 : 2 * N_DL_RB - 1

%                 m1 = m + N_RB_DL_MAX - N_DL_RB + 1;

%                 k = 6 * m + mod((v + v_shift),6) + 1;

%                 subframe(k,l + N_DL_symb * kk + 1) = r_l_ns(m1);%mapping rs to subframe

%             end

%         end

%     case 6,%the subframe will go to antana port 6

%         for ns= 2 * sub_index : 2 * sub_index + 1

%             kk=mod(ns,2);

%

%     otherwise disp('illagal antana port number p .');

% end

function rs_seq_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);

% *************************************************************************

% Function Description: (v1.0---20090428 by )

%  This function is used for the progress of generation of the reference

%       signal sequence that is needed by cell_specific reference signal

%       in 3GPP LTE.

%

%  usage :

%        rs_seq_l_ns = gen_rs_seq (N_cell_id,N_CP,ns,l);

%

%  input parameter :

%       "N_cell_id" : Physical layer cell identity.

%       "N_CP" : For normal CP,N_CP=1; for extended CP,N_CP=0;

%       "ns" : The slot number within a radio frame

%       "l" : The OFDM symbol number within the slot

%

%  output parameter :

%       "rs_seq_l_ns": the reference_signal sequence needed by 3GPP TDD-LTE

%

%   note :

%       the generalization of the reference signal sequence

%           can be found in Ref.36.211.850

%**************************************************************************

% N_cell_id= 17;

% N_CP = 1;

% ns=1;

% l=4;

%parameter needed,can be found in LTE reference 36.211-850

N_RB_DL_MAX=110;

%generation of gold sequence(生成Gold序列)

gold_seq = gen_gold_seq(N_cell_id,N_CP,ns,l);

%generation of reference sequence(生成参考序列)

rs_seq_l_ns = zeros(1,N_RB_DL_MAX * 2);

for m = 1 : N_RB_DL_MAX * 2

rs_seq_l_ns(m)=(1/sqrt(2)) * ( (1-2*gold_seq(2*m-1)) + (1-2*gold_seq(2*m))*j );

end

function  gold_seq_out = gen_gold_seq (N_cell_id,N_CP,ns,l)

% *************************************************************************

% Function Description: (v1.0---20090428 by )

%  This function is used for the progress of generation of gold sequence

%  that is needed by cell_specific reference signal in 3GPP LTE.

%

%  usage :

%       gold_seq_out = gen_gold_seq (N_cell_id,N_CP,ns,l)

%

%  input parameter(输入参数):

%       "N_cell_id" : Physical layer cell identity.

%       "N_CP" : For normal CP,N_CP=1; for extended CP,N_CP=0;

%       "ns" : The slot number within a radio frame

%       "l" : The OFDM symbol number within the slot

%

%  output parameter :

%       "gold_seq_out": the gold_seq needed by 3GPP TDD-LTE,

%        it starts at c(1601) and with a length of (N_RB_DL_MAX+1)*4

% note :

%       the initialization of the m-sequence can be found in 36.211.850.

%**************************************************************************

% N_cell_id= 17;

% N_CP = 1;

% ns=1;

% l=4;

%parameter needed,can be found in LTE reference 36.211-850

N_RB_DL_MAX=110;

NC=1600;

%generation of the first m-sequence x1.(产生第一个m序列x1)

% the length of x1 needed at least is N_RB_DL_MAX*4+NC

x1=zeros(1,(N_RB_DL_MAX+1)*4+NC);

x1(1)=1;

%the values of x1(32)---x1((N_RB_DL_MAX+1)*4+NC-31)

for k = 1 : (N_RB_DL_MAX+1) * 4 + NC - 31

x1(k+31)=mod((x1(k+3)+x1(k)),2);

end

x1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%generation of the second m-sequence x2.(产生第二个m序列x2)

% the length of x2 needed at least is (N_RB_DL_MAX)*4+NC

x2=zeros(1,(N_RB_DL_MAX+1)*4+NC);

%the initialization of the first 31 values of x2;

x2(1) = N_CP;

for k=1:9

x2(k+1)=bitget(N_cell_id,k); %information of cell id

end

other21bits=(7*(ns+1)+l+1)*(N_cell_id*2+1);

for k=1:21

x2(k+10)=bitget(other21bits,k);  %initialization of the other 21 bits;

end

%the values of x2(32)---x2((N_RB_DL_MAX+1)*4+NC-31)

for k=1:(N_RB_DL_MAX+1)*4+NC-31

x2(k+31)=mod((x2(k+3)+x2(k+2)+x2(k+1)+x2(k)),2);

end

x2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%the generation of the gold sequence cn;

gold_seq_out=zeros(1,(N_RB_DL_MAX+1)*4);

for k=1:(N_RB_DL_MAX+1)*4

gold_seq_out(k)=mod((x1(k+NC)+x2(k+NC)),2);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值