?? multi_awgn_vita_123encoded_bib_all2_wdiv2.m
字號(hào):
%function pb=multi_awgn_vita(Eb_to_Nj_in_dB,Eb_to_No_in_dB,BPH,number_of_states,Q)
%VITERBI This program simulates the Viterbi sequnce decoding of the
% differential frequency hopping system with
% (2,1,3) convolutional coding and divisity of level 2
%
% Eb_to_Nj_in_dB is the signal-to-jamming ratio given in dB
%
% Eb_to_No_in_dB is the signal-to-noise ratio given in dB
%
% BPH is the number of bits transmitted by one hop
%
% number_of_states is the number of states in the DFH
% trellis,corresponding to the right L stages of the DFH encoding
% shift register
%
% Q is the number of jamming tones in the DFH bandwidth
%
% 這個(gè)程序是正確的,帶(n,k,K)=(1,2,3)的卷積糾錯(cuò)碼,編碼后在后面只補(bǔ)上L個(gè)0,即符號(hào)流總長(zhǎng)度是2N+L而不是2(N+L),
%
% 這個(gè)程序是帶(1,2,3)的卷積糾錯(cuò)碼并且加了基于比特的分組(block)交織
%
%********系統(tǒng)參數(shù)********%
% Eb_to_Nj_in_dB=8;
Eb_to_Nj_in_dB=[0,1,2];
Eb_to_No_in_dB=13.35;
BPH=2;
number_of_states=16;
Q=2; % 干擾音的個(gè)數(shù)
N=1000; % 每次符號(hào)流長(zhǎng)度
times=10; % 重復(fù)做500次
PB_all=zeros(length(Eb_to_Nj_in_dB),1);
num_of_err=zeros(length(Eb_to_Nj_in_dB),times);
%************************%
WTbarpp=waitbar(0,'Outer SNRs Loop:Please Wait...');
for pp=1:length(Eb_to_Nj_in_dB)
fanout=2^BPH; % DFH的扇出系數(shù)
Eb_to_Nj=10^(Eb_to_Nj_in_dB(pp)/10); % 比值形式的Eb/Nj
Eb_to_No=10^(Eb_to_No_in_dB/10); % 比值形式的Eb/No
L=floor(log(number_of_states)/log(fanout)); % 編碼移位寄存器的長(zhǎng)度為L(zhǎng)+1,最右邊L級(jí)是其狀態(tài)位,與網(wǎng)格圖中的狀態(tài)一一對(duì)應(yīng)(注意并不是與跳頻頻點(diǎn)一一對(duì)應(yīng))
% num_of_err=zeros(1,times);
% pb=zeros(1,times);
WTbar=waitbar(0,'SNR inside loop:please wait for a moment...');
for rep=1:times
% source=[randint(1,N,fanout),zeros(1,L)]; % 信息源:(注意不是10進(jìn)制的,而是fanout進(jìn)制的)隨機(jī)符號(hào)流,最后補(bǔ)上L個(gè)0符號(hào),使移位寄存器的狀態(tài)清零
source=randint(1,N,fanout);
%***********************信源部分************************%
% 將信息符號(hào)流轉(zhuǎn)化成二進(jìn)制信息比特流
dsource=zeros(1,N*BPH);
if(BPH~=1)
for i=1:N
dsource((i-1)*BPH+1:i*BPH)=deci2change(source(i),BPH,2);
end
else
dsource=source(1:N);%*****
end
%******************************************************%
% % *******************差錯(cuò)控制編碼部分(8,4)碼**********************%
% % G=[1 0 0 0 1 0 1 1;
% % 0 1 0 0 1 1 1 0;
% % 0 0 1 0 1 1 0 1;
% % 0 0 0 1 0 1 1 1];
% G=[1 0 0 0 1 0 1 1;0 1 0 0 1 1 0 1;0 0 1 0 0 1 1 1;0 0 0 1 1 1 1 0]; % (8,4,4)擴(kuò)展?jié)h明碼的生成矩陣G
% % H=[1 1 1 1 1 1 1 1;1 1 0 1 1 0 0 0;0 1 1 1 0 1 0 0;1 0 1 1 0 0 1 0]; % (8,4,4)擴(kuò)展?jié)h明碼的一致校驗(yàn)矩陣H
% % trt=syndtable(H); % (8,4,4)擴(kuò)展?jié)h明碼的伴隨式譯碼表
% dsource_coded=encode(dsource,8,4,'linear',G)';
% % source_coded0=zeros(1,2*N);
% % *****************************************************************%
% *******************差錯(cuò)控制編碼部分(n,k,K)=(1,2,3)卷積碼**********************%
KK=3; %卷積碼的約束長(zhǎng)度K=3
trel=poly2trellis(KK,[7,5]); % 卷積碼的網(wǎng)格圖trel
dsource_coded=convenc(dsource,trel,0);
% *****************************************************************%
% *********************交織部分(塊交織)(基于比特的交織)****************%
% 僅適用于BPH=2且N=1000時(shí)
interleave_outcome=zeros(1,2*BPH*N);
A1=zeros(200,200);
for i=1:2*BPH*N
A1(i)=dsource_coded(i);
end
A=A1.';
for i=1:2*BPH*N
interleave_outcome(i)=A(i);
end
%************************************************%
% % *******************隨機(jī)交織************************%
% [interleave_outcome,alpha]=interleave(dsource_coded); % dsource_coded 長(zhǎng)度為(n/k)*N*BPH=2*N*BPH
%
% % ***************************************************%
% 編碼和交織后將二進(jìn)制序列轉(zhuǎn)換成十進(jìn)制序列,準(zhǔn)備輸入到G函數(shù)進(jìn)行映射
if (BPH~=1)
for i=1:2*N
register=interleave_outcome((i-1)*BPH+1:i*BPH);
source_coded_ba0(i)=change2deci(register,2);
end
else
source_coded_ba0=interleave_outcome(1:2*N);% source_coded_ba0 是行矢量,source_coded_ba0是編碼輸出十進(jìn)制符號(hào)序列,長(zhǎng)度為2N個(gè)符號(hào)(補(bǔ)2L個(gè)0符號(hào)之前)
end
source_coded=[source_coded_ba0,zeros(1,L)];% G函數(shù)映射前補(bǔ)上L個(gè)0符號(hào)
% ******************* G 函數(shù)實(shí)現(xiàn)部分 ************************ %
% 先定義三個(gè)關(guān)鍵矩陣"nextstates" "output" "input"
nextstate=zeros(number_of_states,fanout); % nextstate矩陣:行代表網(wǎng)格圖中的各狀態(tài)(一一對(duì)應(yīng)),列與輸入移位寄存器的信息符號(hào)一一對(duì)應(yīng),
% 矩陣中存儲(chǔ)的內(nèi)容是與當(dāng)前狀態(tài)和輸入符號(hào)對(duì)應(yīng)的下一狀態(tài)號(hào)(即存儲(chǔ)網(wǎng)格圖的狀態(tài)轉(zhuǎn)移規(guī)則)
output=zeros(number_of_states,fanout); % output矩陣:行代表網(wǎng)格圖中的各狀態(tài)(一一對(duì)應(yīng)),列與輸入移位寄存器的信息符號(hào)一一對(duì)應(yīng),
% 矩陣中存儲(chǔ)的內(nèi)容是與當(dāng)前狀態(tài)和輸入符號(hào)對(duì)應(yīng)的網(wǎng)格圖分支轉(zhuǎn)移輸出(分支轉(zhuǎn)移輸出是跳頻頻率號(hào))
input=zeros(number_of_states,number_of_states);
number_of_out=number_of_states*fanout;% 跳頻頻點(diǎn)數(shù)Nt
for i=0:number_of_states-1
for j=0:fanout-1
[next_state,out_put]=G_func1(i,j,L,fanout);
nextstate(i+1,j+1)=next_state;
output(i+1,j+1)=out_put;
input(i+1,next_state+1)=j;
end
end
% ********************************************************* %
% ********************維特比譯碼部分**********************%
depth_of_trellis=length(source_coded);%*******************
Eb=1;
Es=Eb*BPH*(1/2);
diversi=2; % 2重分集
Ec=Es/diversi;% 分集后每個(gè)分集碼片的能量
% Ej0=(Eb*number_of_out*Q)/(Eb_to_Nj);% 每個(gè)多音干擾的能量Ej0
Ej0=(Es*number_of_out)/(BPH*Q*Eb_to_Nj); % 每跳時(shí)間內(nèi)每個(gè)多音干擾的能量Ej0
sgma=sqrt(Eb/(2*Eb_to_No));% AWGN的均方根
demod_input=zeros(number_of_out,depth_of_trellis);
f=zeros(1,depth_of_trellis);
% rc=zeros(1,number_of_out);% 移到下面去了
% rs=zeros(1,number_of_out);
D=0; % D 記錄網(wǎng)格圖的當(dāng)前狀態(tài),這里初始狀態(tài)是0狀態(tài)
% % *******************信道和非相干解調(diào)部分:加多音干擾和噪聲,然后非相干解調(diào)****************** %
% for i=1:depth_of_trellis % i表示網(wǎng)格圖的時(shí)間走勢(shì)
% f(i)=output(D+1,source_coded(i)+1); % f(i)是i時(shí)刻的分支轉(zhuǎn)移輸出,即i時(shí)刻的跳頻頻率號(hào),頻率號(hào)范圍是[0,number_of_out-1]而不是[1,number_of_out]
% thyta=2*pi*rand;% 干擾音與跳頻信號(hào)的相對(duì)相位
% % J=randint(1,Q,number_of_out); % J 矩陣中存放Q個(gè)干擾音所在的頻率號(hào),干擾音所在頻率號(hào)范圍也是[0,number_of_out-1]而不是[1,number_of_out]
% J=gen_multijammer(Q,number_of_out);% J 矩陣中存放Q個(gè)干擾音所在的頻率號(hào),干擾音所在頻率號(hào)范圍也是[0,number_of_out-1]而不是[1,number_of_out]
% for j=0:number_of_out-1
% if (j==f(i))
% rc(j+1)=sqrt(Es)+sgma*randn;
% rs(j+1)=sgma*randn;
% else
% rc(j+1)=sgma*randn;
% rs(j+1)=sgma*randn;
% end
% end
% for k=1:Q
% for j=0:number_of_out-1
% if (j==J(k))
% rc(j+1)=rc(j+1)+sqrt(Ej0)*cos(thyta);
% rs(j+1)=rs(j+1)+sqrt(Ej0)*sin(thyta);
% end
% end
% end
% for j=0:number_of_out-1
% demod_input(j+1,i)=sqrt(rc(j+1)^2+rs(j+1)^2);
% end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -