work7gmsk_turbo.m
来自「turbocoding in gmsk modulation」· M 代码 · 共 136 行
M
136 行
clear
clc
sr=256000.0; % Symbol rate
ml=1; % ml:Number of modulation levels
br=sr.*ml; % Bit rate
nd = 10000; % Number of symbols that simulates in each loop
ebn0=5; % Eb/N0
SNR=[0:10];
IPOINT=8; % Number of oversamples
%************************* Filter initialization ***************************
irfn=21; % Number of taps
B=0.25*sr;
B2=0.6*sr;
[xh] = gaussf(B,irfn,IPOINT,sr,1); %Transmitter filter coefficients
[xh2] =gaussf(B2,irfn,IPOINT,sr,0); %Receiver filter coefficients
%******************** START CALCULATION *************************************
nloop=10; % Number of simulation loops
% for iiii=1:length(SNR)
for iiii=1:length(SNR)
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
for iii=1:nloop
%*************************** Data generation ********************************
data1=rand(1,nd.*ml)>0.5; % rand: built in function
[data111]=convlenc(data1);
% [data111, alpha] = turbo_encode(data1, length(data1), 1, 0, 3);
% 'seqin' : input binary sequence, in {0,1} form; if set to the string "length" however,
% the function just returns the codeword length as 'seqout'.
% 'len' : length of sequence (input beeing padded or truncated).
% 'key' : seed to use for pseudo-random interleaving during encoding.
% 'puncture': 1 to use the puncturer, giving rate 1/2; 0 otherwise, giving rate 1/3 (default).
% 'gnum' : generator polynom, 1 (default), 2 or 3.
%*************************** GMSK Modulation ********************************
% data111=2*data11-1;
data2=oversamp(data111,length(data111),IPOINT);
data3=conv(data2,xh); % NEW for GMSK
th=zeros(1,length(data3)+1);
ich2=zeros(1,length(data3)+1);
qch2=zeros(1,length(data3)+1);
for ii=2:length(data3)+1
th(1,ii)=th(1,ii-1)+pi/2*data3(1,ii-1)./IPOINT;
end
ich2=cos(th);
qch2=sin(th);
%************************** Attenuation Calculation ***********************
spow=sum(ich2.*ich2+qch2.*qch2)/nd; % sum: built in function
attn=0.5*spow*sr/br*10.^(-SNR(iiii)/10);
attn=sqrt(attn); % sqrt: built in function
%********************** Fading channel **********************
%[ifade,qfade]=sefade2(data2,qdata1,itau,dlvl1,th1,n0,itnd1,now1,length(data2),fftlen2,fstp,fd,flat);
%********************* Add White Gaussian Noise (AWGN) **********************
[ich3,qch3]= comb(ich2,qch2,attn);% add white gaussian noise
[ich4,qch4] = compconv(ich3,qch3,xh2);
syncpoint =irfn*IPOINT-IPOINT/2+1;
ich5=ich4(syncpoint:IPOINT:length(ich4));
qch5=qch4(syncpoint:IPOINT:length(qch4));
%**************************** GMSK Demodulation *****************************
demoddata2(1,1)=-1;
for k=3:2:nd*ml*2+1
demoddata2(1,k)=ich5(1,k)*qch5(1,k-1)*cos(pi*(k))>0;
end
for n=2:2:nd*ml*2+1
demoddata2(1,n)=ich5(1,n-1)*qch5(1,n)*cos(pi*(n))>0;
end
[demodata]=demoddata2(1,2:nd*ml*2+1);
%************************** Bit Error Rate (BER) ****************************
[dec_op]=viterbidec(demodata);
demodata1=2*demodata-1;
% [dec_op, alpha] = turbo_decode(demodata1, length(demodata1), 1, 1, 1, 1, 5);
%
%function [seqout, alpha] = turbo_decode(seqin, len, key, puncture, gnum,
%dec_alg, nb_iters)
% Input:
% 'seqin' : input codeword, in {<0, >=0} form (soft decoding);
% should be normalized in interval [-1,1].
% 'len' : length of original sequence.
% 'key' : seed to use for pseudo-random interleaving during decoding.
% 'puncture' : 1 to use the puncturer, giving rate 1/2; 0 otherwise, giving rate 1/3 (default).
% 'gnum' : generator polynom, 1 (default), 2 or 3.
% 'dec_alg' : decoding algorithm: 1 for logmapo decoder (default), 2 for sova0 decoder.
% 'nb_iters' : maximum number of iterations (defalut: 5).
%
% Output:
% 'seqout' : output decoded sequence, in {0,1} form;
% note: {<0,>=0} is mapped to {0,1}
% 'alpha' : used pseudo-random interleaving.
% ltot1 = numbits in seqin+2
noe2=size(find(data1-dec_op),2); % sum: built in function
nod2=length(data1); % length: built in function
end
% fprintf('%d\t%e\n',iii,noe2/nod2); % fprintf: built in function
noe=noe+noe2;
nod=nod+nod2;
ner(iiii)=noe/nod;
end
%********************** Output result ***************************
semilogy(SNR,ner,'bp-','LineWidth',2)
% axis([-2 13 10^-5 0.5])
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
% ber = noe/nod;
% fprintf('%d\t%d\t%d\t%e\n',ebn0,noe,nod,noe/nod); % fprintf: built in function
% fid = fopen('BERgmsk.dat','a');
% fprintf(fid,'%d\t%e\t%f\t%f\t\n',ebn0,noe/nod,noe,nod); % fprintf: built in function
% fclose(fid);
%******************** end of file ***************************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?