📄 dab_test.m
字号:
% Remove Guard Intervals %
% --------------------------------------------- %
SymDeCP = zeros(NumSubc,NumLoop+2);
SymDeCPtmp = reshape(SymCh,NumIFFT + NumCP,NumLoop+2);
SymDeCP = SymDeCPtmp((NumCP+1+SyncDelay):NumAddPrefix+SyncDelay,:);
% --------------------------------------------- %
% FFT %
% --------------------------------------------- %
% input: SymDeCP(NumSubc,NumLoop); output: SymFFT(NumSubc,NumLoop)
SymFFT = fft(SymDeCP,NumIFFT);
%-----------------------------------------------------
% 分离PRS和NULl 差分解调 解交织
%------------------------------------------------------
SymFFTDe=SymFFT(:,3:NumLoop+2);
SymFFTDe=SymFFTDe((NumIFFT-NumSubc)/2+1:NumIFFT-(NumIFFT-NumSubc)/2+1,:);
RePRStmp=SymFFT(:,2);
RePRS=RePRStmp((NumIFFT-NumSubc)/2+1:NumIFFT-(NumIFFT-NumSubc)/2+1);
ReQpsk(:,1)=SymFFTDe(:,1)./(RePRS+10^-16);
for kk=2:NumLoop
ReQpsk(:,kk)=SymFFTDe(:,kk)./SymFFTDe(:,kk-1)
end
%解交织
Deinterleav=zeros(NumSubc+1,NumLoop);
for kk=1:NumSubc
Deinterleav(kk,:)=ReQpsk(D1(kk),:);
end
Deinterleav=Deinterleav(1:NumSubc,:);
% --------------------------------------------- %
% Make Decision(Include DeQPSK) %
% --------------------------------------------- %
SymDec = zeros(NumSubc,NumLoop);
for m = 1:NumLoop
for n = 1:NumSubc
Real = real(Deinterleav(n,m));
Imag = imag(Deinterleav(n,m));
if( abs((Real -1)) < abs((Real +1)))
SymDec(2*n-1,m) = 0;
else
SymDec(2*n-1,m) = 1;
end
if( abs((Imag -1)) < abs((Imag +1 )) )
SymDec(2*n,m) = 0;
else
SymDec(2*n,m) = 1;
end
end
end
BitsRx = zeros(1,NumSubc*NumLoop);
BitsRx = SymDec(:);
[Num1,Ber1] = symerr(BitsTx,BitsRx);
%--------------------------------------------------------------------------
% 删余填零,维特比解码
%-------------------------------------------------------------------------
%---------------------
% 在相应位填零
%---------------------
punc_output=(reshape(BitsRx,1040,cnv_q))';
for i=1:cnv_q
repunc_tmp=punc_output(i,:);
reVP1=repunc_tmp(1:20*22);
reVP2=repunc_tmp((20*22+1):(28*21+20*22));
reVT=repunc_tmp((20*22+28*21+1):end);
reVP1tmp=(reshape(reVP1,22,20))';
reVP2tmp=(reshape(reVP2,21,28))';
a=0;b=0;c=0;
depunc_VP1=zeros(20,32);
depunc_VP2=zeros(28,32);
depunc_VT=zeros(1,24);
for j=1:32
if VP1(j)==1
a=a+1;
depunc_VP1(:,j)=reVP1tmp(:,a);
end
end
for j=1:32
if VP2(j)==1
b=b+1;
depunc_VP2(:,j)=reVP2tmp(:,b);
end
end
for j=1:24
if VT(j)==1
c=c+1;
depunc_VT(j)=reVT(c);
end
end
depunc_VP1tmp=(depunc_VP1)';
depunc_VP2tmp=(depunc_VP2)';
depunc_VP1tmp=reshape(depunc_VP1tmp,1,20*32);%变行向量
depunc_VP2tmp=reshape(depunc_VP2tmp,1,28*32);
depunc_out(i,:)=[depunc_VP1tmp depunc_VP2tmp depunc_VT];%结果是row 为单位的
end
depunc_outtmp=depunc_out';
depunc_outcolumn=depunc_outtmp(:);
recnv_output=depunc_outcolumn';
%----------------------------
% 维特比解码以VP1,VP2,VT组成联合删余向量情况下进行)
%----------------------------
G=cnv_g;k=cnv_k0;channel_output=recnv_output;
%定义新的删余向量,以1560位单位删余20*32+28*32+24
VP1S=[VP1 VP1 VP1 VP1 VP1];
VP1S=[VP1S VP1S VP1S VP1S];
VP2S=[VP2 VP2 VP2 VP2 VP2 VP2 VP2];
VP2S=[VP2S VP2S VP2S VP2S];
P=[VP1S VP2S VT];
n=size(G,1);
[r,c]=size(P);
punc=reshape(P,1,r*c);
position_P0=find(~punc); %取0的位置如P=[1 1;1 0];position_P0=4,未用到
% check the sizes
if rem(size(G,2),k) ~=0
error('Size of G and k do not agree')
end
if rem(size(channel_output,2),n) ~=0
error('channel output not of the right size')
end
L=size(G,2)/k;
number_of_states=2^((L-1)*k);
% generate state transition matrix, output matrix, and input matrix
for j=0:number_of_states-1
for l=0:2^k-1
[next_state,memory_contents]=nxt_stat(j,l,L,k);
input(j+1,next_state+1)=l;
branch_output=rem(memory_contents*G',2);
nextstate(j+1,l+1)=next_state;
output(j+1,l+1)=bin2deci(branch_output);
end
end
state_metric=zeros(number_of_states,2);
depth_of_trellis=length(channel_output)/n;
channel_output_matrix=reshape(channel_output,n,depth_of_trellis);
survivor_state=zeros(number_of_states,depth_of_trellis+1);
% start decoding of non-tail channel outputs
for i=1:depth_of_trellis-L+1
flag=zeros(1,number_of_states);
if i <= L
step=2^((L-i)*k);
else
step=1;
end
for j=0:step:number_of_states-1
for l=0:2^k-1
branch_metric=0;
binary_output=deci2bin(output(j+1,l+1),n);
for ll=1:n
%if (rem(i,2)==0) &(ll==2) %判断是否是删除的位置,若是,则metric=0;不是,则计算metric
if (rem(i+1,3)==0) &(ll==2) | (rem(i+0,3)==0) &(ll==2)
branch_metric=branch_metric+0;
else
branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));
end
% branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));
end
if((state_metric(nextstate(j+1,l+1)+1,2) > state_metric(j+1,1)...
+branch_metric) | flag(nextstate(j+1,l+1)+1)==0)
state_metric(nextstate(j+1,l+1)+1,2) = state_metric(j+1,1)+branch_metric;
survivor_state(nextstate(j+1,l+1)+1,i+1)=j;
flag(nextstate(j+1,l+1)+1)=1;
end
end
end
state_metric=state_metric(:,2:-1:1);
end
% start decoding of the tail channel-outputs
for i=depth_of_trellis-L+2:depth_of_trellis
flag=zeros(1,number_of_states);
last_stop=number_of_states/(2^((i-depth_of_trellis+L-2)*k));
for j=0:last_stop-1
branch_metric=0;
binary_output=deci2bin(output(j+1,1),n);
for ll=1:n
%if (rem(i,2)==0) &(ll==2) %rc=2/3
if (rem(i+1,3)==0) &(ll==2) | (rem(i+0,3)==0) &(ll==2) %rc=3/4
branch_metric=branch_metric+0;
else
branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));
end
% branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));
end
if((state_metric(nextstate(j+1,1)+1,2) > state_metric(j+1,1)...
+branch_metric) | flag(nextstate(j+1,1)+1)==0)
state_metric(nextstate(j+1,1)+1,2) = state_metric(j+1,1)+branch_metric;
survivor_state(nextstate(j+1,1)+1,i+1)=j;
flag(nextstate(j+1,1)+1)=1;
end
end
state_metric=state_metric(:,2:-1:1);
end
% generate the decoder output from the optimal path
state_sequence=zeros(1,depth_of_trellis+1);
state_sequence(1,depth_of_trellis)=survivor_state(1,depth_of_trellis+1);
for i=1:depth_of_trellis
state_sequence(1,depth_of_trellis-i+1)=survivor_state((state_sequence(1,depth_of_trellis+2-i)...
+1),depth_of_trellis-i+2);
end
decodeder_output_matrix=zeros(k,depth_of_trellis-L+1);
for i=1:depth_of_trellis-L+1
dec_output_deci=input(state_sequence(1,i)+1,state_sequence(1,i+1)+1);
dec_output_bin=deci2bin(dec_output_deci,k);
decoder_output_matrix(:,i)=dec_output_bin(k:-1:1)';
end
decoder_output=reshape(decoder_output_matrix,1,k*(depth_of_trellis-L+1));
recnv_input=decoder_output;
% [Num2,Ber2] = symerr(cnv_input,recnv_input);
% 每隔384位去掉l-1个零点
receive_input=recnv_input(1:384);
for i=1:cnv_q-1
receive_input=[receive_input recnv_input(i*(384+7-1)+1:i*(384+7-1)+384)]
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -