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

仿真思路:

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

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

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

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

step5:接收端QPSK解调;

step6:对QPSK解调后的输出,经维特比译码还原至1/3码率的bit stream,采用硬判决方式译码,取译码后的原数据长度为原始bit 流,即为系统bit。

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);
BitError           = comm.ErrorRate;
ConvEncoder=comm.ConvolutionalEncoder(...
    'TerminationMethod','Terminated');
Viterbi=comm.ViterbiDecoder('InputFormat','Hard',...
    'TerminationMethod','Terminated');
%% Outer Loop computing Bit-error rate as a function of EbNo
for EbNo = EbNo_vector
    snr = EbNo + 10*log10(2);
    AWGN.EbNo=20;
    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 =       step(DeModulator, rx_sig);           % QPSK Demodulator
        decoded     = Viterbi.step(demod);                % Viterbi decoder
        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

 

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