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

📄 montecarlo.asv

📁 很好的OFDM的基于MATLAB的仿真程序包
💻 ASV
字号:
%simulation chain% This is simulation for the OFDM system.% ------- simulation1.m ------------------------------------% Black team% April-08-05% ----------------------------------------------------------clear;clf;%define global variable: knowm at the transmitter and receiverglobal nr_cyclic_bits                  % number of cyclic bitsglobal nr_subcarriers                  % number of subcarriersglobal size_training_seq               % used to detect a incomming messageglobal Ex                              % normalized energy per subcarrierglobal gap                             % gap in the waterfilling algoglobal nr_pilots                       % number of pilots at the very beginningglobal nr_frames                       % number of frames per blockglobal encoder_order                   % encoder rate: 1/encoder_orderglobal nr_fft% just for initialization in transmitterglobal begin_flag                      % flag: synchronization sequence and 10 pilots at beginning   global train_flag                      % flag: first message block, message with synchronization sequenceglobal start                           % flag: if start>0, transmit % just initialization for receiverglobal begin_flag_receiver             % begin_flag for receiver global train_flag_receiver             % train_flag for receiverglobal alfa;                           % temp variable to calculate H global belta;                          % temp variable to calculate H  % just for saving these value, like a bufferglobal tempb;                      % Temp: bits repartitionglobal tempe;                      % Temp: energy repartitionglobal tempH;                      % Temp: channel responseglobal tempN;                      % Temp: noise varianceglobal Len;                        % Length of message global last_t;% initializationsigma = 6:2:16;                     % Noise power values to simulate (in dB),                                     % some errors can occur for too large noise                                    % because of synchronizationsigma =fliplr(sigma);Ex = 100;                           % gain applied at the transmitter (energy per OFDM symbol)                          gap = -3;                           % waterfilling algorithm parameternr_cyclic_bits = 40;                % Size of cyclic prefix (in nr bits)   size_training_seq = 50;             % Size of training sequence (in bits)nr_frames = 30;                     % Number of parallel frames per blocknr_subcarriers = 127;               % Number of subcarriers usednr_fft = 256;                       % Number of fft, = 2*nr_subcarriers + 2nr_pilots = 30;                     % Number of parallel pilots (empty or not)size_message = 10^3;                encoder_order = 2;is_updated = 0;                       %if is_updated =0, the transmitter                                       %has no info about the channel                                      %if is_updated =1, there was a feedback                                      last_t = 0;                           % t_samp of last time. Use it if                                       % t_samp is bad this time   % pilot, first ten_pilots and traning sequence                                     pilot = rand(nr_subcarriers,1) + j*rand(nr_subcarriers,1);training_seq = rand(1, size_training_seq);pilots_ten=[];for i = 1:nr_pilots        temp = pilot + i * 0.05;        pilots_ten = [pilots_ten temp];end    % train_message for synchronization (message)IFFTpilot2 = symifft(pilot);pilot_train2 = add_prefix(IFFTpilot2,nr_cyclic_bits);train_message = reshape(pilot_train2,1,(nr_fft+nr_cyclic_bits));uptrain_message = upfir(train_message);uptrain_message = uptrain_message(1:end-7);% train_pilots for synchronization (10_pilots)IFFTpilot1 = symifft(pilot + 0.05);pilot_train1 = add_prefix(IFFTpilot1,nr_cyclic_bits);train_pilots = reshape(pilot_train1,1,(nr_fft+nr_cyclic_bits));uptrain_pilots=upfir(train_pilots);uptrain_pilots=uptrain_pilots(1:end-7);    % Loop over different values of Noise power(in dB).nr_errors = zeros(1, length(sigma));   % Error counterfor sigma_point = 1:length(sigma)    sigma_point    for blk=1:10        %generation of the message        message = generate(size_message);        output=[];          % initial for the beginning of all        begin_flag = 0;        begin_flag_receiver = 0;        train_flag = 0;        train_flag_receiver = 0;        alfa = 0;        belta = 0;        tempN = 0;        bn = zeros(1,nr_subcarriers);        en = zeros(1,nr_subcarriers);        size_frame = 127;        is_updated = 0                                         blk = 0;        sumSNR = 0;        start = 1;                while (start>0)                blk = blk+1;                % total bit energy        if(blk==1)            sumEb = 0;                  % pilots block        else            sumEb = sumEb + Ex * nr_subcarriers / size_frame;        end               start        %Transmitter sends Training sequence, Pilot and then block of        %frames, Pilot, block of frames, Pilots, etc..        m1 = transmitter(training_seq, pilot, pilots_ten, message, bn, en, size_frame, is_updated);               % modelisation of the channel                m2 = filter( [1 0 0 0 0 0.5 0 0.3],1,m1);                %channel fading       m3 = addnoise(m2,sigma(sigma_point));                    %adding some noise         m3 = [zeros(1,30) m3];                                   %delay        %Transmitter synchronizes at the beginning, then estimates the        %channel thanks to the Pilots, receives blocks after blocks and        %provides the channel information        [m4, en, bn, size_frame] = receiver(training_seq, pilot,train_message,train_pilots,m3);                     output = [output m4];               is_updated = 1;                             end  % let length(output) = size_message, for comparision in Matlab  if(length(output)<size_message)     output = [output zeros( 1,(size_message-length(output)) )]; end if(length(output)>size_message)    output = output(1:size_message); end  % error count  nr_errors(sigma_point) = sum(xor(output,message)); SNR(sigma_point) = sumEb / 10^(sigma(sigma_point)/10) / (blk - 1); endbend% Compute the BER.BER = nr_errors / length(message)/10SNRdb = 10 * log10(SNR)[SNR2db Index] = sort(SNRdb);               %sort from smallest to largestBER2 = BER(Index);figure(1);semilogy(SNR2db, BER2)figure(2);subplot(211)plot(abs(tempH));subplot(212)plot(tempb); 

⌨️ 快捷键说明

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