In The Name of GOD
Dear all,
I wrote a mfile that it simulates BER of a 8PSK-TCM modulation over a fading channel, It seems to work properly, but I don't know is it what we want in a TCM transmitter or not. I would be very happy if any one tell me it is true or not. this is my code:
% In The Name of GOD
clear
% 8PSK-TCM simulation
M = 8;
tx = randint(1,1000);
conv_input = tx(1:2:end);
uncode_data = tx(2:2:end);
% Convolutional encoder
trellis = poly2trellis(7 ,[str2double(dec2base(bin2dec('1011011'),M)) str2double(dec2base(bin2dec('1111001'),M))]);
code_data = convenc(conv_input,trellis);
% partitioning
partition=[pskmod(1,M,0,'gray') pskmod(7,M,0,'gray');
pskmod(2,M,0,'gray') pskmod(4,M,0,'gray');
pskmod(3,M,0,'gray') pskmod(5,M,0,'gray');
pskmod(0,M,0,'gray') pskmod(6,M,0,'gray')];
% TCM Modulation
txSig = zeros(1,length(uncode_data));
for k = 1: length(uncode_data)
i = code_data(2*k-1)+code_data(2*k)*2;
txSig(1,k)=partition(i+1,uncode_data(k)+1);
end
% Effect of Rayleigh channel
x = randn(length(txSig),1);
y = randn(length(txSig),1);
ray = sqrt(0.5*(x.^2+y.^2));
fadeSig = txSig.*ray';
EbNo = (0:2:30);
k = log2(8);
SNR = EbNo+10*log10(k);
BER = zeros(1,length(EbNo));
for n = 1:length(SNR)
% Add Gaussian noise.
rxSig = awgn(fadeSig,SNR(n),'measured');
% Demodulate.
rx = pskdemod(rxSig, M,0,'gray');
% Decode
r_code = zeros(1,length(rx)*2);
r_uncode = zeros(1,length(rx));
for i=1:length(rx)
switch rx(i)
case 0
r_code(1,2*i-1) = 1;
r_code(1,2*i) = 1;
r_uncode(1,i) = 0;
case 1
r_code(1,2*i-1) = 0;
r_code(1,2*i) = 0;
r_uncode(1,i) = 0;
case 2
r_code(1,2*i-1) = 1;
r_code(1,2*i) = 0;
r_uncode(1,i) = 0;
case 3
r_code(1,2*i-1) = 0;
r_code(1,2*i) = 1;
r_uncode(1,i) = 0;
case 4
r_code(1,2*i-1) = 1;
r_code(1,2*i) = 0;
r_uncode(1,i) = 1;
case 5
r_code(1,2*i-1) = 0;
r_code(1,2*i) = 1;
r_uncode(1,i) = 1;
case 6
r_code(1,2*i-1) = 1;
r_code(1,2*i) = 1;
r_uncode(1,i) = 1;
case 7
r_code(1,2*i-1) = 0;
r_code(1,2*i) = 0;
r_uncode(1,i) = 1;
otherwise
error('This is impossible')
end
decrx1 = vitdec(r_code,trellis, 2,'trunc', 'hard');
decrx(1:2:length(tx))= decrx1;
decrx(2:2:length(tx))= r_uncode;
end
[nErrors, BER(1,n)] = biterr(tx,decrx);
end
semilogy(EbNo,BER,'b*',EbNo,BER,'b');grid on;
legend('Theoretical BER','Empirical BER');
xlabel('EbNo (dB)'); ylabel('BER');
title('TCM Modulation with a convolutional encoder in a Rayleigh channel');
|