map_simu.asv

来自「短波信道抗多音干扰的性能分析及其仿真」· ASV 代码 · 共 95 行

ASV
95
字号
function pb=map_simu(BPH,number_of_states,n,rho_in_dB)
% this function simulates the MAP demodulation
% progress of the DFH system
% BPH:the number of bits per hop
% number_of_states:the number of frequency slots
% n:correlation interval
% rho_in_dB:SNR in dB

rho=10^(rho_in_dB/10);
N=10000;
fanout=2^BPH;
L=floor(log(number_of_states)/log(fanout));
source=randint(1,BPH*N);
source1=reshape(source,BPH,N);
dsource1=zeros(1,N);
dource1=
for i=1:N
    dsource1(i)=change2deci(source1(:,i)',2);
end
dsource=zeros(1,N+n-1);
dsource=[dsource1,randint(1,n-1,fanout)]; %generate info source
depth_of_trellis=length(dsource);

f=zeros(1,depth_of_trellis); %G-function generates frequency sequence 
D=0;
for i=1:depth_of_trellis
    f(i)=G_func(D,dsource(i),L,fanout);
    D=f(i);
end

E=1;
sgma=sqrt(E/(BPH*2*rho));
demod_input=zeros(number_of_states,depth_of_trellis); %simulate the FFT output 
for i=1:depth_of_trellis
    for j=0:number_of_states-1
        if(j~=f(i))
           rc=sgma*randn;
           rs=sgma*randn;
       else
           rc=sqrt(E)+sgma*randn;
           rs=sgma*randn;
       end
       demod_input(j+1,i)=rc^2+rs^2;
   end
end

nextstate=zeros(number_of_states,fanout); % derive the state trasfer matrix
for i=0:number_of_states-1
    for j=0:fanout-1
        next_state=G_func(i,j,L,fanout);
        nextstate(i+1,j+1)=next_state;
    end
end 

state_metric=zeros(fanout^(n),1); % metric matrix for decision
%decis=zeros(1,N);  % decision output
symbol_matrix=zeros(fanout^(n),n); % the whole possible input sequence
decision=zeros(1,BPH*N);

for i=1:fanout^(n)           % generate the whole possible input sequence
    symbol_matrix(i,:)=deci2change(i-1,n,fanout);
end

latest_state=0;  % the last state of every input sequence
mid_state=zeros(fanout^(n),n); % the middle state of every number in a sequence

for i=1:depth_of_trellis-n+1   % start to demodulate
    for j=1:fanout^(n)         %derive the middle state
        middlestate=latest_state;
        for k=1:n
            mid_state(j,k)=nextstate(middlestate+1,symbol_matrix(j,k)+1);
            middlestate=mid_state(j,k);
        end
    end
    
    for j=1:fanout^(n)   % compute the metrics using FFT output
        for k=i:i+n-1
            state_metric(j)=state_metric(j)+demod_input(mid_state(j,k-i+1)+1,k);
        end
    end
    
    [C,I]=max((sum(reshape(state_metric,fanout^(n-1),fanout)))'); % decision making
    %decis(i)=I-1;
    decision((i-1)*BPH+1:i*BPH)=deci2change(I-1,BPH,fanout);
    latest_state=nextstate(latest_state+1,I); % change the last state
    state_metric=zeros(fanout^(n),1); % initial state_metric for the next compute
end

num_of_err=0;  % symbol error counting
for i=1:length(source)
    if(source(i)~=decision(i))
       num_of_err=num_of_err+1;
   end
end
pb=num_of_err/length(source); % bit error probability

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?