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

📄 resource_alloc.m

📁 基于OFDM的无线宽带系统仿真It contains mainly two parts, i.e. link-level simulator and system-level simulator.
💻 M
字号:
function [st_baseStation] = resource_alloc(st_baseStation, st_mobileStations, st_initConfig)

switch st_baseStation.scheduler_Algo
    case 0
        st_baseStation.allocation(1,1,1:st_baseStation.nuSubChannels)=1:st_baseStation.nuSubChannels;
        switch st_baseStation.FixModulation
            case 'bpsk'
                for lp_idMS = 1:st_initConfig.nuMob
                    st_baseStation.mod(1,1,lp_idMS)=1;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                    st_baseStation.fec(1,1,lp_idMS)=1/3;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                end
            case 'qpsk'
                switch st_baseStation.FixFec
                    case '1/3'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=2;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=1/3;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                    case '1/2'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=2;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=1/2;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                    case '2/3'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=2;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=2/3;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                end
            case 'qam16'
                switch st_baseStation.FixFec
                    case '1/3'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=4;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=1/3;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                    case '1/2'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=4;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=1/2;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                    case '2/3'
                        for lp_idMS = 1:st_initConfig.nuMob
                            st_baseStation.mod(1,1,lp_idMS)=4;%st_mobileStations(lp_idMS).mod(1,1,lp_idMS);
                            st_baseStation.fec(1,1,lp_idMS)=2/3;%st_mobileStations(lp_idMS).fec(1,1,lp_idMS);
                        end
                end

        end
    case {1 2} % see description in test config
        % Now implementing SISO.
        % Other advanced option will be implemented once the system is built.
        % Resource allocation algorithm
        % As of now, all available sub carriers will be divided uniformly among all
        % users. Adjacent sub carriers will be allocated to one user.
        % Since we are considering SISO, we need to consider only number of
        % available sub carrier and the total number of active mobiles
        % Number of sub carriers per mobile


        % Per sub channel resource allocation. As of now each sub
        % channel is being assigned to one user
        %         st_baseStation.allocation(1,1,1:st_baseStation.nuSubChannels)=1:st_baseStation.nuSubChannels;

        RR_alloc_number=1;%round(rand*st_baseStation.nuSubChannels+1); % Random frequency hopping
%         sub_channel_counter=0;
        %flg_sub_chan_allocation_available=1;
        RR_rand_mob_start_idx=ceil(rand*st_initConfig.nuMob);
        RR_mobile_list = [RR_rand_mob_start_idx:st_initConfig.nuMob 1:RR_rand_mob_start_idx-1];
        for lp_idMS = RR_mobile_list
            for lp_nuSubChannels=1:st_baseStation.nuSubChannelsMAX_RR
                RR_alloc_number = mod(RR_alloc_number,st_baseStation.nuSubChannels)+1;
%                 sub_channel_counter = sub_channel_counter +1 ;
                st_baseStation.mod(RR_alloc_number,1,1)=st_mobileStations(lp_idMS).mod(1,1,RR_alloc_number);
                st_baseStation.fec(RR_alloc_number,1,1)=st_mobileStations(lp_idMS).fec(1,1,RR_alloc_number);
                st_baseStation.allocation(RR_alloc_number,1,1)=lp_idMS;
                st_baseStation.mobId(RR_alloc_number,1,1)=uint32(st_mobileStations(lp_idMS).MobNumber(st_initConfig.nFrmCntSlot));
                st_baseStation.ueDistance(RR_alloc_number,1,1)=uint16(round(abs(st_initConfig.locMS(lp_idMS) - st_initConfig.locBS(st_initConfig.desiredBsIdx))));
                st_baseStation.poweradjust(RR_alloc_number,1,1) = st_mobileStations(lp_idMS).poweradjust(1,1,RR_alloc_number);

%                 flg_sub_chan_allocation_full=mod(sub_channel_counter,st_baseStation.nuSubChannels);
%                 if flg_sub_chan_allocation_available==0
%                     break
%                 end
            end
%             if flg_sub_chan_allocation_available==0
%                 break
%             end

        end
        %         check=1;
        % Resource allocation

        %     case 3
        % Round Robin, but multiple sub channels to one user based on data
        % rate requirement
    case 4
        % max c/I
        %         sub_channel_counter=0;
        for lp_nuSubChannels=1:st_baseStation.nuSubChannels
            
            % know the length already. pre-allocate to save mem and speed
            mob_thpt_next=nan(1,st_initConfig.nuMob);
            for lp_idMS = 1:st_initConfig.nuMob
                mob_thpt_next(lp_idMS)=st_mobileStations(lp_idMS).ThptNext(lp_nuSubChannels);            
            end
            [val_thpt,mob_handle_number]=max(mob_thpt_next);
            st_baseStation.mod(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).mod(1,1,lp_nuSubChannels);
            st_baseStation.fec(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).fec(1,1,lp_nuSubChannels);
            st_baseStation.allocation(lp_nuSubChannels,1,1)=mob_handle_number;
            st_baseStation.mobId(lp_nuSubChannels,1,1)=uint32(st_mobileStations(mob_handle_number).MobNumber(st_initConfig.nFrmCntSlot));
            st_baseStation.ueDistance(lp_nuSubChannels,1,1)=uint16(round(abs(st_initConfig.locMS(mob_handle_number) - st_initConfig.locBS(st_initConfig.desiredBsIdx))));
            st_baseStation.poweradjust(lp_nuSubChannels,1,1) = st_mobileStations(mob_handle_number).poweradjust(1,1,lp_nuSubChannels);
        end
    case 5
        % Simple Proportional Fair algorithm with no frills!
        for lp_nuSubChannels=1:st_baseStation.nuSubChannels
            mob_thpt_next=nan(1,st_initConfig.nuMob);
            for lp_idMS = 1:st_initConfig.nuMob
                if st_mobileStations(lp_idMS).ThptAvgPast == 0,
                    st_mobileStations(lp_idMS).ThptAvgPast = 1;
                end
                mob_thpt_next(lp_idMS)=st_mobileStations(lp_idMS).ThptNext(lp_nuSubChannels)/st_mobileStations(lp_idMS).ThptAvgPast;
            end
            [val_thpt,mob_handle_number]=max(mob_thpt_next);
            st_baseStation.mod(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).mod(1,1,lp_nuSubChannels);
            st_baseStation.fec(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).fec(1,1,lp_nuSubChannels);
            st_baseStation.allocation(lp_nuSubChannels,1,1)=mob_handle_number;
            st_baseStation.mobId(lp_nuSubChannels,1,1)=uint32(st_mobileStations(mob_handle_number).MobNumber(st_initConfig.nFrmCntSlot));
            st_baseStation.ueDistance(lp_nuSubChannels,1,1)=uint16(round(abs(st_initConfig.locMS(mob_handle_number) - st_initConfig.locBS(st_initConfig.desiredBsIdx))));
            st_baseStation.poweradjust(lp_nuSubChannels,1,1) = st_mobileStations(mob_handle_number).poweradjust(1,1,lp_nuSubChannels);
        end
        case 6
        % Proportional fair, with data rate requirement
            for lp_nuSubChannels=1:st_baseStation.nuSubChannels
                mob_thpt_next=nan(1,st_initConfig.nuMob);
                for lp_idMS = 1:st_initConfig.nuMob
                    mob_thpt_next(lp_idMS)=st_mobileStations(lp_idMS).ThptNext(lp_nuSubChannels)/(st_mobileStations(lp_idMS).fair)^st_initConfig.tunablealpha;
                end
                [val_thpt,mob_handle_number]=max(mob_thpt_next);
                st_baseStation.mod(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).mod(1,1,lp_nuSubChannels);
                st_baseStation.fec(lp_nuSubChannels,1,1)=st_mobileStations(mob_handle_number).fec(1,1,lp_nuSubChannels);
                st_baseStation.allocation(lp_nuSubChannels,1,1)=mob_handle_number;
                st_baseStation.mobId(lp_nuSubChannels,1,1)=uint32(st_mobileStations(mob_handle_number).MobNumber(st_initConfig.nFrmCntSlot));
                st_baseStation.ueDistance(lp_nuSubChannels,1,1)=uint16(round(abs(st_initConfig.locMS(mob_handle_number) - st_initConfig.locBS(st_initConfig.desiredBsIdx))));
                st_baseStation.poweradjust(lp_nuSubChannels,1,1) = st_mobileStations(mob_handle_number).poweradjust(1,1,lp_nuSubChannels);
            end
    otherwise        
end

⌨️ 快捷键说明

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