problem in convolutional coding

1 次查看(过去 30 天)
tamim
tamim 2022-10-21
评论: Rik 2022-10-21
i dont know what is the problem in this code:
% rate 1/2 convolutional encoder
% define trellis
trellis = poly2trellis(7,[171 133]);
% define input and output
x = randintrlv(1:100,3);
y = convenc(x,trellis);
Error using convenc
Expected MSG to be binary.

Error in convenc (line 88)
validateattributes(msg, {'numeric', 'logical'}, ...
% define generator polynomials
g1 = [1 0 1 0 1 1 1 0];
g2 = [1 1 1 0 1 1 0 1];
% encode
y1 = mod(conv(y,g1),2);
y2 = mod(conv(y,g2),2);
% interleave
z = [y1;y2];
z = z(:)';
% modulate
M = 4;
k = log2(M);
y_tx = bi2de(reshape(z,k,length(z)/k).','left-msb');
% plot constellation
scatterplot(y_tx,1,0,'k*');
axis([-5 5 -5 5]);
% add noise
EbNo = 10;
snr = EbNo + 10*log10(k) - 10*log10(log2(M));
y_rx = awgn(y_tx,snr,'measured');
% demodulate
z_rx = de2bi(y_rx,k,'left-msb');
% de-interleave
y1_hat = z_rx(1:2:end);
y2_hat = z_rx(2:2:end);
% decode
tblen = 15;
y_hat = vitdec(y1_hat,trellis,tblen,'trunc','hard');
% plot BER
ber = berawgn(EbNo,'psk',M,'nondiff');
semilogy(EbNo,ber,'k*');
hold on;
ber = berawgn(EbNo,'psk',M,'nondiff');
semilogy(EbNo,ber,'ko');
legend('Theoretical BER','Empirical BER');
xlabel('Eb/No (dB)');
ylabel('Bit Error Rate');
it shows this error:
Error using convenc
Expected MSG to be binary.
Error in convenc (line 88)
validateattributes(msg, {'numeric', 'logical'}, ...
Error in test2 (line 11)
y = convenc(x,trellis);
  1 个评论
Rik
Rik 2022-10-21
x = randintrlv(1:100,3)
x = 1×100
22 69 84 33 96 9 54 15 41 67 34 85 98 87 59 65 23 64 32 3 50 40 78 10 27 4 51 2 97 92
That isn't binary. Apparently the convenc function expects the input to be binary.
Why do you expect this to work?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Error Detection and Correction 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by