📄 awgn_conv_r12_k2.m
字号:
% Name: AWGN_conv_R12_K2.m
% Date: November 19, 2007
% Description:
% Simulation of rate-1/2 convolutional coding over an AWGN channel.
%
% Copyright (c) 2007. Robert Morelos-Zaragoza. All rights reserved.
clear
trellis = poly2trellis(2, [3 2]); % Trellis structure
nsim = 500; % Number of simulations
SNRinit = 0;
SNRinc = 1;
SNRfinal = 6;
SNR = [];
n = 8000; % Block length
k = 4000; % Number of message bits
rate = k/n; % Code rate
tblength = 7; % Traceback length
P2 = [];
seed = input('Enter your student ID:');
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 ...
fprintf('.');
if mod(Nsimulation,50) == 0
fprintf('\n');
end
%*************************** Encoding ****************************
x = (sign(rand(1,k))+1)/2; % random bits
y = convenc(x,trellis); % Encode the message.
z = -2*y+1; % BPSK modulation
% AWGN
z=z+sqrt(Var)*randn(1,n);
%*************************** Decoding ****************************
xhat = vitdec(z,trellis,tblength,'cont','unquant');
[errors,ratio]=biterr(xhat(tblength+1:end),x(1:end-tblength));
TotalNumError = TotalNumError + errors;
TotalN = TotalN + k;
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
% Compare BER curve with that of uncoded BPSK modulation
semilogy ([SNR 7 8 9] ,Q(sqrt(2*10.^([SNR 7 8 9]/10))),'-r*');
axis tight
hold on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -