Rules | Recent posts | topic RSS | Search | Register  | Log in

turbo coding

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> Digital communication
Author Message
islamatef



Joined: 20 Jul 2006
Posts: 71
Helped: 3


Post16 Aug 2006 20:50   turbo coding

I need matlab file that simulate turbo encoder/decoder using modulation and coding rate
Back to top
ahmedseu



Joined: 31 Jul 2006
Posts: 231
Helped: 20


Post17 Aug 2006 20:31   Re: turbo coding

This program is for Space-Time Turbo Coder and all the required modulation methods are included.


%Space-Time Turbo Coder
echo off
clear all
clear
clc

dec_alg = input(' Please enter the decoding algorithm. (0:Log-MAP, 1:SOVA) default 0 ');
if isempty(dec_alg)
dec_alg = 0;
end
awgn = input(' Please choose AWGN/Rayleigh (+1/-1): default +1 ');
if isempty(awgn)
awgn = 1;
end
L_total = input(' Please enter the frame size (= info + tail, default: 400) ');
if isempty(L_total)
L_total = 400; % information bits plus tail bits
end
%g = [ 1 1 1; 1 0 1 ];
%g = [1 1 0 1; 1 1 1 1];
g = [1 1 1 1 1; 1 0 0 0 1];
[n,K] = size(g);
m = K - 1;
%puncture = 0, puncturing into rate 1/2;
%puncture = 1, no puncturing
puncture = input(' Please choose punctured / unpunctured (0/1): default 0 ');
if isempty(puncture)
puncture = 0;
end
% Code rate
rate = 1/(2+puncture);
% Number of iterations
niter = input(' Please enter number of iterations for each frame: default 5 ');
if isempty(niter)
niter = 5;
end
% Number of frame errors to count as a stop criterior
ferrlim = input(' Please enter number of frame errors to terminate: default 15 ');
if isempty(ferrlim)
ferrlim = 15;
end
EbN0db = input(' Please enter Eb/N0 in dB : default [2.0] ');
if isempty(EbN0db)
EbN0db = [2.0];
end

fprintf('+ + Please be patient. Wait a while to get the result. + +\n');
% set up the trellis for g;
[output, transition, inv_state] = trellis(g);
% output of the first encoder isn't interleaved; order intact
alpha(1,1:L_total) = [1: L_total];
% generate a backward block interleaver for the second encoder
%alpha(2, 1:L_total) = back_block( [1:L_total], 3, 4);
% generate a random interleaver for the second encoder
alpha(2, 1:L_total) = r_inter( L_total);
blocknum = zeros(1,40);

%----------------------------------------------------------
user_no=1;
frame_num=1; %100;
bit_len=192*2;

for EbNo=5:15
power1=EbNo;
fprintf(' Eb/No = %d\n',EbNo);
SNR=1/power(10,EbNo/10); % sigma2
block = 1;
errblock = 0;
ffer=0;
bber=0;
G1=sqrt(0.5)*(randn(1,frame_num)+i*randn(1,frame_num)); %block fading
G2=sqrt(0.5)*(randn(1,frame_num)+i*randn(1,frame_num));
gain1=G1*sqrt(frame_num)/norm(G1);
gain2=G2*sqrt(frame_num)/norm(G2);

for frame=1:frame_num
ber=0;
users_data=randint(user_no,bit_len/2-m); % Information Generator
%%en_output = en_turbo( users_data, g, alpha, puncture ) ;
alpha = spread_interleaver(L_total,0);
en_output = encoderm(users_data, g, alpha, puncture );
% BPSK modulator
%en_output = 2 * en_output - ones(size(en_output));%
%--------------------------------------------------------
%if addinter ==1
% en_output1 = inter(en_output, m_inter, n_inter);
% en_output = en_output1;
%end
%--------------------------------------------------------
% Modulator: QPSK, 8PSK, and 16-QAM (star 16-QAM)
%--------------------------------------------------------
mod_in=en_output;
mod_out=mod_qpsk(mod_in);
%mod_out=mod_8psk(mod_in);
%mod_out=mod_16qam(mod_in);
%mod_out=opt_16qam_mod(mod_in);
psk_out=mod_out;
%--------------------------------------------------------
trans_sig1=sqrt(0.5)*psk_out;
for ip=1:bit_len/4 %STTD
trans_sig2(2*ip-1)=-conj(trans_sig1(2*ip));
trans_sig2(2*ip)=conj(trans_sig1(2*ip-1));
end
receiv=gain1(frame)*trans_sig1+gain2(frame)*trans_sig2+...
sqrt(0.5*EbNo)*(randn(1,bit_len/2)+i*randn(1,bit_len/2));
for ip=1:bit_len/4 %STTD decoding
re_sig(2*ip-1)=conj(gain1(frame))*receiv(2*ip-1)+gain2(frame)*conj(receiv(2*ip));
re_sig(2*ip)=conj(gain1(frame))*receiv(2*ip)-gain2(frame)*conj(receiv(2*ip-1));
end
%--------------------------------------------------------
% Demodulator: QPSK, 8PSK, and 16-QAM (star 16-QAM)
%--------------------------------------------------------
demod_in=re_sig;
demod_out=soft_qpsk_demod(demod_in);
%demod_out=soft_8psk_demod(demod_in);
%demod_out=soft_16qam_demod(demod_in);
%demod_out=soft_opt_16qam_demod(demod_in);
%--------------------------------------------------------
%if addinter ==1
% r1 = inter(demod_out, n_inter, m_inter);
% demod_out = r1;
%end
%---------------------------------------------------------
%ar=sqrt((gain1(frame)^2+gain2(frame)^2)/2);
ar=1;
Lcc = 2*ar/EbNo; % reliability value of the channel
%Lcc =1;
% weight channel output by channel reliability, to be used in decoder
r_Lc = demod_out * Lcc;
% at receiver, serial to parallel demultiplex to get the code word of each encoder
subr = demultiplex(r_Lc,dimension,alpha,puncture);
% iterative decoding begin
Le = 0*ones(1,L_total);
for iter = 1:iteration
L_in = Le;
L_out = sova(output,transition,inv_state, L_in,g,subr(1,Smile,1);
for i = 1:L_total
Le(i) = L_out(i)-subr(1,n*(i-1)+1)-L_in(i);
end
% normalization
c = mean(abs(Le))*2/std(abs(Le))^2;
Le = c *Le;
% interleaving the extrinsic value to be used as a priori information for decoder two
dim = 2;
for i = 1:L_total
L_in(i) = Le(alpha(dim,i));
end
L_out = sova(output,transition,inv_state, L_in,g,subr(dim,Smile,-1);
% deinterleave the soft output
for i = 1:L_total
temp(alpha(dimension,i)) = L_out(i);
end
% calculate bit error rate for the present block, present iteration
x_hat = (sign(temp(1:L_info))+1)/2;
err=find(x_hat ~= users_data );
Pe(sum(blocknum(1:power1-1))+block,iter) = length(err)/L_info;
ber=biterr(x_hat,users_data);
bber=bber+ber;
% extrinsic information to be used in the metrics of the first decoder
for i = 1:L_total
Le(i) = L_out(i)-subr(dim,n*(i-1)+1)-L_in(i);
end
% deinterleaving the extrinsic value Le as the a priori information of the next decoder
for i = 1:L_total
temp(alpha(dim,i)) = Le(i);
end
Le = temp;
% mean value of the a prior information for present block, present iteration
L_mean(sum(blocknum(1:power1-1))+block,iter) = mean(abs(Le));
% normalization
c = mean(abs(Le))*2/std(abs(Le))^2;
Le = c *Le;
end %iter
%if Pe(sum(blocknum(1:power1-1))+block,iteration)~=0 % frame error
% errblock = errblock+1;
%end
%%fprintf('\n %3d',block);
%for p = 1:iteration
% fprintf('%15.5e', Pe(sum(blocknum(1:power1-1))+block,p));
%end
%fprintf('\n');
block = block+1;
end % frame
blocknum(power1) = block-1;
%for k = 1:iteration
% fprintf('%15.5e', mean(Pe(sum(blocknum(1:power1-1))+1:...
% sum(blocknum(1:power1)),k)));
%end
ber0(EbNo)=bber/(frame_num*length(x_hat)*iteration)
end
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> Digital communication
Page 1 of 1 All times are GMT + 1 Hour


Abuse
Administrator
Moderators
topic RSS 
sitemap