📄 gsmsim_demo_bcch.m
字号:
function [] = GSMsim_demo_2(NumberOfBlocks,Lh,LogName)
% GSMSIM_DEMO:
% This demonstrates the function of the GSMsim
% package. Use this file as a starting point for building
% your own simulations.
%
% SYNTAX: GSMsim_demo_2(NumberOfBlocks,Lh,logname)
%
% INPUT: NumberOfBlocks:
% The number of GSM code blocks to process, a block
% corresponds to four GSM bursts.
%
% Lh: The length of the channel impulse response
% minus one.
% LogName:
% The basename of the file to which the simulation log is
% to be written. The simulation log is handy for
% evaluating the convergence og a simulation.
%
% OUTPUT: To a file called: logname.NumberOfBlocks.Lh
% Simulation statistics are constantly echoed to the screen for
% easy reference.
%
% WARNINGS: Do not expect this example to be more than exactly that,
% an example. This example is NOT scientifically correct.
%
% AUTHOR: Arne Norre Ekstr鴐 / Jan H. Mikkelsen
% EMAIL: aneks@kom.auc.dk / hmi@kom.auc.dk
%
% $Id: GSMsim_demo_2.m,v 1.6 1998/10/01 10:18:47 hmi Exp $
% This is an aid for the final screen report
%
tTotal=clock;
NumberOfBlocks = 1;
Lh= 3;
% There has, not yet, been observed any errors.
%
B_ERRS_Ia=0;
B_ERRS_Ib=0;
B_ERRS_II=0;
B_ERRS_II_CHEAT=0;
% gsm_set MUST BE RUN PRIOR TO ANY SIMULATIONS, SINCE IT DOES SETUP
% OF VALUES NEEDED FOR OPERATION OF THE PACKAGE.
%
gsm_set;
% PREPARE THE TABLES NEEDED BY THE VITERBI ALGORITHM.
%
[ SYMBOLS , PREVIOUS , NEXT , START , STOPS ] = viterbi_init(Lh);
% We need to initialize the interleaving routines, for that we need an so
% called first burst for the interleaver, this burst will not be fully
% received. Nor will bit errors be checked, hence there is no reason for
% encoding it...
%
tx_enc1=round(rand(1,456));
% Now we need a tx_data_matrix to start the deinterleaver thus get data
% for a burst. Bit errors will be checked for in this block.
%
tx_block2=data_gen(260);
% Do channel coding of data
%
tx_enc2=channel_enc(tx_block2);
% Interleave data
%
tx_data_matrix=interleave(tx_enc1,tx_enc2);
% Time goes by, and new become old, thus swap before entry of loop.
%
tx_enc1=tx_enc2;
tx_block1=tx_block2;
% Transmit and receive burst
%
rx_data_matrix1=tx_data_matrix;
% Sliding average time report aid.
%
A_Loop=0;
for N=2:NumberOfBlocks+1,
% Time report aid.
%
t0=clock;
% Get data for a new datablock, number two is the latest.
%
INIT_L = 184;
tx_block2=data_gen(INIT_L);
% Do channel coding of data
%
tx_enc2=channel_enc_BCCH(tx_block2);
% tx_data_mnatrix contains data for four burst, generated from two blocks.
%
tx_data_matrix=interleave(tx_enc1,tx_enc1);
% a = 57;
% tx_enc= [tx_enc(1,1:a);tx_enc(1,a+1:2*a);tx_enc(1,2*a+1:3*a);tx_enc(1,3*a+1:4*a);tx_enc(1,4*a+1:5*a); ...
% tx_enc(1,5*a+1:6*a);tx_enc(1,6*a+1:7*a);tx_enc(1,7*a+1:8*a)];
% tx_data_matrix=reshape( tx_enc, 8,57);
% tx_data_matrix = [tx_data_matrix(1,:),tx_data_matrix(2,:);tx_data_matrix(3,:),tx_data_matrix(4,:); ...
% tx_data_matrix(5,:),tx_data_matrix(6,:);tx_data_matrix(7,:),tx_data_matrix(8,:)];
for n=1:4,
% THIS IS ALL THAT IS NEEDED FOR MODULATING A GSM BUST, IN THE FORMAT
% USED IN GSMsim. THE CALL INCLUDES GENERATION AND MODULATTION OF DATA.
%
[ tx_burst , I , Q ] = gsm_mod(Tb,OSR,BT,tx_data_matrix(n,:),TRAINING);
% AT THIS POINT WE RUN THE CHANNEL SIMULATION. NOTE, THAT THE CHANNEL
% INCLUDES TRANSMITTER FORNT-END, AND RECEIVER FRONT-END. THE CHANNEL
% SELECTION IS BY NATURE INCLUDED IN THE RECEIVER FRONT-END.
% THE CHANNEL SIMULATOR INCLUDED IN THE GSMsim PACKAGE ONLY ADDS
% NOISE, AND SHOULD _NOT_ BE USED FOR SCIENTIFIC PURPOSES.
%
% SNR =9;
% Speed = 0;
% r=channel_simulator(I,Q,OSR,SNR,Speed);
% r(n,:) = I +Q*j;
r(n,:) = BCCHDemodulation(n);
% z = r(n).';
% N = 129;
% % B = kaiser(N,9);
% B = fir1(N,0.18);
% h = dfilt.dffir(B);
% % freqz(h);
% I = real(r(n,:));
% I = [I,zeros(1,(N-1)/2)];
%
% Q = imag(r(n,:));
% Q= [Q, zeros(1,(N-1)/2)];
% yI = filter(B,1,I);
% yQ = filter(B,1,Q);
% Z = yI(1,(N-1)/2+1:600+(N-1)/2) + yQ(1,(N-1)/2+1:600+(N-1)/2)*j;
% r(n,:)= Z;
% [mm,nn]=size(Z);
% for kk = 1:nn/OSR
% r(n,(kk-1)*OSR+1:kk*OSR) = r(n,(kk-1)*OSR+1:kk*OSR).*(-i).^kk;
% end
% r(n,:) = real(r(n,:));
% RUN THE MATCHED FILTER, IT IS RESPONSIBLE FOR FILTERING SYNCRONIZATION
% AND RETRIEVAL OF THE CHANNEL CHARACTERISTICS.
%
t_BCCH_gen=find_bcch;
T_SEQ=t_BCCH_gen(6,:);
[Y, Rhh,h_est] = mafi( r(n,:),Lh,T_SEQ,OSR);
% HAVING PREPARED THE PRECALCULATABLE PART OF THE VITERBI
% ALGORITHM, IT IS CALLED PASSING THE OBTAINED INFORMATION ALONG WITH
% THE RECEIVED SIGNAL, AND THE ESTIMATED AUTOCORRELATION FUNCTION.
%
% rx_burst = viterbi_detectorzb(SYMBOLS,NEXT,PREVIOUS,START,STOPS,Y,Rhh);
rx_burst = viterbi_detector(SYMBOLS,NEXT,PREVIOUS,START,STOPS,Y,Rhh);
% RUN THE DeMUX
%
rx_data_matrix2(n,:)=DeMUX(rx_burst);
end
% This is for bypassing the channel, uncomment to use
%
% rx_data_matrix2=tx_data_matrix;
% A block is regenerated using eight bursts.
%
% rx_enc=deinterleave( [ rx_data_matrix1 ; rx_data_matrix2 ] )
rx_enc=deinterleave_bcch( rx_data_matrix2 );
% rx_data_matrix2 = [rx_data_matrix2(1,:),rx_data_matrix2(2,:),rx_data_matrix2(3,:),rx_data_matrix2(4,:)];
% rx_enc=reshape( rx_data_matrix2, 8,57 );
% a = 57;
% rx_enc= [rx_enc(1,:),rx_enc(2,:),rx_enc(3,:),rx_enc(4,:),rx_enc(5,:),rx_enc(6,:),rx_enc(7,:),rx_enc(8,:)];
% rx_block=channel_dec(rx_enc);
% C = textread('.\data\456bitout.dat','%s');
% [m,nn]=size(C);
% rx_enc1 = hex2dec(C);
% rx_enc1= rx_enc1';
% xor(rx_enc,rx_enc1)
trel = poly2trellis(5,[23 33]); % Define trellis, according to GSM0503.
tblen = 228;
rx_block1=vitdec(rx_enc,trel,tblen,'term','hard');
rx_block= channel_dec_BCCH(rx_enc);
% g = [1, 0,0, 1, zeros(1,13),1, zeros(1,5),1, zeros(1,2),1,zeros(1,13),1];
g = [1, zeros(1,13), 1, zeros(1,2),1, zeros(1,5),1, zeros(1,13),1,0,0,1];
d = [rx_block];
[q,r] = deconv(d,g);
% ADJUST RESULT TO BINARY REPRESENTATION
L = length(r);
out = abs(r(L-39:L));
for n = 1:length(out),
if ceil(out(n)/2) ~= floor(out(n)/2)
out(n) = 1;
else
out(n) = 0;
end
end
out = addcrc(rx_block(1:184),g);
crc = rx_block(185:224);
crcre = out(185:224);
crcerr = xor(crcre, crc)
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -