matlab rdk,卷积编码和维特比译码的MATLAB实现

% 2011-3-29 从matlab demos 当中找来的关于卷积编码和维特比译码的实例

figure(1) %

subplot(211) %

EbNo = 4.5:.5:7; linEbNo = 10.^(EbNo(:).*0.1);

M = 4; codeRate = 1/2; constlen = 7; k = log2(M); codegen = [171

133];

tblen =

32; % traceback length

trellis = poly2trellis(constlen, codegen);

dspec = distspec(trellis, 7);

expVitBER = bercoding(EbNo, 'conv', 'hard', codeRate, dspec);

semilogy(EbNo, expVitBER, 'g'); xlabel('Eb/No

(dB)'); ylabel('BER');

title('Performance for R=1/2, K=7 Conv. Code and QPSK with Hard

Decision');

grid on; axis([4 8 10e-7 10e-3]); legend('Union Bound', 0);

figure(2) %

subplot(311) %

numSymb = 100; numPlot = 20;

Nsamp =

4; % oversampling rate

EbNoDemo = 3; EsN0 = EbNoDemo + 10*log10(k);

seed = [654321 123456];

rand('state', seed(1)); randn('state',

seed(2));

msg_orig = randsrc(numSymb, 1, 0:1);

stem(0:numPlot-1, msg_orig(1:numPlot),'bx');

axis([ 0 numPlot -0.2 1.2]); xlabel('时间');

ylabel('幅度');

title('卷积编码前的二进制符号' );

legend off

subplot(312) %

[msg_enc_bi] = convenc(msg_orig, trellis);

numEncPlot = numPlot / codeRate; tEnc = (0:numEncPlot-1) *

codeRate;

stem(tEnc, msg_enc_bi(1:length(tEnc)),'rx');

axis([min(tEnc) max(tEnc) -0.2 1.2]); xlabel('时间'); ylabel('幅度');

title('卷积编码后的二进制符号' );

figure(3) %

subplot(211) %

randn('state', seed(2));

msg_enc = bi2de(reshape(msg_enc_bi, ...

size(msg_enc_bi,2)*k,size(msg_enc_bi,1) / k)');

grayencod = bitxor(0:M-1, floor((0:M-1)/2));

msg_gr_enc = grayencod(msg_enc+1);

msg_tx = modulate(modem.pskmod(M, pi/4), msg_gr_enc);

msg_tx = rectpulse(msg_tx, Nsamp);

msg_rx = awgn(msg_tx,

EsN0-10*log10(1/codeRate)-10*log10(Nsamp));

numModPlot = numEncPlot * Nsamp ./ k;

tMod = (0:numModPlot-1) ./ Nsamp .* k;

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('时间'); ylabel('幅度');

title('QPSK基带调制后的编码符号');

legend('同相分量', '正交分量', 0);

subplot(212) %

msg_rx_int = intdump(msg_rx, Nsamp);

msg_gr_demod = demodulate(modem.pskdemod(M, pi/4),

msg_rx_int);

[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(:);

stem(tEnc, msg_enc_bi(1:numEncPlot),'rx'); hold on;

stem(tEnc, msg_demod_bi(1:numEncPlot),'bo'); hold off;

axis([0 numPlot -0.2 1.2]);

xlabel('时间'); ylabel('幅度'); title('解调符号' );

figure(2) %

subplot(313) %

msg_dec = vitdec(msg_demod_bi, trellis, tblen, 'cont',

'hard');

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('时间');

ylabel('幅度');

title('译码符号' );

% cla; %

figure(1) %

subplot(212) %

load('vitsimresults.mat');

semilogy(EbNo, expVitBER, 'g', EbNo, ratio, 'b*-');

xlabel('Eb/No (dB)'); ylabel('BER');

title('Performance for R=1/2, K=7 Conv. Code and QPSK with Hard

Decision');

axis([4 8 10e-7 10e-3]); legend('Union Bound', 'Simulation

Results', 0); grid on;

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值