?? multi_rayleigh_vita_213encoded_all_wdiv2.m
字號:
%function pb=multi_rayleigh_vita_213encoded_all(Eb_to_Nj_in_dB,Eb_to_No_in_dB,BPH,number_of_states,Q)
%VITERBI This program simulates the Viterbi sequnce detection of the
% differential frequency hopping system with diversity 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
%
% 這個程序是正確的,帶(n,k,K)=(1,2,3)的卷積糾錯碼,編碼后在后面只補上L個0,即符號流總長度是2N+L而不是2(N+L),
%
% 這個程序是帶(1,2,3)的卷積糾錯碼并且加了基于比特的分組(block)交織
%
%********系統參數********%
Eb_to_Nj_in_dB=[12,15,18];
Eb_to_No_in_dB=13.35;
BPH=2;
number_of_states=16;
Q=4; % 干擾音的個數
N=1000; % 每次符號流長度
times=500; % 重復做500次
PB_all=zeros(length(Eb_to_Nj_in_dB),1);
vita_symbol_err=zeros(length(Eb_to_Nj_in_dB),times);% 維特比譯碼后, (8,4) 譯碼之前2^BPH=4進制符號錯誤個數計數器
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的扇出系數
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)); % 編碼移位寄存器的長度為L+1,最右邊L級是其狀態位,與網格圖中的狀態一一對應(注意并不是與跳頻頻點一一對應)
% num_of_err=zeros(1,times);
% pb=zeros(1,times);
WTbar=waitbar(0,'SNR inside loop:please wait...');
for rep=1:times
% source=[randint(1,N,fanout),zeros(1,L)]; % 信息源:(注意不是10進制的,而是fanout進制的)隨機符號流,最后補上L個0符號,使移位寄存器的狀態清零
source=randint(1,N,fanout);
%***********************信源部分************************%
% 將信息符號流轉化成二進制信息比特流
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
%******************************************************%
% *******************差錯控制編碼部分(n,k,K)=(1,2,3)卷積碼**********************%
KK=3; %卷積碼的約束長度K=3
trel=poly2trellis(KK,[7,5]); % 卷積碼的網格圖trel
dsource_coded=convenc(dsource,trel,0);
% *****************************************************************%
% *********************交織部分(塊交織)(基于比特的交織)****************%
% 僅適用于BPH=2且N=1000時
interleave_outcome=zeros(1,2*BPH*N);
A1=zeros(50,80);
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
%************************************************%
% % *******************隨機交織************************%
% [interleave_outcome,alpha]=interleave(dsource_coded); % dsource_coded 長度為(n/k)*N*BPH=2*N*BPH
%
% % ***************************************************%
% 編碼和交織后將二進制序列轉換成十進制序列,準備輸入到G函數進行映射
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是編碼輸出十進制符號序列,長度為2N個符號(補2L個0符號之前)
end
source_coded=[source_coded_ba0,zeros(1,L)];% G函數映射前補上L個0符號
% ******************* G 函數實現部分 ************************ %
% 先定義三個關鍵矩陣"nextstates" "output" "input"
nextstate=zeros(number_of_states,fanout); % nextstate矩陣:行代表網格圖中的各狀態(一一對應),列與輸入移位寄存器的信息符號一一對應,
% 矩陣中存儲的內容是與當前狀態和輸入符號對應的下一狀態號(即存儲網格圖的狀態轉移規則)
output=zeros(number_of_states,fanout); % output矩陣:行代表網格圖中的各狀態(一一對應),列與輸入移位寄存器的信息符號一一對應,
% 矩陣中存儲的內容是與當前狀態和輸入符號對應的網格圖分支轉移輸出(分支轉移輸出是跳頻頻率號)
input=zeros(number_of_states,number_of_states);
number_of_out=number_of_states*fanout;% 跳頻頻點數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; % 分集后每個分集碼片的能量
% Ej0=(Eb*number_of_out*Q)/(Eb_to_Nj);% 每個多音干擾的能量Ej0
Ej0=(Es*number_of_out)/(BPH*Q*Eb_to_Nj); % 每跳時間內每個多音干擾的能量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 記錄網格圖的當前狀態,這里初始狀態是0狀態
% % *******************信道和非相干解調部分:加多音干擾和噪聲,然后非相干解調****************** %
% for i=1:depth_of_trellis % i表示網格圖的時間走勢
% f(i)=output(D+1,source_coded(i)+1); % f(i)是i時刻的分支轉移輸出,即i時刻的跳頻頻率號,頻率號范圍是[0,number_of_out-1]而不是[1,number_of_out]
% theta=2*pi*rand;% 干擾音與跳頻信號的相對相位
% % J=randint(1,Q,number_of_out); % J 矩陣中存放Q個干擾音所在的頻率號,干擾音所在頻率號范圍也是[0,number_of_out-1]而不是[1,number_of_out]
% J=gen_multijammer(Q,number_of_out);% J 矩陣中存放Q個干擾音所在的頻率號,干擾音所在頻率號范圍也是[0,number_of_out-1]而不是[1,number_of_out]
% for j=0:number_of_out-1
% if (j==f(i))
% rc(j+1)=raylrnd(sqrt(Es))+sgma*randn;% 改了,原來是sqrt(Es)+sgma*randn,信號幅度服從瑞利分布,瑞利分布的參數是sqrt(Es)*222222222222222222222222*
% rs(j+1)=sgma*randn;
% else
% rc(j+1)=sgma*randn;
% rs(j+1)=sgma*randn;
% end
% end
% jam_rayleigh=raylrnd(sqrt(Ej0));% 干擾音的幅度服從瑞利分布,瑞利分布的參數是sqrt(Ej0)*222222222222222222222222222222222222222222222222222222222222222*
% for k=1:Q
% for j=0:number_of_out-1
% if (j==J(k))
% rc(j+1)=rc(j+1)+jam_rayleigh*cos(theta);%改了,原來是rc(j+1)+sqrt(Ej0)*cos(thyta)*2222222222222222222222222222222222222222222222222222222222*
% rs(j+1)=rs(j+1)+jam_rayleigh*sin(theta);%改了,原來是rs(j+1)+sqrt(Ej0)*sin(thyta)*2222222222222222222222222222222222222222222222222222222222*
% 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
% D=nextstate(D+1,source_coded(i)+1);
% end
%
% % *************** End of the Rayleigh Fading Channel and Noncoherent Modulation Modular *************** %
% *******************信道和非相干解調部分:加多音干擾和噪聲,然后非相干解調,得到解調輸出即維特比譯碼器的輸入****************** %
for i=1:depth_of_trellis % i表示網格圖的時間走勢
f(i)=output(D+1,source_coded(i)+1); % f(i)是i時刻的分支轉移輸出,即i時刻輸出的跳頻頻率號
rc1=zeros(1,number_of_out);% 每次搞完一跳后都把rc數組清零,準備存放下一跳的相關解調器輸出數據,第1個分集chip的rc
rc2=zeros(1,number_of_out);% 第2個分集chip的rc,當然也可以把rc定義為分集重數diversi那么多行,number_of_out那么多列的一個矩陣,可能會更簡練一些
rs1=zeros(1,number_of_out);% 每次搞完一跳后都把rs數組清零,準備存放下一跳的相關解調器輸出數據,第1個分集chip的rs
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -