b b M = 4;
codeRate = 1/2;
constlen = 7;
k = log2(M);
% 产生二进制数
Fd = 1;
Fs = 4;
N = Fs/Fd;
numSymb = 5000;
numPlot = 20;
SNRpBitDemo =4;
SNR = SNRpBitDemo + 10*log10(k);
seed = [654321 123456];
rand('state', seed(1));
randn('state', seed(2));
msg_orig = randsrc(numSymb,1,[0:1]);
%卷积编码前的二进制数图
figure(1)
stem([0:numPlot-1], msg_orig(1:numPlot),'bx');
axis([ 0 numPlot -0.2 1.2]);
xlabel('Time');
ylabel('Amplitude');
title('Binary Symbols Before Convolutional Encoding' );
% 卷积编码
constlen = [7];
codegen = [171 133];
tblen = 32;
codeRate = 1/2;
trel = poly2trellis(constlen, codegen);
[msg_enc_bi]=convenc(msg_orig, trel);
numEncPlot = numPlot ./ codeRate;
tEnc = [0:numEncPlot-1] * codeRate;
% 卷积编码图
figure(2)
stem(tEnc, msg_enc_bi(1:length(tEnc)),'rx');
axis([ min(tEnc) max(tEnc) -0.2 1.2]);
xlabel('Time');
ylabel('Amplitude');
title('Binary Symbols After Convolutional Encoding' );
%加训练序列
Lc=500;
for j=1:Lc
temp=rand;
if temp<0.5
pn_seq(j)=0;
else
pn_seq(j)=1;
end
end
x=msg_enc_bi'
xx=[pn_seq x]
xxx=xx'
%QPSK调制
randn('state', seed(2));
[msg_enc]= bi2de(reshape(xxx, ...
size(xxx,2)*k,size(xxx,1) / k)');
grayencod = bitxor([0:M-1],floor([0:M-1]/2));
msg_gr_enc = grayencod(msg_enc+1);
msg_tx = dmodce(msg_gr_enc, Fd, [Fs, pi/4], 'psk', M);
%进入AWGN信道
msg_rx = awgn(msg_tx, -7);
numModPlot = numEncPlot * Fs ./ k;
tMod = [0:numModPlot-1] ./ Fs .* k;
figure(3)
plot(tMod, real(msg_tx(1:length(tMod))),'c-', ...
tMod, imag(msg_tx(1:length(tMod))),'m-');
axis([ min(tMod) max(tMod) -1.5 1.5]); xlabel('Time'); ylabel('Amplitude');
title('Encoded Symbols After QPSK Baseband Modulation' );
%QPSK解调
legend('In-phase','Quadrature',0);
msg_gr_demod = ddemodce(msg_rx, Fd, [Fs, pi/4], 'psk', M);
[dummy graydecod] = sort(grayencod); graydecod = graydecod - 1;
msg_demod = graydecod(msg_gr_demod+1)';
msg_demod_bi = de2bi(msg_demod,k)' ;
msg_demod_bi = msg_demod_bi(:);
%解调后的图
figure(4)
stem(tEnc, msg_demod_bi(1:numEncPlot),'bx');
axis([ 0 numPlot -0.2 1.2]);
xlabel('Time');
ylabel('Amplitude');
title('Demodulated Symbols' );
%自适应均衡
y=msg_demod_bi';
L=length(y);
K=15;
delta=0.01;
estimated_c=zeros(1,2*K+1);
for i=1:Lc-2*K
y_i=y(i:i+2*K);
z_i=estimated_c*y_i';
e_i=pn_seq(i)-z_i;
estimated_c=estimated_c+delta*e_i*y_i;
mse(i)=e_i.^2;
end
%学习曲线
figure(5)
p=1:470
plot(p,mse)
axis([0,470,0,1])
%用LMS算法算出的抽头系数作为固定权值
test=y(1:470);
equalized_test=filter(estimated_c,1,test);
sequence_use=y(501:10500);
equalized_x=filter(estimated_c,1,sequence_use);
for t=1:10000
if equalized_x(t)<0.5
sign_out(t)=0;
else
sign_out(t)=1;
end
end
%维特比译码硬判决
msg_dec = vitdec(sign_out, trel, tblen, 'cont', 'hard');
msg_dec=msg_dec';
%译码后的图
figure(6)
stem([0:numPlot-1], msg_orig(1:numPlot),'rx'); hold on;
stem([0:numPlot-1], msg_dec(1+tblen:numPlot+tblen),'bo'); hold off;
axis([ 0 numPlot -0.2 1.2]); xlabel('Time'); ylabel('Amplitude');
title('Decoded Symbols' );
[errorBitCod ratioBitCod] = biterr(msg_enc, msg_demod);
[errorBitCh ratioBitCh] = biterr(msg_orig(1:end-tblen), msg_dec(1+tblen:end));
- 1
- 2
- 3
前往页