⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplemeritber.m

📁 无线移动信道的matlab源码 用于对无线通信信道的编程实现
💻 M
字号:
clear all;
diary simplemeritber.text

SNRpSym=linspace(1,10,10);
% Initalize sampling times, oversampling rate, modulation.
Fd = 1; Fs = 1; N = Fs/Fd; modulation = 'psk';

% Define alphabet (quaternary). Signal to Noise ratio (SNR).
% Change M to 2 to get results for BPSK instead of QPSK
M = 2; k = log2(M); 

iters =1;

% Set random number seeds for uniform and Gaussian noise
rand('state', 123456789);  randn('state', 987654321);

% Create Gray encoding and decoding arrays
grayencod	= bitxor([0:M-1],floor([0:M-1]/2));
[dummy graydecod] = sort(grayencod);  graydecod = graydecod - 1;
for (idx2 = [1:length(SNRpSym)])
 idx = 1;
 errBit=0;ratBit=0;
    while ((idx <= iters))
        % code rate
        rate=1/2;
        reciprate=1/rate;
        R=4800;
        data=randint(1,R);
        codeout=encoder(data,rate);
        I=15;
        Icol=100; % the column of the interleaver 
        Insize=Icol*I;
        tt=mod(length(codeout),Insize);
        code=[];
        if tt~=0
            code=[codeout zeros(1,Insize-tt)];
        else code=codeout;
        end  
        Ntt=ceil(length(code)/Insize);
        % frequecy interleaver
        datare=reshape(code,Insize,Ntt);
        datainter=zeros(Insize,Ntt);
        for ii=1:Ntt
            datainter(:,ii)=transpose(rectan_interleaver(transpose(datare(:,ii)),I,Icol));
        end
        datainterout=reshape(datainter,1,Insize*Ntt);
%           % Generate random numbers from in the range [0,M-1]
%         msg_orig = randsrc(datainterout,1,[0:M-1]);
        msg_orig=datainterout;
        % Gray encode symbols
        msg_gr_orig = grayencod(msg_orig+1)';

        % Digitally modulate and upsample the signal
        msg_tx  = dmodce(msg_gr_orig, Fd, Fs, modulation, M);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%channel%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% METHOD='es_j';
% N_i1=15;
% f_max=48;   %f_max*Tb=0.01
% PHASE='rand';
% PLOT=1;
% sigma_0_2=1/2;%the avarage power of the u1(t) and the u2(t) is 1
% T_s=1/length(msg_tx);
% T_sim=1;
% % rho=0.9856;
% K=7;           % dB K=10*log10(A^2/(2*sigma2))
% rho=sqrt(2*10^(K/10));
% % f_rho=0.7326*f_max;
% f_rho=0;
% % theta_rho=rand(1,1)*2*pi;
% theta_rho=0;
% [f_i_n,c_i_n,theta_i_n]=parameter_Jakes(METHOD,N_i1,sigma_0_2,f_max,PHASE,0);
% N_i2=16;
% [f_i_n1,c_i_n1,theta_i_n1]=parameter_Jakes(METHOD,N_i2,sigma_0_2,f_max,PHASE,0);
% mu_i_t2=Mu_i_t(c_i_n1,f_i_n1,theta_i_n1,T_s,T_sim,0);
% xi_t=Rice_proc(c_i_n,f_i_n,theta_i_n,f_i_n1,c_i_n1,theta_i_n1,rho,f_rho,theta_rho,T_s,T_sim,0);
%         y_t=transpose(msg_tx).*xi_t;

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sigma_0_2=0.2774;
% kappa_0=0.506;
% theta_0=30;
% sigma_3=0.0905;
% m_3=0.0439;
% f_c=1e6;
% T_s=1/length(msg_tx);
% T_sim=1;
% f_max=48;
% rho=0.1118;
% f_rho=0.6366*f_max;
% theta_rho=rand(1,1)*2*pi;
% 
% xi_t=Suzuki_Type_II(25,15,sigma_0_2,kappa_0,theta_0,f_max,...
%                    sigma_3,m_3,rho,theta_rho,f_c,T_s,T_sim,0);
%         y_t=transpose(msg_tx).*xi_t;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
% f_max=48;
% xi_t = rayleigh( f_max, 10000, length(msg_tx));
%         y_t=transpose(msg_tx).*xi_t;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f_max=48;
   m_s=1;t_0=0;
       [C1,F1,TH1,C2,F2,TH2,F01,F02,RHO,F_RHO,q_l,T]=F_S_K_p(15,'tu',f_max);
       [y_t,T,t_0]=F_S_K(msg_tx,f_max,m_s,T,t_0,q_l,C1,F1,TH1,C2,F2,TH2,F01,F02,RHO,F_RHO,0); 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         % Add Gaussian noise to the signal.  The noise signal is calibrated using
        % the 'measured' option.  The noise power is scaled for oversampling.
        msg_rx  = awgn(y_t, SNRpSym(idx2), 'measured', [], 'dB');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % Demodulate, detect, and downsample the signal
        msg_gr_demod = ddemodce(msg_rx, Fd, Fs, modulation, M);

        % Gray decode message
        msg_demod = graydecod(msg_gr_demod+1)';
          Qpsk=[0:M-1]';
         demod_out=[];
         for n=1:length(msg_demod)
%            
             [A,B]=min(abs(real(msg_demod(n))*ones(M,1)-Qpsk)); 
             
             demod_out(1,(n-1)*k+1:n*k)=de2bi(B-1,k,'left-msb');
             
         end
        
        %%%%%%%%deinterleaver%%%%%%%%%%%%%%%%%%%%%%%
        datadeinter=reshape(demod_out,Insize,Ntt);
        datadeinterout=zeros(Insize,Ntt);
        for ii=1:Ntt
            datadeinterout(:,ii)=transpose(d_rectan_interleaver(transpose(datadeinter(:,ii)),I,Icol));
        end
        datadeinterf=reshape(datadeinterout,1,Insize*Ntt);
        deco=datadeinterf(1:length(codeout));
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        decoded=decoder(deco,rate);
        % calculate bit error count, BER, symbol error count and SER, for this iteration.
        
        [err rat] = biterr(decoded,data);
        errBit=errBit+err;
      

        % Increment for next iteration, pause to allow <ctrl-C> break
        idx = idx + 1;   pause(.1);
    end

    % average the errors and error ratios for the iterations.
%     errors(idx2,:) = [sum(errBit)];
%     ratio(idx2,:)  = [mean(ratBit)];
      ratBit=errBit/((idx-1)*R);
    % Plot the simulated results for SER and BER.
   
     % Plot the simulated results for SER and BER.
    fprintf('**************multipath channel I=45**************\n');

    fprintf('************** Es/N0 = %5.2f db fmax=%d **************\n',SNRpSym(idx2),f_max);
         fprintf('totalerror=%d,   totalber=%8.4e \n',errBit,ratBit);
         

    fprintf('***********************************************\n\n');
end

diary off

⌨️ 快捷键说明

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