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

📄 packet_sim.m

📁 source Matlab traites the UWB
💻 M
字号:
%%clear all, close all;%% Necessary pathaddpath ../rng;addpath ../util;addpath ../pulse;addpath ../receiver;addpath ../data_signal;addpath ../reed_solomon;addpath ../../src/channel;addpath ../../src/scrambling_timehopping;% Simulation parametersPLOT_DEBUG = 0;FS_CONT = 12e9;RSCODE  = 1;if RSCODE == 1  DATA_LENGTH = 870  fullblock = floor(DATA_LENGTH/330);  PACKET_LENGTH = fullblock*378 + (DATA_LENGTH-fullblock*330) + 48;else  DATA_LENGTH = 127*8;  PACKET_LENGTH = DATA_LENGTH;end% Physical layerTC = 2e-9; % Chip length in seconds%BURST_LENGTH = 4; % LPRF, in chipBURST_LENGTH = 16; % HPRF, in chipSYMBOL_LENGTH = 512; % In chip% Multipath channelCH_MODEL = 1;CH_ATT_THLD_DB = 30; %rays with bigger attenuation are considered 0CH_RNG_SEED = sum(100*clock);%group all the parameters corresponding to the channelchannel_p = group_channel_params(CH_RNG_SEED,CH_MODEL,CH_ATT_THLD_DB,0.5,1e-9);% ReceiverT_INT = 1e-9;N_INT = 1;channel_mask       = ones(1,50);channel_mask_unit  = T_INT*N_INT;t0 = clock;% Get the data signal of interest[burst, ths, compound_channel, ... samples_per_symbol, samples_per_burst, Ls] ...    = init_data_signal(FS_CONT, PACKET_LENGTH, TC,BURST_LENGTH,SYMBOL_LENGTH, ...                       channel_p);[rx_data  data_bit, symbol_start, signal_start] ...     = get_data_signal(PACKET_LENGTH, ...                      samples_per_burst, samples_per_symbol, Ls, ...                      burst, ths);if(PLOT_DEBUG)    figure;    plot(rx_data);    hold on;    samples_per_chip = TC * FS_CONT;    samples_per_burst = samples_per_chip*BURST_LENGTH;    samples_per_symbol = samples_per_chip*SYMBOL_LENGTH;    burst_start = cumsum(ones(1,PACKET_LENGTH*SYMBOL_LENGTH/BURST_LENGTH)* ...                         samples_per_burst)-samples_per_burst;    plot(burst_start,zeros(1,length(burst_start)),'.g');    symbol_start = cumsum(ones(1,PACKET_LENGTH)*samples_per_symbol) - ...        samples_per_symbol;    plot(symbol_start,zeros(1,length(symbol_start)),'*m');    plot(signal_start,zeros(1,length(signal_start)),'*r');    hold off;end% Add AWGN% Receiver% Get the signal only where necessaryburst_start_0 = symbol_start + ths*samples_per_burst;burst_start_1 = burst_start_0 + (samples_per_symbol/2);% Energy detection receiver and decodingif isempty(channel_mask)  n = Ls-rem(Ls,T_INT*FS_CONT*N_INT);else  n = round(length(channel_mask)*channel_mask_unit*FS_CONT);endsignal_idx_0 = repmat(burst_start_0,n,1)+repmat((0:n-1)',1,PACKET_LENGTH) + 1;signal_idx_1 = signal_idx_0 + samples_per_symbol/2 + 1;if(PLOT_DEBUG)  figure;  subplot(2,1,1);  plot(rx_data(reshape(signal_idx_0,1,PACKET_LENGTH*n)));  subplot(2,1,2);  plot(rx_data(reshape(signal_idx_1,1,PACKET_LENGTH*n)));  disp(data_bit);end% Energy receiver[rx_down_0,samples_per_tint] = ed_receiver(rx_data(reshape(signal_idx_0,1, ...                                                  PACKET_LENGTH*n)),T_INT, ...                                           FS_CONT,N_INT,-1);[rx_down_1,samples_per_tint] = ed_receiver(rx_data(reshape(signal_idx_1,1, ...                                                  PACKET_LENGTH*n)),T_INT, ...                                           FS_CONT,N_INT,-1);if(PLOT_DEBUG)  figure;  subplot(2,1,1);  plot(rx_down_0);  subplot(2,1,2);  plot(rx_down_1);end% Decision rule and detectionrx_down = sum(reshape((rx_down_0 - rx_down_1), ...                      n/(T_INT*FS_CONT),PACKET_LENGTH),1);idx_dec0 = find(rx_down>0);idx_dec1 = find(rx_down<0);idx_unknown = find(rx_down==0);demod_bit = [];demod_bit(idx_dec0) = 0;demod_bit(idx_dec1) = 1;demod_bit(idx_unknown) = round(rand(1,length(idx_unknown)));if RSCODE == 1  % RS decoding  dec_bit = rs_decoder_154a(demod_bit);else  dec_bit = demod_bit;end% Compute the BER[num_err,ber_sim] = symerr(data_bit,dec_bit);dt=etime(clock,t0);fprintf('(dt = %.2f), ber = %.4f\n',dt,ber_sim);

⌨️ 快捷键说明

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