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

📄 awgn_binrs753.m

📁 详细讲述纠错码的书籍
💻 M
字号:
% Name: AWGN_binRS753.m
% Date: December 12, 2005
% Description:
% Simulation of an RS (7,5,3) code over an AWGN channel.
%
% Copyright (c) 2006. Robert Morelos-Zaragoza. All rights reserved.

clear
m = 3;                                      % Galois field GF(2^m)
m2 = 2^m;
pol=[1 0 1 1];
pold = 13;
alpha = gf(2,m,pold);                       % Primitive element of GF(2^m)
for i=1:m2-1;
    a(i,:) = gftuple(i-1,pol,2);
end
a(m2,:) = gftuple(zeros(1,m),pol,2);        % Zero treated specially

n = 7;                                      % RS block length
k = 5;                                      % RS message symbols
rate = k/n;                                 % RS code rate
nsim = 30000;                               % Number of simulations
SNRinit =  0;
SNRinc = 1;
SNRfinal = 8;
SNR = [];
P2 = [];
seed = 12751;
rand('state',seed);
randn('state',seed);

for SNRdB = SNRinit:SNRinc:SNRfinal
    TotalNumError = 0;
    TotalN = 0;
    SNRdBs = SNRdB + 10*log(rate)/log(10);
    No = (10.^(-SNRdBs/10));
    Var = No/2;                             % Noise in dBW, Eb=1
    sigma = sqrt(Var);
    for Nsimulation = 1:nsim
        % Print progress ...
        if mod(Nsimulation,20) == 0
            fprintf('.');
            if mod(Nsimulation,1000) == 0
                fprintf('\n');
            end
        end

        % Random bits
        bin_data = randint(m,k,[0,1])';

        % ****************      REED-SOLOMON ENCODING     ****************
        y = rsenco(bin_data,n,k);       % M binary RS codewords

        z = -2*y+1;                     % BPSK modulation

        % ********************          AWGN          ********************
        z = z+sqrt(Var)*randn(n,m);

        % ********************    HARD DECISIONS      ********************
        bin_eRS = (1-sign(z))/2;

        % ****************      REED-SOLOMON DECODING     ****************
        bin_uhatRS = rsdeco(bin_eRS,n,k);

        errors = sum(sum(xor(bin_uhatRS,bin_data))); % Compare previous
        TotalNumError = TotalNumError + errors;
        TotalN = TotalN + k*m;
    end
    P1 = TotalNumError/TotalN;                    % Find the bit error rate
    P2 = [P2 P1];                                 % Concatenate all P1 data
    SNR = [SNR SNRdB];
    fprintf('%5.2f\t%e\t%6.0f\t%6.0f\n', SNRdB, P1, TotalNumError, TotalN);
end
semilogy (SNR,P2,'-bo');                          %Plot bit error rate
hold on
axis tight
grid on
legend('RS(7,5,3) sim')

⌨️ 快捷键说明

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