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

📄 measurement2.m

📁 基于OFDM的无线宽带系统仿真It contains mainly two parts, i.e. link-level simulator and system-level simulator.
💻 M
字号:
function [cnt_meas,st_measurement,st_mobileStations] = measurement2(cnt_meas,st_channelGrid,st_measurement,st_baseStation,st_mobileStations,st_initConfig)% This function will measure the signal to interference plus noise ratio at% each OFDM symbol at each sub carrier for each mobile at each location,% for as many frames as being simulated.% Then will find the Frame in error or not and will record it% It will also store the allocated modulation and FEC rate% It will also store the Feedback SINR to be used in the next round of% frame transmissiong_lin = st_channelGrid.g_lin;sub_chan_alloc_chart(1:st_baseStation.nuSubChannels)=st_baseStation.allocation(1:st_baseStation.nuSubChannels,1,1);for lp_nmob=1:st_initConfig.nuMob    % find the subchannels allocated to the current mobile handle index    sub_chan_allocated = find(sub_chan_alloc_chart==lp_nmob); %    sub_carrs_allocated=[];    for lp_num_sub_chan_alloc=sub_chan_allocated        sub_carrs_allocated = [sub_carrs_allocated (lp_num_sub_chan_alloc-1)*st_baseStation.nuSubCarrPerSubChan+1:lp_num_sub_chan_alloc*st_baseStation.nuSubCarrPerSubChan]; %    end    num_sub_carr_alloc=length(sub_carrs_allocated);    gain_ctf = nan(st_initConfig.nuSubCarr,st_initConfig.nuOfdmSymbPerSubFrame,st_initConfig.nuBs,st_initConfig.nuAntennaBS,st_initConfig.nuAntennaMS);    for lp_nBs = 1:st_initConfig.nuBs        for lp_nTxAntenna=1:st_initConfig.nuAntennaBS            for lp_nRxAntenna=1:st_initConfig.nuAntennaMS                index1 = st_mobileStations(lp_nmob).ch_idx(lp_nBs,lp_nTxAntenna,lp_nRxAntenna)+st_mobileStations(lp_nmob).ch_step(lp_nBs,lp_nTxAntenna,lp_nRxAntenna)*st_initConfig.feedBackDelayIntervalNuOfdms;                gain_ctf(:,:,lp_nBs,lp_nTxAntenna,lp_nRxAntenna) = g_lin(lp_nmob,lp_nBs)*st_channelGrid.gain_ch(st_initConfig.sub_cars,index1:st_mobileStations(lp_nmob).ch_step(lp_nBs,lp_nTxAntenna,lp_nRxAntenna):index1+st_mobileStations(lp_nmob).ch_step(lp_nBs,lp_nTxAntenna,lp_nRxAntenna)*(st_initConfig.nuOfdmSymbPerSubFrame-1));                tmp = st_mobileStations(lp_nmob).ch_idx(lp_nBs,lp_nTxAntenna,lp_nRxAntenna) +  st_mobileStations(lp_nmob).ch_step(lp_nBs,lp_nTxAntenna,lp_nRxAntenna)*(st_initConfig.nuOfdmSymbPerSubFrame -1);                if tmp > st_initConfig.chnums_max,                                        tmp = tmp- (st_initConfig.chnums_max - st_initConfig.chnums_min);                elseif tmp <=st_initConfig.chnums_min                    tmp = tmp+ (st_initConfig.chnums_max - st_initConfig.chnums_min);                end                st_mobileStations(lp_nmob).ch_idx(lp_nBs,lp_nTxAntenna,lp_nRxAntenna) = tmp;                                end        end    end    sinr = sum(gain_ctf(st_initConfig.sub_cars,:,st_initConfig.desiredBsIdx,1,:)./(sum(gain_ctf(st_initConfig.sub_cars,:,st_initConfig.intfBsIdxvector,1,:),3) + st_initConfig.noisePowerPerSubc/st_initConfig.maxPowBsSubCarr),5);    sinrChErr = sinr + sqrt(10^(1/10))*randn(size(sinr)); % 1dB error    sinrChErr(sinrChErr<0) = 1e-10;    for lp_all_subChan=1:st_baseStation.nuSubChannels        st_mobileStations(lp_nmob).sinrFeedBack(lp_all_subChan) ...            = mean(sinrChErr((lp_all_subChan-1)*st_baseStation.nuSubCarrPerSubChan+1:lp_all_subChan*st_baseStation.nuSubCarrPerSubChan,st_initConfig.nuOfdmSymbPerSubFrame-st_initConfig.feedBackDelayIntervalNuOfdms));        st_mobileStations(lp_nmob).sinrFeedBackNoChErr(lp_all_subChan) ...            = mean(sinr((lp_all_subChan-1)*st_baseStation.nuSubCarrPerSubChan+1:lp_all_subChan*st_baseStation.nuSubCarrPerSubChan,st_initConfig.nuOfdmSymbPerSubFrame-st_initConfig.feedBackDelayIntervalNuOfdms));    end    % LOOK UP THE SNR VS FER TABLE    cnt_lp_sub_chan=0;    total_bits_sent_by_mobile_in_this_frame=0;    tmp_Thpt = zeros(1,length(sub_chan_allocated));    for lp_nuSubChannels=sub_chan_allocated%1:num_sub_carr_alloc %sub_carrs_allocated        cnt_lp_sub_chan=cnt_lp_sub_chan+1;        curr_sinr = st_baseStation.poweradjust((lp_nuSubChannels),1,1) * mean(mean(sinr(sub_carrs_allocated( (cnt_lp_sub_chan-1)*st_baseStation.nuSubCarrPerSubChan+1:(cnt_lp_sub_chan)*st_baseStation.nuSubCarrPerSubChan),: )));        % READ UP ERROR PROBABILITY from the appropriate table for the rate        %SNR in dB qpsk1by3  qpsk1by2  qpsk2by3  qam161by3 qam161by2 qam162by3 qam641by3 qam641by2 qam642by3 0        switch st_baseStation.mod(lp_nuSubChannels,1,1);            case    0                colidx=11;%7;            case    2                switch st_baseStation.fec(lp_nuSubChannels,1,1);                    case    1/3                        colidx=2;%3;                    case    1/2                        colidx=3;%4;                    case    2/3                        colidx=4;                end            case    4                switch st_baseStation.fec(lp_nuSubChannels,1,1);                    case    1/3                        colidx=5;                    case    1/2                        colidx=6;                    case    2/3                        colidx=7;                end            case    6                switch st_baseStation.fec(lp_nuSubChannels,1,1);                    case    1/3                        colidx=8;                    case    1/2                        colidx=9;                    case    2/3                        colidx=10;                end        end        % FIND THE ROW INDEX FROM WHERE TO READ THE FER VALUE        Idx1 = max(find(st_initConfig.FerLin<=curr_sinr));        Idx2 = min(find(st_initConfig.FerLin>=curr_sinr));        Fer1 = st_initConfig.FerdB(Idx1,colidx); %LOOK UP THE FER TABLE TO FIND THE FER        Fer2 = st_initConfig.FerdB(Idx2,colidx);        Fer = mean([Fer1 Fer2]);        % 1 means the frame is in error        % 0 means frame not in error        % TRY A DICE TO FIND WHETHER THIS FRAME IS IN ERROR        % STORE THIS RESULT AS BELOW        % STORE THE FRAME BEING IN ERROR OR NOT IN AN ARRAY FOR EACH POSITION        % OF THE MOBILE        randnum=rand;        %       st_mobileStations(lp_nmob).FrminError(st_initConfig.nFrmCntSlot,lp_nuSubChannels)=(randnum <= Fer);        % Frame is in error or not ?        save_UserInforCnt = mod(st_initConfig.nFrmCnt-1,st_initConfig.saveUserInfo_factor) + 1;        st_measurement.FrminError(lp_nuSubChannels,save_UserInforCnt)=uint8(randnum <= Fer);        %         if colidx == 12 % if there is no modulation and coding        %         else        st_measurement.totalFramesinError=st_measurement.totalFramesinError+uint32(st_measurement.FrminError(lp_nuSubChannels,save_UserInforCnt));        %         end        %         st_measurement.totalFramesinError=st_measurement.totalFramesinError+st_mobileStations(lp_nmob).<(st_initConfig.nFrmCntSlot,lp_nuSubChannels);        % CHECK IF THE REMAINING FILE SIZE IS POSITIVE THEN ONLY IT MAKES        % SENSE TO CALCULATE THE FRAME (0.5MS) BEING IN ERROR OR NOT AND        % THE ASSOCIATED SUCCESSFUL BITS SENT ETC....        % update the number of bits to be sent in the next frame        nuBitsInFrame = floor(st_mobileStations(lp_nmob).mod(1,1,lp_nuSubChannels)*st_mobileStations(lp_nmob).fec(1,1,lp_nuSubChannels)*st_baseStation.nuSubCarrPerSubChan*st_initConfig.nuOfdmSymbPerSubFrame);        if ((st_measurement.FrminError(lp_nuSubChannels,save_UserInforCnt))==uint8(1)) % if the frame is in Error        else            total_bits_sent_by_mobile_in_this_frame=total_bits_sent_by_mobile_in_this_frame+nuBitsInFrame;        end        tmp_Thpt(lp_nuSubChannels) = (1-Fer)*nuBitsInFrame;    end    st_mobileStations(lp_nmob).Thpt=sum(tmp_Thpt);    st_measurement.totalBitsSent=st_measurement.totalBitsSent+total_bits_sent_by_mobile_in_this_frame;    st_mobileStations(lp_nmob).RemFileSz(mod(st_initConfig.nFrmCntSlot,st_initConfig.nuFrmPerSlot)+1)=st_mobileStations(lp_nmob).RemFileSz(st_initConfig.nFrmCntSlot)-total_bits_sent_by_mobile_in_this_frame;    if st_baseStation.scheduler_Algo >=4        average_window = min(st_baseStation.tcNuSubFrames,st_mobileStations(lp_nmob).MobActiveCnt);%+1);        %st_mobileStations(lp_nmob).ThptAvgPast =  st_mobileStations(lp_nmob).ThptAvgPast*(1-1/average_window) + total_bits_sent_by_mobile_in_this_frame/((st_initConfig.nFrmCnt*st_initConfig.subFramePeriod))/average_window;        st_mobileStations(lp_nmob).ThptAvgPast =  st_mobileStations(lp_nmob).ThptAvgPast*(1-1/average_window) + total_bits_sent_by_mobile_in_this_frame/((st_initConfig.subFramePeriod))/average_window;        st_mobileStations(lp_nmob).fair = st_mobileStations(lp_nmob).ThptAvgPast/st_mobileStations(lp_nmob).targetUEthpt + 1e-6;    endend

⌨️ 快捷键说明

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