⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_map.m

📁 通信中常用的卷积码信道译码源码程序
💻 M
字号:
clear all% Few help variablesglobal Yes NoYes = 1;No = 0;LcOFlag = 0; MaxFlag = 0;%% -- User defined parameters start -- %%% Code generator vectors, in binary or octal form (see 'help% poly2trellis' in Matlab for correct form). If empty, then specify% 'Trellis.K' and 'Trellis.Rate' to use built-in codegenerators.%% $$$ Trellis.g = [1,0,0;% $$$ 	     1,1,0;% $$$ 	     1,1,1];LData = 500;TerminateF = Yes;			% default = 'Yes'PunctureF = No;				% default = 'No'% $$$ Trellis.g = [1,1,1;1,0,1];%Trellis.g = [561,753];Trellis.K = 7;Trellis.Rate = 1/2;% Number of input bits Trellis.k = 1;% Generators in 'binary' or 'octal' form. Empty == 'binary'.GenForm = ['octal'];			EncType = 'non-recursive';                  % 'recursive' / 'non-recursive'DecMetric = 'soft';                     % 'hard' / 'soft'% Turbo-codesiterations=1;constellation = 'QPSK';% Modulation mappingswitch upper(constellation) case 'BPSK'  ModMap = [-1;1]; case 'QPSK'  ModMap = [-1-j; -1+j; 1-j; 1+j];	  % NOTE! Column vector! case '16-QAM'  Lut_tmp = bin2dec(...      ['1011'; '1001'; '0001'; '0011';       '1010'; '1000'; '0000'; '0010';       '1110'; '1100'; '0100'; '0110';       '1111'; '1101'; '0101'; '0111']);  Points_tmp = [-3+J*3;-1+J*3;1+J*3;3+J*3;		-3+J*1;-1+J*1;1+J*1;3+J*1;		-3-J*1;-1-J*1;1-J*1;3-J*1;		-3-J*3;-1-J*3;1-J*3;3-J*3];  ModMap(Lut_tmp+1) = Points_tmp;  clear Lut_tmp Points_tmp;end % switch constellationEs = (ModMap'*ModMap)/length(ModMap);BitsLut = double(dec2bin([0:length(ModMap)-1]))-48;  Trellis.ModLut = ModMap.';Trellis.BitsLut = BitsLut;% Number of bits / constellation pointNbits = log2(length(ModMap));% Signal-to-noise ratio in dB'sSNR = [0:1:3];% Number of loopsloop_end = 20000;%% -- User defined parameters end -- %%% Initialise parametersBER = zeros(length(SNR),loop_end);time_tot = 0;% Generate trellis[Trellis, Lut, TerminateF, PunctureF] = ...    trellis_gen(Trellis, EncType, DecMetric, ...		GenForm, TerminateF, PunctureF);Trellis.flag_3gpp = 0;% For hard decision trellis decoding, initialise trellisif strcmp(DecMetric,'hard')  Trellis = trellis_init(Trellis, Lut);end % if strcmp(DecMetric,rand('state',sum(100*clock));randn('state',sum(100*clock));%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -- SNR-loop begins -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%for s = 1:length(SNR)  % if Es = 1, SNR = 1/N0 => N0 = 1/SNR,   snr_linear = 10^(SNR(s)/10);			  % 2*sigma^2 = N0  sigma_2 = Es/(2*snr_linear*Nbits*Trellis.Rate);  N0 = 2*sigma_2;  berrs_tot = 0;  raw_berrs_tot = 0;    for i1 = 1:loop_end    time1 = clock;    Data = round(rand(1,LData));% $$$   Data = ones(1,LData);          %% -- Encoding -- %%        [Data_coded,alpha_enc] = trellis_encoder(Data, Trellis, Lut, ...					     TerminateF);     %% --          -- %%    %% -- Modulation -- %%    [Data_mod_tmp] = bb_modulation(Data_coded, ModMap);    [dummy, alpha_channel] = sort(rand(1,length(Data_mod_tmp)));    Data_mod = Data_mod_tmp(1,alpha_channel);    %% --          -- %%          %% -- Channel -- %%    awgn_tmp=randn(2,length(Data_mod))*sqrt(sigma_2);    awgn=awgn_tmp(1,:)+sqrt(-1)*awgn_tmp(2,:);      %complex Gaussian noise    fading_gains = ones(1,length(Data_mod));% + (1E-100)*sqrt(-1);      Data_ch = Data_mod.*fading_gains + awgn;    %% --         -- %%        %% -- Receiver -- %%        Data_received = Data_ch; %(2*(Data_ch>0)-1)>0;          %% --          -- %%        %% -- Decoding -- %%        alpha_rsc = [1:length(Data)];	% dummy variable    [Data_decoded,berrs,ferrs,raw_berrs,raw_ferrs] = ...	turbo_rec(Data_received, fading_gains, 2*sigma_2, alpha_channel, ...		  alpha_enc, alpha_rsc, iterations, Trellis, Lut, ModMap, ...		  BitsLut, Data, PunctureF, LcOFlag, MaxFlag);        % $$$   Data_decoded = trellis_decoder(Data_received, Trellis, Lut, ...% $$$ 				 alpha_channel, 'convolution');        %% --          -- %%        %% -- Error check -- %%    % $$$   BER(1,i1) = length(find(Data_decoded - Data)) / length(Data);        %% --             -- %%    time = etime(clock,time1);    time_tot = time_tot + time;    berrs_tot = berrs_tot + berrs;    raw_berrs_tot = raw_berrs_tot + raw_berrs;        if ~mod(i1,1000)      disp(sprintf(['SNR loop #%2.1fdB#, iteration %d finished in time' ...		    ' %1.2fs'],SNR(s), i1, time_tot));    end % if ~mod(i1,...  end % for i1 = 1:loop_end  total_ber(s) = berrs_tot/(length(Data_decoded)*loop_end)  total_raw_ber(s) = raw_berrs_tot/(length(Data_decoded)*loop_end)  disp(sprintf('SNR loop #%2.1fdB# finished in time %1.2fs', SNR(s), time_tot));  save conv_own9_tmp.mat total_ber SNR time_totend % for s = 1:length(SNR)disp(sprintf('Total time: %2.12f hours', time_tot/3600));% Remove pathseval(['rmpath ' Trellis.Path_list]);SNR_raw = 10*log10(10.^(SNR./10)*Trellis.Rate);save test_jari_K7.mat total_ber SNR time_tot SNR_raw total_raw_ber

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -