lab24b.m

来自「再不同传输环境下」· M 代码 · 共 55 行

M
55
字号

function [ber, numBits] = bertooltemplate(EbNo, maxNumErrs, maxNumBits)
% Import Java class for BERTool.
import com.mathworks.toolbox.comm.BERTool;

% Initialize variables related to exit criteria.
totErr = 0;  % Number of errors observed
numBits = 0; % Number of bits processed

% --- Set up parameters. ---
% --- INSERT YOUR CODE HERE.
N_symbols = 10000; % Number of symbols in the calculation
M=32;
N_samples_per_symbol=8;
% Simulate until number of errors exceeds maxNumErrs
% or number of bits processed exceeds maxNumBits.
while((totErr < maxNumErrs) && (numBits < maxNumBits))

   % Check if the user clicked the Stop button of BERTool.
   if (BERTool.getSimulationStop)
      break;
   end

   % --- Proceed with simulation.
   % --- Be sure to update totErr and numBits.
   % --- INSERT YOUR CODE HERE.
    % genere data
    x=randsrc(N_symbols,1,0:M-1);
    %Modulation 32QAM
    y=qammod(x,M,0,'gray');
    %calcule SNR
    SNR = EbNo + 10*log10(log2(M)) - 10*log10(N_samples_per_symbol);
    %genre rectpulse
    ytx=rectpulse(y,N_samples_per_symbol);
    %Ajoute le bruit
    yrx=awgn(ytx,SNR,'measured');%%Channel type
    
    %intdump au reception
    ymf=intdump(yrx,N_samples_per_symbol);
    %Demodulation
    x_estimate=qamdemod(ymf,M,0,'gray');
    
    %calcule nombre d'erreurs
    [number_of_errors,bit_error_rate] = biterr(x,x_estimate);
    
     %% Update totErr and numBits.
   totErr = totErr + number_of_errors;
   numBits = numBits + N_symbols*log2(M) ;

    
end % End of loop

% Compute the BER.
ber = totErr/numBits;

⌨️ 快捷键说明

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