第三章 pro3信道编码咬尾卷积编码与维特比软判决译码

仿真思路:

step1:生成随机bit作为待调制信号sig;

step2:对生成bit stream做信道编码,编码方式:咬尾卷积1/3编码,可观察经编码后的码率变化;

step3:将信道编码后的bit stream经QPSK调制;

step4:调制信号过awgn信道,改变snr,观察过信道后信号变化;

step5:接收端QPSK软解调,输出LLR;

step6:将LLR结果导入维特比输入,经维特比译码还原至1/3码率的bit stream,采用软判决方式译码,取译码后的原数据长度为原始bit 流,即为系统bit。代码中LLR结果取了乘以-1,取决于实现时LLR实现时分子分母的含义。

step6:计算误码率;

%% Constants
FRM=2048;
MaxNumErrs=200;MaxNumBits=1e7;
EbNo_vector=0:10;BER_vector=zeros(size(EbNo_vector));
%% Initializations
    Modulator      = comm.QPSKModulator('BitInput',true);
    AWGN             = comm.AWGNChannel;
    DeModulator =  comm.QPSKDemodulator('BitOutput',true,...
        'DecisionMethod','Log-likelihood ratio',...
        'VarianceSource', 'Input port');
    BitError           = comm.ErrorRate;
    ConvEncoder=comm.ConvolutionalEncoder(...
        'TerminationMethod','Terminated');
    Viterbi=comm.ViterbiDecoder(...
        'InputFormat','Soft',...
        'SoftInputWordLength', 4,...
        'OutputDataType', 'double',...
        'TerminationMethod','Terminated');
    Quantizer=dsp.ScalarQuantizerEncoder(...
        'Partitioning',  'Unbounded',...
        'BoundaryPoints', -7:7,...
        'OutputIndexDataType','uint8');
%% Outer Loop computing Bit-error rate as a function of EbNo
% for EbNo = EbNo_vector
%     snr = EbNo + 10*log10(2);
    snr = 20;
    noise_var = 10.^(-snr/10);
    AWGN.EbNo=snr;
    numErrs = 0; numBits = 0;results=zeros(3,1);
    %% Inner loop modeling transmitter, channel model and receiver for each EbNo
%     while ((numErrs < MaxNumErrs) && (numBits < MaxNumBits))  
        % Transmitter
        u             = randi([0 1], FRM,1);                  % Generate random bits
        encoded     = ConvEncoder.step(u);               % Convolutional encoder
        mod_sig = step(Modulator,   encoded);                % QPSK Modulator

        scatterplot(mod_sig); 
        % Channel
        rx_sig  = step(AWGN,        mod_sig);        % AWGN channel
%         rx_sig = awgn(mod_sig,20,'measured');
        % Receiver

        scatterplot(rx_sig); 
        demod       =  DeModulator.step(rx_sig, noise_var);          % Soft-decision QPSK Demodulator
        llr         = Quantizer.step(-demod);                              % Quantize Log-Likelihood Ratios    
        decoded     = Viterbi.step(llr);                                              % Viterbi decoder with LLRs
        y           = decoded(1:FRM);                                          % Compute output bits
        results = step(BitError,    u, y);                  % Update BER
        numErrs = results(2);
        numBits = results(3);
%     end
    % Compute BER
    ber = results(1); bits= results(3);
    %% Clean up & collect results
    reset(BitError);
    BER_vector(EbNo+1)=ber;
% end

 

你可能感兴趣的:(第三章 pro3信道编码咬尾卷积编码与维特比软判决译码)