diff --git a/MainFiles/mainInit.m b/MainFiles/mainInit.m index effe15e..76fcc98 100644 --- a/MainFiles/mainInit.m +++ b/MainFiles/mainInit.m @@ -4,8 +4,7 @@ %% Init of active vehicles and states % Move IDvehicle from simValues to station Management -stationManagement.activeIDs = simValues.IDvehicle; -simValues = rmfield(simValues,'IDvehicle'); +stationManagement.activeIDs = []; % The simulation starts at time '0' timeManagement.timeNow = 0; @@ -54,6 +53,8 @@ stationManagement.activeIDsCV2X = stationManagement.activeIDsCV2X(stationManagement.activeIDsCV2X>0); stationManagement.activeIDs11p = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)~=constants.V_STATE_LTE_TXRX); stationManagement.activeIDs11p = stationManagement.activeIDs11p(stationManagement.activeIDs11p>0); +stationManagement.activeIDsEnter = []; +stationManagement.activeIDsExit = []; stationManagement.indexInActiveIDs_ofLTEnodes = zeros(length(stationManagement.activeIDsCV2X),1); for i=1:length(stationManagement.activeIDsCV2X) stationManagement.indexInActiveIDs_ofLTEnodes(i) = find(stationManagement.activeIDs==stationManagement.activeIDsCV2X(i)); @@ -64,10 +65,11 @@ end %% Number of vehicles at the current time -outputValues.Nvehicles = length(stationManagement.activeIDs); +outputValues.Nvehicles = simValues.maxID; outputValues.NvehiclesTOT = outputValues.NvehiclesTOT + outputValues.Nvehicles; outputValues.NvehiclesLTE = outputValues.NvehiclesLTE + length(stationManagement.activeIDsCV2X); outputValues.Nvehicles11p = outputValues.Nvehicles11p + length(stationManagement.activeIDs11p); +outputValues.meanPositionError = zeros(outputValues.Nvehicles, 1); %% Initialization of packets management % Number of packets in the queue of each node @@ -201,15 +203,22 @@ end % Copy real coordinates into estimated coordinates at eNodeB (no positioning error) -simValues.XvehicleEstimated = positionManagement.XvehicleReal; -simValues.YvehicleEstimated = positionManagement.YvehicleReal; +positionManagement.XvehicleEstimated = positionManagement.XvehicleReal; +positionManagement.YvehicleEstimated = positionManagement.YvehicleReal; % Call function to compute distances -% computeDistance(i,j): computeDistance from vehicle with index i to vehicle with index j -% positionManagement.distance matrix has dimensions equal to simValues.IDvehicle x simValues.IDvehicle in order to -% speed up the computation (only vehicles present at the considered instant) -% positionManagement.distance(i,j): positionManagement.distance from vehicle with index i to vehicle with index j -[positionManagement,stationManagement] = computeDistance (simParams,simValues,stationManagement,positionManagement); +[positionManagement] = computeDistance (positionManagement); + +% Position Delay +% timetables of old positions +n_vehicles = length(positionManagement.XvehicleReal); +positionManagement.XvehicleHistory = cell(n_vehicles, 1); +positionManagement.YvehicleHistory = cell(n_vehicles, 1); +for i = 1:n_vehicles + positionManagement.XvehicleHistory{i} = timetable(Size=[0 1], VariableTypes={'double'}, TimeStep=seconds(simParams.positionTimeResolution)); + positionManagement.YvehicleHistory{i} = timetable(Size=[0 1], VariableTypes={'double'}, TimeStep=seconds(simParams.positionTimeResolution)); +end + % Save positionManagement.distance matrix positionManagement.XvehicleRealOld = positionManagement.XvehicleReal; @@ -219,7 +228,7 @@ % Computation of the channel gain % 'dUpdate': vector used for the calculation of correlated shadowing -dUpdate = zeros(outputValues.Nvehicles,outputValues.Nvehicles); +dUpdate = zeros(0, 0); [sinrManagement,simValues.Xmap,simValues.Ymap,phyParams.LOS] = computeChannelGain(sinrManagement,stationManagement,positionManagement,phyParams,simParams,dUpdate); % Update of the neighbors @@ -397,7 +406,7 @@ timeManagement.timeNextCV2X = inf; % if not only 11p -if ismember(constants.V_STATE_LTE_TXRX, stationManagement.vehicleState(stationManagement.activeIDs)) +if ismember(constants.V_STATE_LTE_TXRX, stationManagement.vehicleState) % Initialization of resouce allocation algorithms in LTE-V2X if ismember(simParams.BRAlgorithm, [constants.REASSIGN_BR_REUSE_DIS_SCHEDULED_VEH,... constants.REASSIGN_BR_MAX_REUSE_DIS, constants.REASSIGN_BR_MIN_REUSE_POW]) @@ -445,11 +454,11 @@ % Must be ordered with respect to the packet generation instant % (Vittorio 5.5.3) % subframeGen = ceil(timeManagement.timeNextPacket/phyParams.Tsf); - TTIGen = ceil(timeManagement.timeNextPacket/phyParams.TTI); - TTI_BR = ceil(stationManagement.BRid/appParams.NbeaconsF); - stationManagement.BRid = stationManagement.BRid + (TTI_BR<=TTIGen) * appParams.Nbeacons; - stationManagement.BRid = sort(stationManagement.BRid,2); - stationManagement.BRid = stationManagement.BRid - (stationManagement.BRid>appParams.Nbeacons) * appParams.Nbeacons; + TTIGen = ceil(timeManagement.timeNextPacket(stationManagement.activeIDs)/phyParams.TTI); + TTI_BR = ceil(stationManagement.BRid(stationManagement.activeIDs)/appParams.NbeaconsF); + stationManagement.BRid(stationManagement.activeIDs) = stationManagement.BRid(stationManagement.activeIDs) + (TTI_BR<=TTIGen) * appParams.Nbeacons; + stationManagement.BRid(stationManagement.activeIDs) = sort(stationManagement.BRid(stationManagement.activeIDs),2); + stationManagement.BRid(stationManagement.activeIDs) = stationManagement.BRid(stationManagement.activeIDs) - (stationManagement.BRid(stationManagement.activeIDs)>appParams.Nbeacons) * appParams.Nbeacons; % vector correctSCImatrixCV2X created stationManagement.correctSCImatrixCV2X = []; @@ -483,7 +492,7 @@ % of the first TTI in 0 timeManagement.timeNextCV2X = 0; timeManagement.ttiCV2Xstarts = true; - + % The channel busy ratio of C-V2X is initialized sinrManagement.cbrCV2X = zeros(simValues.maxID,1); sinrManagement.cbrLTE_coexLTEonly = zeros(simValues.maxID,1); diff --git a/MainFiles/mainPositionUpdate.m b/MainFiles/mainPositionUpdate.m index f696ac7..15d706b 100644 --- a/MainFiles/mainPositionUpdate.m +++ b/MainFiles/mainPositionUpdate.m @@ -6,20 +6,28 @@ % Call function to update vehicles positions [indexNewVehicles,indexOldVehicles,indexOldVehiclesToOld,stationManagement.activeIDsExit,positionManagement] = updatePosition(timeManagement.timeNow,stationManagement.activeIDs,simParams.positionTimeResolution,positionManagement,simValues,outParams,simParams); else - % Store IDs of vehicles at the previous beacon period and update positions - [positionManagement.XvehicleReal,positionManagement.YvehicleReal,stationManagement.activeIDs,indexNewVehicles,indexOldVehicles,indexOldVehiclesToOld,stationManagement.activeIDsExit,positionManagement.v,positionManagement.direction] = updatePositionFile( ... - round(timeManagement.timeNextPosUpdate,2), ... - simValues.dataTrace,stationManagement.activeIDs, ... - positionManagement.XvehicleReal,positionManagement.YvehicleReal, ... - round(timeManagement.timeNextPosUpdate,2)-simParams.positionTimeResolution,simValues,outParams); - %% ONLY LTE - if sum(stationManagement.vehicleState(stationManagement.activeIDs)==100)>0 - %if simParams.technology ~= 2 % not only 11p - % Update stationManagement.BRid vector (variable number of vehicles in the scenario) - [stationManagement.BRid] = updateBRidFile(stationManagement.BRid,stationManagement.activeIDs,indexNewVehicles); - end + % Interpolate position of all vehicles from current trace file + [positions] = updatePositionFile(simValues.trafficTraceTimetable, timeManagement.timeNow, simValues.IDvehicle); + positionManagement.XvehicleReal = positions.X; + positionManagement.YvehicleReal = positions.Y; + positionManagement.v = positions.V; + positionManagement.direction = NaN(height(positions)); + + old_active_ids = stationManagement.activeIDs; + % Mark vehicles coming in and out of bounds as active/inactive + [activeIds, enteredVehicles, exitedVehicles] = checkVehicleBounds(positions, stationManagement.activeIDs, ... + "XMin", simParams.XminTrace, "XMax", simParams.XmaxTrace, "YMin", simParams.YminTrace, "YMax", simParams.YmaxTrace); + indexNewVehicles = find(ismember(activeIds, enteredVehicles)); + indexOldVehicles = find(~ismember(activeIds, enteredVehicles)); + oldVehicles = activeIds(indexOldVehicles); + [~ , indexOldVehiclesToOld] = ismember(oldVehicles, old_active_ids); + stationManagement.activeIDs = activeIds; + stationManagement.activeIDsExit = exitedVehicles; + stationManagement.activeIDsEnter = enteredVehicles; + stationManagement.indexOldVehiclesToOld = indexOldVehiclesToOld; end + % Vectors IDvehicleLTE and IDvehicle11p are updated stationManagement.activeIDsCV2X = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)==100); stationManagement.activeIDsCV2X = stationManagement.activeIDsCV2X(stationManagement.activeIDsCV2X>0); @@ -68,20 +76,25 @@ end % Add LTE positioning delay (if selected) - [simValues.XvehicleEstimated,simValues.YvehicleEstimated,PosUpdateIndex] = addPosDelay(simValues.XvehicleEstimated,simValues.YvehicleEstimated,positionManagement.XvehicleReal,positionManagement.YvehicleReal,stationManagement.activeIDs,indexNewVehicles,indexOldVehicles,indexOldVehiclesToOld,positionManagement.posUpdateAllVehicles,simParams.positionTimeResolution); - + [positionManagement.XvehicleEstimated, positionManagement.YvehicleEstimated,... + positionManagement.XvehicleHistory, positionManagement.YvehicleHistory] = addPosDelay(positionManagement.XvehicleReal, positionManagement.YvehicleReal, positionManagement.XvehicleHistory, positionManagement.YvehicleHistory, timeManagement.timeNow, simParams.posDelay, simParams.posPacketLoss); + % Add LTE positioning error (if selected) % (Xvehicle, Yvehicle): fictitious vehicles' position seen by the eNB - [simValues.XvehicleEstimated(PosUpdateIndex),simValues.YvehicleEstimated(PosUpdateIndex)] = addPosError(positionManagement.XvehicleReal(PosUpdateIndex),positionManagement.YvehicleReal(PosUpdateIndex),simParams.sigmaPosError); + [positionManagement.XvehicleEstimated,positionManagement.YvehicleEstimated] = addPosError(positionManagement.XvehicleEstimated, positionManagement.YvehicleEstimated,simParams.sigmaPosError); + + % Record the cumulative mean of positioning error + this_instance_error = sqrt((positionManagement.XvehicleReal - positionManagement.XvehicleEstimated).^2 + (positionManagement.YvehicleReal - positionManagement.YvehicleEstimated).^2); + outputValues.meanPositionError = (this_instance_error + positionManagement.NposUpdates*outputValues.meanPositionError)/(positionManagement.NposUpdates+1); end % Call function to compute the distances -[positionManagement,stationManagement] = computeDistance (simParams,simValues,stationManagement,positionManagement); +[positionManagement] = computeDistance(positionManagement); % Call function to update positionManagement.distance matrix where D(i,j) is the % change in positionManagement.distance of link i to j from time n-1 to time n and used % for updating Shadowing matrix -[dUpdate,sinrManagement.Shadowing_dB,positionManagement.distanceRealOld] = updateDistanceChangeForShadowing(positionManagement.distanceReal,positionManagement.distanceRealOld,indexOldVehicles,indexOldVehiclesToOld,sinrManagement.Shadowing_dB,phyParams.stdDevShadowLOS_dB); +[dUpdate,sinrManagement.Shadowing_dB,positionManagement.distanceRealOld] = updateDistanceChangeForShadowing(positionManagement.distanceReal,positionManagement.distanceRealOld,phyParams.stdDevShadowLOS_dB, activeIds, enteredVehicles, exitedVehicles); % Calculation of channel and then received power [sinrManagement,simValues.Xmap,simValues.Ymap,phyParams.LOS] = computeChannelGain(sinrManagement,stationManagement,positionManagement,phyParams,simParams,dUpdate); @@ -232,6 +245,14 @@ stationManagement.pckNextAttempt(stationManagement.activeIDsExit) = 1; stationManagement.pckTxOccurring(stationManagement.activeIDsExit) = 0; +% resize stationManagement.hasTransmissionThisSlot +new_hasTransmissionThisSlot = zeros(numel(stationManagement.activeIDs), 1); +new_hasTransmissionThisSlot(indexOldVehicles) = stationManagement.hasTransmissionThisSlot(indexOldVehiclesToOld); +stationManagement.hasTransmissionThisSlot = new_hasTransmissionThisSlot; + +% Relinquish the BR for vehicles who exited +stationManagement.BRid(stationManagement.activeIDsExit) = -2; + %% CBR settings for the new vehicles if simParams.cbrActive && (outParams.printCBR || (simParams.technology==constants.TECH_COEX_STD_INTERF && simParams.coexMethod~=constants.COEX_METHOD_NON && simParams.coex_slotManagement==constants.COEX_SLOT_DYNAMIC)) timeManagement.cbr11p_timeStartMeasInterval(stationManagement.activeIDs(indexNewVehicles)) = timeManagement.timeNow; diff --git a/MainFiles/mainV2X.m b/MainFiles/mainV2X.m index be9a261..83e4e8f 100644 --- a/MainFiles/mainV2X.m +++ b/MainFiles/mainV2X.m @@ -30,6 +30,9 @@ % indexEvent is the index of the vector IDvehicle % idEvent is the ID of the vehicle of the current event [timeEvent, indexEvent] = min(timeManagement.timeNextEvent(stationManagement.activeIDs)); + if isempty(timeEvent) + timeEvent = timeManagement.timeNextPosUpdate; + end idEvent = stationManagement.activeIDs(indexEvent); % If the next C-V2X event is earlier than timeEvent, set the time to the @@ -56,7 +59,7 @@ % to the position update % With LTE, it must necessarily be done after the end of a subframe and % before the next one - if timeEvent >= (timeManagement.timeNextPosUpdate-1e-9) && ... + if any(timeEvent >= (timeManagement.timeNextPosUpdate-1e-9)) && ... (isempty(stationManagement.activeIDsCV2X) || (isfield(timeManagement, "ttiCV2Xstarts") && timeManagement.ttiCV2Xstarts==true)) timeEvent = timeManagement.timeNextPosUpdate; end @@ -195,7 +198,7 @@ %printDebugEvents(timeEvent,'LTE subframe starts',-1); %fprintf('Starts\n'); - if timeManagement.timeNow>0 + if timeManagement.timeNow > 0 && any(setdiff(stationManagement.activeIDsCV2X, stationManagement.activeIDsEnter)) [phyParams,simValues,outputValues,sinrManagement,stationManagement,timeManagement] = ... mainCV2XttiEnds(appParams,simParams,phyParams,outParams,simValues,outputValues,timeManagement,positionManagement,sinrManagement,stationManagement); end diff --git a/MainFilesCV2X/elaborateFateRxCV2X.m b/MainFilesCV2X/elaborateFateRxCV2X.m index a8f419e..bd3a42f 100644 --- a/MainFilesCV2X/elaborateFateRxCV2X.m +++ b/MainFilesCV2X/elaborateFateRxCV2X.m @@ -3,7 +3,10 @@ % transmissions % [ID TX, ID RX, BRid, distance] -distance = positionManagement.distanceReal(stationManagement.vehicleState(stationManagement.activeIDs)==100,stationManagement.vehicleState(stationManagement.activeIDs)==100); +LTEIndices = find(stationManagement.vehicleState == constants.V_STATE_LTE_TXRX); +ActiveIndices = stationManagement.activeIDs; +ActiveLTEIndices = intersect(LTEIndices, ActiveIndices); +distance = positionManagement.distanceReal(ActiveLTEIndices, ActiveLTEIndices); Ntx = length(IDvehicleTXLTE); % Number of tx vehicles %resultingList = zeros(Ntx*length(neighborsID(1,:)),5); % Initialize error matrix @@ -15,13 +18,6 @@ end for i = 1:Ntx - - %if IDvehicleTXLTE(i)==39 - % fp = fopen('Temp.txt','a'); - % fprintf(fp,'T=%f: new tx, attemmpt %d\n',timeManagement.timeNow,stationManagement.pckTxOccurring(IDvehicleTXLTE(i))); - % fclose(fp); - %end - % Find indexes of receiving vehicles in neighborsID indexNeighborsRX = find(neighborsID(indexVehicleTX(i),:)); @@ -53,7 +49,7 @@ resultingList(indexRaw,1) = IDvehicleTXLTE(i); resultingList(indexRaw,2) = IDvehicleRX; resultingList(indexRaw,3) = stationManagement.BRid(IDvehicleTXLTE(i),stationManagement.pckTxOccurring(IDvehicleTXLTE(i))); - resultingList(indexRaw,4) = distance(indexVehicleTX(i),stationManagement.activeIDsCV2X==IDvehicleRX); + resultingList(indexRaw,4) = distance(indexVehicleTX(i), IDvehicleRX); resultingList(indexRaw,5) = 1; % COLUMN 5=1 IS "CORRECT" % Mark that this packet has been received stationManagement.pckReceived(IDvehicleRX,IDvehicleTXLTE(i))=1; @@ -67,7 +63,7 @@ resultingList(indexRaw,1) = IDvehicleTXLTE(i); resultingList(indexRaw,2) = IDvehicleRX; resultingList(indexRaw,3) = stationManagement.BRid(IDvehicleTXLTE(i),stationManagement.pckTxOccurring(IDvehicleTXLTE(i))); - resultingList(indexRaw,4) = distance(indexVehicleTX(i),stationManagement.activeIDsCV2X==IDvehicleRX); + resultingList(indexRaw,4) = distance(indexVehicleTX(i), IDvehicleRX); resultingList(indexRaw,5) = 0; % COLUMN 5=0 IS "ERROR" elseif ~isinf(phyParams.Ksi) || isempty(find(IDvehicleTXLTE == IDvehicleRX, 1)) % ERROR IN ATTEMPT (NOT THE LAST ONE) AND THE RECEIVER IS NOT diff --git a/MainFilesCV2X/initLastPowerCV2X.m b/MainFilesCV2X/initLastPowerCV2X.m index 0a3f855..9d74f90 100644 --- a/MainFilesCV2X/initLastPowerCV2X.m +++ b/MainFilesCV2X/initLastPowerCV2X.m @@ -51,7 +51,7 @@ % ID rx vehicle IDrx = stationManagement.neighborsIDLTE(stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE(i_tx),j_neigh); - RxPowerIDrx = RXpower_MHz_ofLTE(stationManagement.activeIDsCV2X==IDrx,stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE); + RxPowerIDrx = RXpower_MHz_ofLTE(IDrx,stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE); % Find BRT in use by rx vehicle j %BRTrx = BRidT(IDrx); @@ -120,4 +120,4 @@ % sinrManagement.neighPowerInterfLastLTE(i_tx,j_neigh) = (selfI + Itot) * phyParams.BwMHz_cv2xBR + Ifrom11p; end end -end \ No newline at end of file +end diff --git a/MainFilesCV2X/mainCV2XttiEnds.m b/MainFilesCV2X/mainCV2XttiEnds.m index d8feaaa..71b7c39 100644 --- a/MainFilesCV2X/mainCV2XttiEnds.m +++ b/MainFilesCV2X/mainCV2XttiEnds.m @@ -8,7 +8,7 @@ % geneated in a subframe during which the station is transmitting is % not correctly managed for idLte = stationManagement.activeIDsCV2X' - if stationManagement.pckBuffer(idLte)>1 + if stationManagement.pckBuffer(idLte) > appParams.bufferLength [stationManagement,outputValues] = bufferOverflowLTE(idLte,timeManagement,positionManagement,stationManagement,phyParams,appParams,outputValues,outParams); stationManagement.pckNextAttempt(idLte) = 1; end @@ -48,12 +48,12 @@ stationManagement.BRid(stationManagement.activeIDsCV2X(hasNewPacketThisTbeacon),:) = BRidModified; end -elseif mod(timeManagement.elapsedTime_TTIs,appParams.NbeaconsT)==0 +elseif timeManagement.elapsedTime_TTIs == 1 || mod(timeManagement.elapsedTime_TTIs,appParams.NbeaconsT) == 0 % All other algorithms except standard Mode 4 % TODO not checked in version 5.X %% Radio Resources Reassignment - if simParams.BRAlgorithm==constants.REASSIGN_BR_REUSE_DIS_SCHEDULED_VEH || simParams.BRAlgorithm==constants.REASSIGN_BR_MAX_REUSE_DIS || simParams.BRAlgorithm==constants.REASSIGN_BR_MIN_REUSE_POW + if ismember(simParams.BRAlgorithm, constants.REASSIGN_BR_ALGORITHMS_CONTROLLED) if timeManagement.elapsedTime_TTIs > 0 % Current scheduled reassign period @@ -79,7 +79,7 @@ % BRs reassignment (CONTROLLED with MAXIMUM REUSE DISTANCE) %[stationManagement.BRid,Nreassign] = BRreassignmentControlledMaxReuse(stationManagement.activeIDsCV2X,stationManagement.BRid,scheduledID,stationManagement.neighborsIDLTE,appParams.NbeaconsT,appParams.NbeaconsF); - [stationManagement.BRid,Nreassign] = BRreassignmentControlledMaxReuse(stationManagement.activeIDsCV2X,stationManagement.BRid,scheduledID,stationManagement.allNeighborsID,appParams.NbeaconsT,appParams.NbeaconsF); + [stationManagement.BRid,Nreassign] = BRreassignmentControlledMaxReuse(stationManagement.activeIDsCV2X,stationManagement.BRid,scheduledID,stationManagement.allNeighborsIDEstimated,appParams.NbeaconsT,appParams.NbeaconsF); elseif simParams.BRAlgorithm == constants.REASSIGN_BR_MIN_REUSE_POW @@ -113,7 +113,7 @@ elseif simParams.BRAlgorithm==constants.REASSIGN_BR_ORDERED_ALLOCATION % Call Benchmark Algorithm 102 (ORDERED ALLOCATION) - [stationManagement.BRid,Nreassign] = BRreassignmentOrdered(positionManagement.XvehicleReal,stationManagement.activeIDsCV2X,stationManagement.BRid,appParams.NbeaconsT,appParams.NbeaconsF); + [stationManagement.BRid,Nreassign] = BRreassignmentOrdered(positionManagement.XvehicleEstimated,stationManagement.activeIDsCV2X,stationManagement.BRid,appParams.NbeaconsT,appParams.NbeaconsF); end diff --git a/MainFilesCV2X/mainCV2XttiStarts.m b/MainFilesCV2X/mainCV2XttiStarts.m index a3de990..aa486a7 100644 --- a/MainFilesCV2X/mainCV2XttiStarts.m +++ b/MainFilesCV2X/mainCV2XttiStarts.m @@ -30,7 +30,9 @@ currentT = (mod((timeManagement.elapsedTime_TTIs-1),appParams.NbeaconsT)+1); idLteHasPck = stationManagement.activeIDsCV2X(stationManagement.pckBuffer(stationManagement.activeIDsCV2X) >= 1); for idLte = idLteHasPck' - attemptToDo = stationManagement.pckNextAttempt(idLte); + % attemptToDo = stationManagement.pckNextAttempt(idLte); + % was BRid ever going to have more than one column...? + attemptToDo = 1; if ceil((stationManagement.BRid(idLte,attemptToDo))/appParams.NbeaconsF)==currentT stationManagement.transmittingIDsCV2X(iTransmitting) = idLte; stationManagement.transmittingFusedLTE(iTransmitting) = mod((stationManagement.BRid(idLte,attemptToDo))-1,appParams.NbeaconsF)+1; @@ -40,7 +42,7 @@ end end % hasTransmissionThisSlot introduced from version 6.2 -stationManagement.hasTransmissionThisSlot(stationManagement.transmittingIDsCV2X)=1; +stationManagement.hasTransmissionThisSlot(find(ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X))) = 1; %% timeManagement.timeGeneratedPacketInTxLTE(stationManagement.transmittingIDsCV2X) = timeManagement.timeLastPacket(stationManagement.transmittingIDsCV2X); @@ -71,7 +73,7 @@ % This has been done to allow the possibility of allowing the possibility % of triggering retransmissions if ~isempty(stationManagement.transmittingIDsCV2X) - stationManagement.pckTxOccurring(stationManagement.transmittingIDsCV2X) = stationManagement.pckNextAttempt(stationManagement.transmittingIDsCV2X); + stationManagement.pckTxOccurring(stationManagement.transmittingIDsCV2X) = logical(stationManagement.pckNextAttempt(stationManagement.transmittingIDsCV2X)); stationManagement.pckNextAttempt(stationManagement.transmittingIDsCV2X) = stationManagement.pckNextAttempt(stationManagement.transmittingIDsCV2X) + 1; txIDlastTx = stationManagement.transmittingIDsCV2X(stationManagement.pckNextAttempt(stationManagement.transmittingIDsCV2X)>stationManagement.cv2xNumberOfReplicas(stationManagement.transmittingIDsCV2X)); stationManagement.pckBuffer(txIDlastTx) = stationManagement.pckBuffer(txIDlastTx)-1; diff --git a/MainFilesCV2X/updateKPICV2X.m b/MainFilesCV2X/updateKPICV2X.m index 56bf9ea..47feecd 100644 --- a/MainFilesCV2X/updateKPICV2X.m +++ b/MainFilesCV2X/updateKPICV2X.m @@ -83,11 +83,15 @@ if simParams.typeOfScenario==constants.SCENARIO_TRACE && outParams.printPRRmap simValues = counterMap(iPhyRaw,simValues,stationManagement.activeIDsCV2X,indexInActiveIDsOnlyLTE,activeIDsTXLTE,awarenessID_LTE(:,:,iPhyRaw),errorMatrix); end - + + if outParams.printHiddenNodeEvents + hiddenNodeEvents = countHiddenNodeEvents(errorRxList=errorRxList, awarenessIDLTE=stationManagement.awarenessIDLTE(:,:,iPhyRaw), BRid=stationManagement.BRid, NbeaconsT=appParams.NbeaconsT, duplexCV2X=phyParams.duplexCV2X); + outputValues.hiddenNodeEvents(iPhyRaw) = outputValues.hiddenNodeEvents(iPhyRaw) + hiddenNodeEvents; + end end % Count distance details for distances up to the maximum awareness range (if enabled) if outParams.printPacketReceptionRatio %outputValues.distanceDetailsCounterCV2X = countDistanceDetails(indexInActiveIDsOnlyLTE,activeIDsTXLTE,neighborsID_LTE,stationManagement.neighborsDistanceLTE,errorMatrixRawMax,outputValues.distanceDetailsCounterCV2X,stationManagement,outParams,appParams,phyParams); outputValues.distanceDetailsCounterCV2X = countDistanceDetails(fateRxListRawMax(fateRxListRawMax(:,5)==1,:),fateRxListRawMax(fateRxListRawMax(:,5)==0,:),outputValues.distanceDetailsCounterCV2X,stationManagement,outParams,appParams,phyParams); -end \ No newline at end of file +end diff --git a/MainFilesIEEE802.11p/updateVehicleEndingTx11p.m b/MainFilesIEEE802.11p/updateVehicleEndingTx11p.m index 45b6a95..7c58931 100644 --- a/MainFilesIEEE802.11p/updateVehicleEndingTx11p.m +++ b/MainFilesIEEE802.11p/updateVehicleEndingTx11p.m @@ -42,7 +42,7 @@ % in idle state stationManagement.vehicleState(idEvent) = constants.V_STATE_11P_IDLE; % idle timeManagement.timeNextTxRx11p(idEvent) = Inf; - elseif stationManagement.pckBuffer(idEvent) >= 1 + elseif stationManagement.pckBuffer(idEvent) >= appParams.bufferLength % If there are other packets in the queue, a new % backoff is initialized and started % in this case is retransmission, because the queue only has one diff --git a/MatFilesInit/constants.m b/MatFilesInit/constants.m index eed80b3..9111aab 100644 --- a/MatFilesInit/constants.m +++ b/MatFilesInit/constants.m @@ -151,9 +151,14 @@ % ORDERED ALLOCATION (following X coordinate) REASSIGN_BR_ORDERED_ALLOCATION = 102; - % ***** this two Algorithms used as benchmarks ***** - + REASSIGN_BR_ALGORITHMS_CONTROLLED = [constants.REASSIGN_BR_REUSE_DIS_SCHEDULED_VEH + constants.REASSIGN_BR_MAX_REUSE_DIS + constants.REASSIGN_BR_POW_CONTROL + constants.REASSIGN_BR_MIN_REUSE_POW + constants.REASSIGN_BR_ORDERED_ALLOCATION]; + REASSIGN_BR_ALGORITHMS_AUTONOMOUS = [constants.REASSIGN_BR_STD_MODE_4 + constants.REASSIGN_BR_RAND_ALLOCATION]; %% **************************************** %% CHANNEL MODEL diff --git a/MatFilesInit/initiateApplicationParameters.m b/MatFilesInit/initiateApplicationParameters.m index a377eb5..5a24d58 100644 --- a/MatFilesInit/initiateApplicationParameters.m +++ b/MatFilesInit/initiateApplicationParameters.m @@ -153,7 +153,13 @@ % if simParams.mco_nVehInterf<0 % error('Error: "simParams.mco_nVehInterf" cannot be < 0'); % end - + +% [bufferLength] +[appParams,varargin]= addNewParam(appParams,'bufferLength',1,'Length of the vehicle packet buffer','integer',fileCfg,varargin{1}); +if appParams.bufferLength<1 + error('bufferLength must be >= 1'); +end + fprintf('\n'); % %%%%%%%%% diff --git a/MatFilesInit/initiateBRAssignmentAlgorithm.m b/MatFilesInit/initiateBRAssignmentAlgorithm.m index a3b536f..da1c146 100644 --- a/MatFilesInit/initiateBRAssignmentAlgorithm.m +++ b/MatFilesInit/initiateBRAssignmentAlgorithm.m @@ -1,324 +1,276 @@ -function [simParams,phyParams,varargin] = initiateBRAssignmentAlgorithm(simParams,phyParams,Tbeacon,fileCfg,varargin) -% function [simParams,varargin]= initiateBRAssignmentAlgorithm(simParams,fileCfg,varargin) -% -% Main settings of the simulation -% It takes in input the structure simParams, the name of the (possible) file config and the inputs -% of the main function -% It returns the structure "simParams" - -fprintf('Settings of resource assignement algorithm\n'); - -% [BRAlgorithm] -% Selects the BR reassignment algorithm: -% Check .../MatFilesInit/constants.m for details -% 2 -> CONTROLLED with REUSE DISTANCE and scheduled vehicles -% 7 -> CONTROLLED with MAXIMUM REUSE DISTANCE (MRD) -% 8 -> AUTONOMOUS with SENSING (3GPP STANDARD MODE 4) - ON A BEACON PERIOD BASIS -% 18 -> AUTONOMOUS with SENSING (3GPP STANDARD LTE-MODE-4 or NR-MODE-2) - ON A SLOT BASIS -% -% 9 -> CONTROLLED with POWER CONTROL -% 10 -> CONTROLLED with MINIMUM REUSE POWER (MRP) - -% [BENCHMARKS Algorithms] -% Algorithms used as benchmarks -% 101 -> RANDOM ALLOCATION -% 102 -> ORDERED ALLOCATION (following X coordinate) - -[simParams,varargin] = addNewParam(simParams,'BRAlgorithm',constants.REASSIGN_BR_STD_MODE_4,'Assignment algorithm','integer',fileCfg,varargin{1}); -switch simParams.BRAlgorithm - case constants.REASSIGN_BR_REUSE_DIS_SCHEDULED_VEH % CONTROLLED with REUSE DISTANCE and scheduled vehicles +function [simParams, phyParams, varargin] = initiateBRAssignmentAlgorithm(simParams, phyParams, Tbeacon, fileCfg, varargin) + % function [simParams,varargin]= initiateBRAssignmentAlgorithm(simParams,fileCfg,varargin) + % + % Main settings of the simulation + % It takes in input the structure simParams, the name of the (possible) file config and the inputs + % of the main function + % It returns the structure "simParams" + + fprintf('Settings of resource assignement algorithm\n'); + + % [BRAlgorithm] + % Selects the BR reassignment algorithm: + % Check .../MatFilesInit/constants.m for details + % 2 -> CONTROLLED with REUSE DISTANCE and scheduled vehicles + % 7 -> CONTROLLED with MAXIMUM REUSE DISTANCE (MRD) + % 8 -> AUTONOMOUS with SENSING (3GPP STANDARD MODE 4) - ON A BEACON PERIOD BASIS + % 18 -> AUTONOMOUS with SENSING (3GPP STANDARD LTE-MODE-4 or NR-MODE-2) - ON A SLOT BASIS + % + % 9 -> CONTROLLED with POWER CONTROL + % 10 -> CONTROLLED with MINIMUM REUSE POWER (MRP) + + % [BENCHMARKS Algorithms] + % Algorithms used as benchmarks + % 101 -> RANDOM ALLOCATION + % 102 -> ORDERED ALLOCATION (following X coordinate) + + implementedAlgorithms = [constants.REASSIGN_BR_ALGORITHMS_CONTROLLED ; constants.REASSIGN_BR_ALGORITHMS_AUTONOMOUS]; + + [simParams, varargin] = addNewParam(simParams, 'BRAlgorithm', constants.REASSIGN_BR_STD_MODE_4, 'Assignment algorithm', 'integer', fileCfg, varargin{1}); + if ~ismember(simParams.BRAlgorithm, implementedAlgorithms) + error('Error: "simParams.BRAlgorithm" not valid. Algorithm not implemented.'); + end + + % Add parameters common to all controlled algorithms + if ismember(simParams.BRAlgorithm, constants.REASSIGN_BR_ALGORITHMS_CONTROLLED) + % [posDelay] + % LTE position delay + [simParams, varargin] = addNewParam(simParams, 'posDelay', 0, 'V2NB Positioning Delay (only controlled BR algorithms) (s)', 'double', fileCfg, varargin{1}); + if simParams.posDelay < 0 + error('Error: "simParams.posDelay" cannot be negative'); + end + % [posError95] % LTE Positioning Accuracy (Gaussian model): 95th percentile of the error (m) - [simParams,varargin] = addNewParam(simParams,'posError95',0,'LTE positioning error - 95th percentile (only controlled) (m)','double',fileCfg,varargin{1}); - simParams.sigmaPosError = simParams.posError95/1.96; % Standard deviation of the error (m) - + [simParams, varargin] = addNewParam(simParams, 'posError95', 0, 'V2NB Positioning error - 95th percentile (only controlled BR algorithms) (m)', 'double', fileCfg, varargin{1}); + if simParams.posError95 < 0 + error('Error: "simParams.posError95" cannot be negative'); + end + simParams.sigmaPosError = simParams.posError95 / 1.96; % Standard deviation of the error (m) + + % [posPacketLoss] + [simParams, varargin] = addNewParam(simParams, 'posPacketLoss', 0, 'V2NB Positioning Signal Packet Loss Probability (only controlled BR algorithms)', 'double', fileCfg, varargin{1}); + if simParams.posPacketLoss < 0 || simParams.posPacketLoss > 1 + error('Error: "simParams.posPacketLoss must be 0 <= p < 1'); + end + % [Tupdate] % Time interval between each position update at the eNodeBs (s) - [simParams,varargin]= addNewParam(simParams,'Tupdate',Tbeacon,'Time interval between position updates at the eNodeBs (s)','double',fileCfg,varargin{1}); - if simParams.Tupdate<=0 + [simParams, varargin] = addNewParam(simParams, 'Tupdate', Tbeacon, 'Time interval between position updates at the eNodeBs (s)', 'double', fileCfg, varargin{1}); + if simParams.Tupdate <= 0 error('Error: "simParams.Tupdate" cannot <= 0'); end - - % [Mreuse] - % Reuse margin (m) (only valid for controlled LTE-V2V with reuse distance [BRAlgorithm 2]) - [simParams,varargin]= addNewParam(simParams,'Mreuse',0,'Reuse margin (m)','integer',fileCfg,varargin{1}); - - % [Treassign] - % Time interval between each scheduled BR reassignment (BRAlgorithm 2,7,9,10) (s) - % By default it is set equal to the beacon period - [simParams,varargin]= addNewParam(simParams,'Treassign',Tbeacon,'Interval of scheduled reassignment (BRAlgorithm 2,7,9,10) (s)','double',fileCfg,varargin{1}); - if simParams.Treassign<=0 - error('Error: "simParams.Treassign" cannot be <= 0.'); - end - case constants.REASSIGN_BR_MAX_REUSE_DIS % CONTROLLED with MAXIMUM REUSE DISTANCE (MRD) - simParams.posError95 = 0; - simParams.sigmaPosError = 0; - simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; % [Treassign] - % Time interval between each scheduled BR reassignment (BRAlgorithm 2,7,9,10) (s) + % Time interval between each scheduled BR reassignment (Controlled BR algorithms) (s) % By default it is set equal to the beacon period - [simParams,varargin]= addNewParam(simParams,'Treassign',Tbeacon,'Interval of scheduled reassignment (BRAlgorithm 2,7,9,10) (s)','double',fileCfg,varargin{1}); - if simParams.Treassign<=0 + [simParams, varargin] = addNewParam(simParams, 'Treassign', Tbeacon, 'Interval of scheduled reassignment (Controlled BR algorithms) (s)', 'double', fileCfg, varargin{1}); + if simParams.Treassign <= 0 error('Error: "simParams.Treassign" cannot be <= 0.'); end - case constants.REASSIGN_BR_POW_CONTROL % CONTROLLED with POWER CONTROL + else + simParams.posDelay = 0; simParams.posError95 = 0; + simParams.posPacketLoss = 0; simParams.sigmaPosError = 0; simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; + simParams.Mreuse = 0; + end - % [Treassign] - % Time interval between each scheduled BR reassignment (BRAlgorithm 2,7,9,10) (s) - % By default it is set equal to the beacon period - [simParams,varargin]= addNewParam(simParams,'Treassign',Tbeacon,'Interval of scheduled reassignment (BRAlgorithm 2,7,9,10) (s)','double',fileCfg,varargin{1}); - if simParams.Treassign<=0 - error('Error: "simParams.Treassign" cannot be <= 0.'); - end - case constants.REASSIGN_BR_MIN_REUSE_POW % CONTROLLED with MINIMUM REUSE POWER (MRP) - simParams.posError95 = 0; - simParams.sigmaPosError = 0; - simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; + % Initalize BRAlgorithm-specific parameters + switch simParams.BRAlgorithm + case constants.REASSIGN_BR_REUSE_DIS_SCHEDULED_VEH % CONTROLLED with REUSE DISTANCE and scheduled vehicles + % [Mreuse] + % Reuse margin (m) (only valid for controlled LTE-V2V with reuse distance [BRAlgorithm 2]) + [simParams, varargin] = addNewParam(simParams, 'Mreuse', 0, 'Reuse margin (m)', 'integer', fileCfg, varargin{1}); + case constants.REASSIGN_BR_MIN_REUSE_POW % CONTROLLED with MINIMUM REUSE POWER (MRP) + % [knownShadowing] + % Selects if shadowing is estimated at the eNB side + [simParams, varargin] = addNewParam(simParams, 'knownShadowing', false, 'if shadowing is estimated at the eNB side', 'bool', fileCfg, varargin{1}); + case constants.REASSIGN_BR_STD_MODE_4 % AUTONOMOUS with SENSING (3GPP STANDARD MODE 4) - ON A SUBFRAME BASIS + simParams.posError95 = 0; + simParams.sigmaPosError = 0; + simParams.Tupdate = Tbeacon; + simParams.Mreuse = 0; - % [Treassign] - % Time interval between each scheduled BR reassignment (BRAlgorithm 2,7,9,10) (s) - % By default it is set equal to the beacon period - [simParams,varargin]= addNewParam(simParams,'Treassign',Tbeacon,'Interval of scheduled reassignment (BRAlgorithm 2,7,9,10) (s)','double',fileCfg,varargin{1}); - if simParams.Treassign<=0 - error('Error: "simParams.Treassign" cannot be <= 0.'); - end + % [resourceReEvaluation] + % Enables the the resource re-evaluation in 5G + [simParams, varargin] = addNewParam(simParams, 'resourceReEvaluation', false, 'Activates the resource re-evaluation in NR-V2X', 'bool', fileCfg, varargin{1}); + if simParams.resourceReEvaluation == true && simParams.mode5G ~= 1 + error('Error: "simParams.mode5G" must be equal to: 5G-V2X when resource re-evaluation is active'); + end - % [knownShadowing] - % Selects if shadowing is estimated at the eNB side - [simParams,varargin]= addNewParam(simParams,'knownShadowing',false,'if shadowing is estimated at the eNB side','bool',fileCfg,varargin{1}); + % [reEvalAfterEmptyResource] + % Enables the the resource re-evaluation after a user has not transmitted in a previously reserved resource + [simParams, varargin] = addNewParam(simParams, 'reEvalAfterEmptyResource', false, 'Activates the resource re-evaluation in NR-V2X after empty transmission', 'bool', fileCfg, varargin{1}); + if simParams.reEvalAfterEmptyResource == true && simParams.mode5G ~= 1 + error('Error: "simParams.mode5G" must be equal to: 5G-V2X when resource re-evaluation is active'); + end + if simParams.reEvalAfterEmptyResource == true && simParams.resourceReEvaluation == false + error('Error: "simParams.reEvalAfterEmptyResource" cannot be true when resourceReEvaluation is false'); + end - case constants.REASSIGN_BR_STD_MODE_4 % AUTONOMOUS with SENSING (3GPP STANDARD MODE 4) - ON A SUBFRAME BASIS - simParams.posError95 = 0; - simParams.sigmaPosError = 0; - simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; + % [dynamicScheduling] + % Enables the dynamic scheduling: resources are changed at each generation + [simParams, varargin] = addNewParam(simParams, 'dynamicScheduling', false, 'Probability to keep the previously selected BR', 'bool', fileCfg, varargin{1}); - % [resourceReEvaluation] - % Enables the the resource re-evaluation in 5G - [simParams,varargin]= addNewParam(simParams,'resourceReEvaluation',false,'Activates the resource re-evaluation in NR-V2X','bool',fileCfg,varargin{1}); - if simParams.resourceReEvaluation == true && simParams.mode5G ~=1 - error('Error: "simParams.mode5G" must be equal to: 5G-V2X when resource re-evaluation is active'); - end + % [probResKeep] + % Probability to keep the previously selected BR + [simParams, varargin] = addNewParam(simParams, 'probResKeep', 0.8 * (~simParams.dynamicScheduling), 'Probability to keep the previously selected BR', 'double', fileCfg, varargin{1}); + if simParams.probResKeep < 0 || simParams.probResKeep > 1 + error('Error: "simParams.probResKeep" must be within 0 and 0.8. In this version it can take also values bigger than 0.8'); + elseif simParams.probResKeep > 0.8 && simParams.probResKeep <= 1 + warning('Warning: "simParams.probResKeep" must be within 0 and 0.8 according to specifications. A value bigger than 0.8 has been inserted'); + end + if simParams.dynamicScheduling == true && simParams.probResKeep ~= 0 + error('Error: "simParams.probResKeep" must be 0 when Dynamic Scheduling is selected'); + end - % [reEvalAfterEmptyResource] - % Enables the the resource re-evaluation after a user has not transmitted in a previously reserved resource - [simParams,varargin]= addNewParam(simParams,'reEvalAfterEmptyResource',false,'Activates the resource re-evaluation in NR-V2X after empty transmission','bool',fileCfg,varargin{1}); - if simParams.reEvalAfterEmptyResource == true && simParams.mode5G ~=1 - error('Error: "simParams.mode5G" must be equal to: 5G-V2X when resource re-evaluation is active'); - end - if simParams.reEvalAfterEmptyResource == true && simParams.resourceReEvaluation == false - error('Error: "simParams.reEvalAfterEmptyResource" cannot be true when resourceReEvaluation is false'); - end + % [ratioSelectedAutonomousMode] + % Percentage of resources to be considered for random selection + [simParams, varargin] = addNewParam(simParams, 'ratioSelectedAutonomousMode', 0.2, 'Percentage of resources to be considered for random selection', 'double', fileCfg, varargin{1}); + if simParams.ratioSelectedAutonomousMode < 0.2 || simParams.ratioSelectedAutonomousMode > 1 + error('Error: "simParams.ratioSelectedAutonomousMode" must be more than 0.2 and not more than 1 (specs: 0.2)'); + end - % [dynamicScheduling] - % Enables the dynamic scheduling: resources are changed at each generation - [simParams,varargin]= addNewParam(simParams,'dynamicScheduling',false,'Probability to keep the previously selected BR','bool',fileCfg,varargin{1}); - - % [probResKeep] - % Probability to keep the previously selected BR - [simParams,varargin]= addNewParam(simParams,'probResKeep',0.8*(~simParams.dynamicScheduling),'Probability to keep the previously selected BR','double',fileCfg,varargin{1}); - if simParams.probResKeep<0 || simParams.probResKeep>1 - error('Error: "simParams.probResKeep" must be within 0 and 0.8. In this version it can take also values bigger than 0.8'); - elseif simParams.probResKeep>0.8 && simParams.probResKeep<=1 - warning('Warning: "simParams.probResKeep" must be within 0 and 0.8 according to specifications. A value bigger than 0.8 has been inserted'); - end - if simParams.dynamicScheduling == true && simParams.probResKeep~=0 - error('Error: "simParams.probResKeep" must be 0 when Dynamic Scheduling is selected'); - end + % [L2active] + % Parameter that gives the possibility to reintroduce L2 in mode2 + % By default (and specifications) is active in LTE and disabled in 5G + [simParams, varargin] = addNewParam(simParams, 'L2active', ~simParams.mode5G, 'Activate or De-activate L2 in mode2/mode4', 'bool', fileCfg, varargin{1}); - % [ratioSelectedAutonomousMode] - % Percentage of resources to be considered for random selection - [simParams,varargin]= addNewParam(simParams,'ratioSelectedAutonomousMode',0.2,'Percentage of resources to be considered for random selection','double',fileCfg,varargin{1}); - if simParams.ratioSelectedAutonomousMode<0.2 || simParams.ratioSelectedAutonomousMode>1 - error('Error: "simParams.ratioSelectedAutonomousMode" must be more than 0.2 and not more than 1 (specs: 0.2)'); - end + % [averageSensingActive] + % Parameter that gives the possibility to reintroduce the average sensing in mode2 + % By default (and specifications) is active in LTE and disabled in 5G + [simParams, varargin] = addNewParam(simParams, 'averageSensingActive', ~simParams.mode5G, 'Activate or De-activate the average sensing mode2/mode4', 'bool', fileCfg, varargin{1}); - % [L2active] - % Parameter that gives the possibility to reintroduce L2 in mode2 - % By default (and specifications) is active in LTE and disabled in 5G - [simParams,varargin]= addNewParam(simParams,'L2active',(~simParams.mode5G),'Activate or De-activate L2 in mode2/mode4','bool',fileCfg,varargin{1}); - - % [averageSensingActive] - % Parameter that gives the possibility to reintroduce the average sensing in mode2 - % By default (and specifications) is active in LTE and disabled in 5G - [simParams,varargin] = addNewParam(simParams,'averageSensingActive',(~simParams.mode5G),'Activate or De-activate the average sensing mode2/mode4','bool',fileCfg,varargin{1}); - - - % This can be used with same effect as averageSensingActive to unify the two conditions - % % [NsensingPeriod] - % % Number of beacon periods during which performing sensing - % [simParams,varargin{1}{1}]= addNewParam(simParams,'NsensingPeriod',10,'Number of beacon periods during which performing sensing','integer',fileCfg,varargin{1}{1}); - % if simParams.NsensingPeriod<=0 - % error('Error: "simParams.NsensingPeriod" must be larger than 0'); - % end - - % [TsensingPeriod] - % Duration of the sensing period, in seconds - [simParams,varargin]= addNewParam(simParams,'TsensingPeriod',1,'Duration of the sensing period, in seconds','double',fileCfg,varargin{1}); - if simParams.TsensingPeriod<=0 - error('Error: "simParams.TsensingPeriod" must be larger than 0'); - end + % This can be used with same effect as averageSensingActive to unify the two conditions + % % [NsensingPeriod] + % % Number of beacon periods during which performing sensing + % [simParams,varargin{1}{1}]= addNewParam(simParams,'NsensingPeriod',10,'Number of beacon periods during which performing sensing','integer',fileCfg,varargin{1}{1}); + % if simParams.NsensingPeriod<=0 + % error('Error: "simParams.NsensingPeriod" must be larger than 0'); + % end - % [minRandValueMode4] - % Minimum duration keeping the same allocation - [simParams,varargin]= addNewParam(simParams,'minRandValueMode4',-1,'Minimum duration keeping the same allocation','integer',fileCfg,varargin{1}); - if simParams.minRandValueMode4~=-1 && simParams.minRandValueMode4<=0 - error('Error: "simParams.minRandValueMode4" must be more than 0'); - end + % [TsensingPeriod] + % Duration of the sensing period, in seconds + [simParams, varargin] = addNewParam(simParams, 'TsensingPeriod', 1, 'Duration of the sensing period, in seconds', 'double', fileCfg, varargin{1}); + if simParams.TsensingPeriod <= 0 + error('Error: "simParams.TsensingPeriod" must be larger than 0'); + end - % [maxRandValueMode4] - % Maximum duration keeping the same allocation - [simParams,varargin]= addNewParam(simParams,'maxRandValueMode4',-1,'Maximum duration keeping the same allocation','integer',fileCfg,varargin{1}); - if simParams.maxRandValueMode4~=-1 && simParams.maxRandValueMode4<=simParams.minRandValueMode4 - error('Error: "simParams.maxRandValueMode4" must be larger than "simParams.minRandValueMode4"'); - end - - % [powerThresholdAutonomous] - % Minimum power threshold to consider a BR as occupied in dBm - [simParams,varargin]= addNewParam(simParams,'powerThresholdAutonomous',-110,'Minimum power threshold to consider a BR as occupied in Mode 4, in dBm','double',fileCfg,varargin{1}); - if simParams.powerThresholdAutonomous/2<-64 || simParams.powerThresholdAutonomous/2>-1 || mod(simParams.powerThresholdAutonomous,2)~=0 - error('Error: "simParams.powerThresholdAutonomous" must be between -128 and -2, step 2 dB'); - end - % From dBm to linear - simParams.powerThresholdAutonomous = db2pow(simParams.powerThresholdAutonomous-30); - - % [minSCIsinr] - % Minimum SINR for a SCI to be correctly decoded - [phyParams,varargin] = addNewParam(phyParams,'minSCIsinr',0,'Minimum SINR for a SCI to be correctly decoded, in dB','double',fileCfg,varargin{1}); - phyParams.minSCIsinr = db2pow(phyParams.minSCIsinr); - - % [asynMode] - % Enables Asynchronous transmitters - [simParams,varargin]= addNewParam(simParams,'asynMode',0,'Enables/Desable Asynchronous transmitters','integer',fileCfg,varargin{1}); - if (simParams.asynMode ~=0 && simParams.asynMode ~= 1) - error('Error: "simParams.asynMode" cannot different from 0 or 1'); - end - - % [percAsynUser] - % TODO - % if Asynchronous transmitters is active -> sets the percentage of - % Asynchronous users - if simParams.asynMode == 1 - [simParams,varargin]= addNewParam(simParams,'percAsynUser',0.2,'Percentage of asynchronous users','double',fileCfg,varargin{1}); - if simParams.percAsynUser<0 || simParams.percAsynUser>1 - error('Error: "simParams.percAsynUser" must be within 0 and 1'); + % [minRandValueMode4] + % Minimum duration keeping the same allocation + [simParams, varargin] = addNewParam(simParams, 'minRandValueMode4', -1, 'Minimum duration keeping the same allocation', 'integer', fileCfg, varargin{1}); + if simParams.minRandValueMode4 ~= -1 && simParams.minRandValueMode4 <= 0 + error('Error: "simParams.minRandValueMode4" must be more than 0'); end - end - % [FDalgorithm] - % Enables different FD algorithm - [simParams,varargin]= addNewParam(simParams,'FDalgorithm',0,'Enables FD algorithm','integer',fileCfg,varargin{1}); - if simParams.FDalgorithm~=0 && phyParams.PDelta==Inf - error('Error: "phyParams.PDelta" must be defined'); - end - if simParams.FDalgorithm~=0 && phyParams.duplexCV2X~="FD" - error('Error: "phyParams.duplexCV2X" must be "FD"'); - end - if ismember(simParams.FDalgorithm,[1,2]) && phyParams.cv2xNumberOfReplicasMax==2 - error('Error: "phyParams.cv2xNumberOfReplicasMax" must be equal to 1'); - end - if ismember(simParams.FDalgorithm,[3,4,5,6,7,8]) && phyParams.cv2xNumberOfReplicasMax~=2 - error('Error: "phyParams.cv2xNumberOfReplicasMax" must be equal to 2'); - end - if simParams.FDalgorithm~=0 && simParams.mode5G ~=1 - error('Error: "simParams.mode5G" must be equal to: 5G-V2X'); - end + % [maxRandValueMode4] + % Maximum duration keeping the same allocation + [simParams, varargin] = addNewParam(simParams, 'maxRandValueMode4', -1, 'Maximum duration keeping the same allocation', 'integer', fileCfg, varargin{1}); + if simParams.maxRandValueMode4 ~= -1 && simParams.maxRandValueMode4 <= simParams.minRandValueMode4 + error('Error: "simParams.maxRandValueMode4" must be larger than "simParams.minRandValueMode4"'); + end - % [dynamicPDelta] - % Enables dynamic setting of PDelta - [simParams,varargin]= addNewParam(simParams,'dynamicPDelta',0,'Enables dynamic setting of PDelta','integer',fileCfg,varargin{1}); - if (simParams.dynamicPDelta==1 && phyParams.duplexCV2X~="FD") || (simParams.dynamicPDelta==1 && simParams.FDalgorithm==0) - error('Error: "phyParams.duplexCV2X" must be "FD" or incompatible settings'); - end + % [powerThresholdAutonomous] + % Minimum power threshold to consider a BR as occupied in dBm + [simParams, varargin] = addNewParam(simParams, 'powerThresholdAutonomous', -110, 'Minimum power threshold to consider a BR as occupied in Mode 4, in dBm', 'double', fileCfg, varargin{1}); + if simParams.powerThresholdAutonomous / 2 < -64 || simParams.powerThresholdAutonomous / 2 > -1 || mod(simParams.powerThresholdAutonomous, 2) ~= 0 + error('Error: "simParams.powerThresholdAutonomous" must be between -128 and -2, step 2 dB'); + end + % From dBm to linear + simParams.powerThresholdAutonomous = db2pow(simParams.powerThresholdAutonomous - 30); + + % [minSCIsinr] + % Minimum SINR for a SCI to be correctly decoded + [phyParams, varargin] = addNewParam(phyParams, 'minSCIsinr', 0, 'Minimum SINR for a SCI to be correctly decoded, in dB', 'double', fileCfg, varargin{1}); + phyParams.minSCIsinr = db2pow(phyParams.minSCIsinr); - % [T1autonomousMode] - % Minimum time for the next allocation in ms - % For 5G, T1 is modelled as the sum of Tproc,0 and Tproc,1 - % Tproc,1 must be smaller to 3, 2.5, or 2.25 ms for a SCS of 15, 30, 60 kHz, respectively. - % Tproc,0 is equivalent to 1 ms for a SCS of 15 kHz and 0.50 ms for the rest of SCS configurations. - - if phyParams.muNumerology==0 % 4G and 5G SCS=15 - [simParams,varargin]= addNewParam(simParams,'T1autonomousMode',1,'Minimum time for the next allocation in Autonomous Mode','integer',fileCfg,varargin{1}); - if simParams.T1autonomousMode<1 || simParams.T1autonomousMode>4 - error('Error: "simParams.T1autonomousMode" must be between 1 and 4 in LTE and 5G SCS=15'); + % [asynMode] + % Enables Asynchronous transmitters + [simParams, varargin] = addNewParam(simParams, 'asynMode', 0, 'Enables/Desable Asynchronous transmitters', 'integer', fileCfg, varargin{1}); + if simParams.asynMode ~= 0 && simParams.asynMode ~= 1 + error('Error: "simParams.asynMode" cannot different from 0 or 1'); end - elseif phyParams.muNumerology==1 || phyParams.muNumerology==2 % 5G SCS=30 and 5G SCS=60 - [simParams,varargin]= addNewParam(simParams,'T1autonomousMode',0.5,'Minimum time for the next allocation in Autonomous Mode','double',fileCfg,varargin{1}); - if (simParams.T1autonomousMode<0.5 || simParams.T1autonomousMode>3)&&(phyParams.muNumerology==1) - error('Error: "simParams.T1autonomousMode" must be between 0.5 and 3 in 5G with SCS=30'); - elseif (simParams.T1autonomousMode<0.5 || simParams.T1autonomousMode>2.75)&&(phyParams.muNumerology==2) - error('Error: "simParams.T1autonomousMode" must be between 0.5 and 2.75 in 5G with SCS=60'); + + % [percAsynUser] + % TODO + % if Asynchronous transmitters is active -> sets the percentage of + % Asynchronous users + if simParams.asynMode == 1 + [simParams, varargin] = addNewParam(simParams, 'percAsynUser', 0.2, 'Percentage of asynchronous users', 'double', fileCfg, varargin{1}); + if simParams.percAsynUser < 0 || simParams.percAsynUser > 1 + error('Error: "simParams.percAsynUser" must be within 0 and 1'); + end end - end - - % [T2autonomousMode] - % Maximum time for the next allocation in ms - [simParams,varargin]= addNewParam(simParams,'T2autonomousMode',100,'Maximum time for the next allocation in autonomous mode','integer',fileCfg,varargin{1}); - if simParams.T2autonomousMode<20 || simParams.T2autonomousMode>100 - error('Error: "simParams.T2autonomousMode" must be between 20 and 100 ms in LTE and 5G'); + + % [FDalgorithm] + % Enables different FD algorithm + [simParams, varargin] = addNewParam(simParams, 'FDalgorithm', 0, 'Enables FD algorithm', 'integer', fileCfg, varargin{1}); + if simParams.FDalgorithm ~= 0 && phyParams.PDelta == Inf + error('Error: "phyParams.PDelta" must be defined'); end - - simParams.T1autonomousModeTTIs = simParams.T1autonomousMode*(2^phyParams.muNumerology); % T1 in terms of TTIs - simParams.T2autonomousModeTTIs = simParams.T2autonomousMode*(2^phyParams.muNumerology); % T2 in terms of TTIs - case constants.REASSIGN_BR_RAND_ALLOCATION % RANDOM ALLOCATION - simParams.posError95 = 0; - simParams.sigmaPosError = 0; - simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; - - % [T1autonomousMode] - % Minimum time for the next allocation in ms - % For 5G, T1 is modelled as the sum of Tproc,0 and Tproc,1 - % Tproc,1 must be smaller to 3, 2.5, or 2.25 ms for a SCS of 15, 30, 60 kHz, respectively. - % Tproc,0 is equivalent to 1 ms for a SCS of 15 kHz and 0.50 ms for the rest of SCS configurations. - if hyParams.muNumerologyp == 0 % 4G and 5G SCS=15 - [simParams,varargin]= addNewParam(simParams,'T1autonomousMode',1,'Minimum time for the next allocation in Autonomous Mode','integer',fileCfg,varargin{1}); - if simParams.T1autonomousMode < 1 || simParams.T1autonomousMode > 4 - error('Error: "simParams.T1autonomousMode" must be between 1 and 4 in LTE and 5G SCS=15'); + if simParams.FDalgorithm ~= 0 && phyParams.duplexCV2X ~= "FD" + error('Error: "phyParams.duplexCV2X" must be "FD"'); end - elseif phyParams.muNumerology == 1 || phyParams.muNumerology == 2 % 5G SCS=30 and 5G SCS=60 - [simParams,varargin]= addNewParam(simParams,'T1autonomousMode',0.5,'Minimum time for the next allocation in Autonomous Mode','double',fileCfg,varargin{1}); - if (simParams.T1autonomousMode < 0.5 || simParams.T1autonomousMode > 3)&&(phyParams.muNumerology == 1) - error('Error: "simParams.T1autonomousMode" must be between 0.5 and 3 in 5G with SCS=30'); - elseif (simParams.T1autonomousMode < 0.5 || simParams.T1autonomousMode > 2.75)&&(phyParams.muNumerology == 2) - error('Error: "simParams.T1autonomousMode" must be between 0.5 and 2.75 in 5G with SCS=60'); + if ismember(simParams.FDalgorithm, [1, 2]) && phyParams.cv2xNumberOfReplicasMax == 2 + error('Error: "phyParams.cv2xNumberOfReplicasMax" must be equal to 1'); end - end - - % [T2autonomousMode] - % Maximum time for the next allocation in ms - [simParams,varargin]= addNewParam(simParams,'T2autonomousMode',100,'Maximum time for the next allocation in autonomous mode','integer',fileCfg,varargin{1}); - if simParams.T2autonomousMode<20 || simParams.T2autonomousMode>100 + if ismember(simParams.FDalgorithm, [3, 4, 5, 6, 7, 8]) && phyParams.cv2xNumberOfReplicasMax ~= 2 + error('Error: "phyParams.cv2xNumberOfReplicasMax" must be equal to 2'); + end + if simParams.FDalgorithm ~= 0 && simParams.mode5G ~= 1 + error('Error: "simParams.mode5G" must be equal to: 5G-V2X'); + end + + % [dynamicPDelta] + % Enables dynamic setting of PDelta + [simParams, varargin] = addNewParam(simParams, 'dynamicPDelta', 0, 'Enables dynamic setting of PDelta', 'integer', fileCfg, varargin{1}); + if (simParams.dynamicPDelta == 1 && phyParams.duplexCV2X ~= "FD") || (simParams.dynamicPDelta == 1 && simParams.FDalgorithm == 0) + error('Error: "phyParams.duplexCV2X" must be "FD" or incompatible settings'); + end + + % [T1autonomousMode] + % Minimum time for the next allocation in ms + % For 5G, T1 is modelled as the sum of Tproc,0 and Tproc,1 + % Tproc,1 must be smaller to 3, 2.5, or 2.25 ms for a SCS of 15, 30, 60 kHz, respectively. + % Tproc,0 is equivalent to 1 ms for a SCS of 15 kHz and 0.50 ms for the rest of SCS configurations. + + if phyParams.muNumerology == 0 % 4G and 5G SCS=15 + [simParams, varargin] = addNewParam(simParams, 'T1autonomousMode', 1, 'Minimum time for the next allocation in Autonomous Mode', 'integer', fileCfg, varargin{1}); + if simParams.T1autonomousMode < 1 || simParams.T1autonomousMode > 4 + error('Error: "simParams.T1autonomousMode" must be between 1 and 4 in LTE and 5G SCS=15'); + end + elseif phyParams.muNumerology == 1 || phyParams.muNumerology == 2 % 5G SCS=30 and 5G SCS=60 + [simParams, varargin] = addNewParam(simParams, 'T1autonomousMode', 0.5, 'Minimum time for the next allocation in Autonomous Mode', 'double', fileCfg, varargin{1}); + if (simParams.T1autonomousMode < 0.5 || simParams.T1autonomousMode > 3) && (phyParams.muNumerology == 1) + error('Error: "simParams.T1autonomousMode" must be between 0.5 and 3 in 5G with SCS=30'); + elseif (simParams.T1autonomousMode < 0.5 || simParams.T1autonomousMode > 2.75) && (phyParams.muNumerology == 2) + error('Error: "simParams.T1autonomousMode" must be between 0.5 and 2.75 in 5G with SCS=60'); + end + end + + % [T2autonomousMode] + % Maximum time for the next allocation in ms + [simParams, varargin] = addNewParam(simParams, 'T2autonomousMode', 100, 'Maximum time for the next allocation in autonomous mode', 'integer', fileCfg, varargin{1}); + if simParams.T2autonomousMode < 20 || simParams.T2autonomousMode > 100 error('Error: "simParams.T2autonomousMode" must be between 20 and 100 ms in LTE and 5G'); end - simParams.T1autonomousModeTTIs = simParams.T1autonomousMode*(2^phyParams.muNumerology); % T1 in terms of TTIs - simParams.T2autonomousModeTTIs = simParams.T2autonomousMode*(2^phyParams.muNumerology); % T2 in terms of TTIs - case constants.REASSIGN_BR_ORDERED_ALLOCATION % ORDERED ALLOCATION (following X coordinate) - simParams.posError95 = 0; - simParams.sigmaPosError = 0; - simParams.Tupdate = Tbeacon; - simParams.Mreuse=0; - otherwise - error('Error: "simParams.BRAlgorithm" not valid. Algorithm not implemented.'); -end -if ~ismember(simParams.BRAlgorithm, [constants.REASSIGN_BR_STD_MODE_4, constants.REASSIGN_BR_RAND_ALLOCATION]) - if phyParams.BRoverlapAllowed - error('Partial overlap in the frequency domain implemented only for Mode 4 (alg. 18) or Random (101)'); + simParams.T1autonomousModeTTIs = simParams.T1autonomousMode * (2^phyParams.muNumerology); % T1 in terms of TTIs + simParams.T2autonomousModeTTIs = simParams.T2autonomousMode * (2^phyParams.muNumerology); % T2 in terms of TTIs end - if phyParams.cv2xNumberOfReplicasMax > 1 - error('HHARQ implemented only for Mode 4 (alg. 18 and alg. 101)'); + if ~ismember(simParams.BRAlgorithm, [constants.REASSIGN_BR_STD_MODE_4, constants.REASSIGN_BR_RAND_ALLOCATION]) + if phyParams.BRoverlapAllowed + error('Partial overlap in the frequency domain implemented only for Mode 4 (alg. 18) or Random (101)'); + end + + if phyParams.cv2xNumberOfReplicasMax > 1 + error('HHARQ implemented only for Mode 4 (alg. 18 and alg. 101)'); + end end -end -fprintf('\n'); + fprintf('\n'); end diff --git a/MatFilesInit/initiateMainSimulationParameters.m b/MatFilesInit/initiateMainSimulationParameters.m index d0ccd06..048cb27 100644 --- a/MatFilesInit/initiateMainSimulationParameters.m +++ b/MatFilesInit/initiateMainSimulationParameters.m @@ -178,30 +178,18 @@ % [XminTrace] % Minimum X coordinate to keep in the traffic trace (m) [simParams,varargin] = addNewParam(simParams,'XminTrace',-1,'Minimum X coordinate to keep in the traffic trace (m)','double',fileCfg,varargin{1}); - if simParams.XminTrace~=-1 && simParams.XminTrace<0 - error('Error: the value set for "simParams.XminTrace" is not valid'); - end % [XmaxTrace] % Maximum X coordinate to keep in the traffic trace (m) [simParams,varargin] = addNewParam(simParams,'XmaxTrace',-1,'Maximum X coordinate to keep in the traffic trace (m)','double',fileCfg,varargin{1}); - if simParams.XmaxTrace~=-1 && simParams.XmaxTrace<0 && simParams.XmaxTrace