From 87e1f10914d70cdbc74af049b3909f9837295397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=8D=93=E9=9C=8F=5FFelix?= Date: Mon, 18 Dec 2023 00:13:51 +0800 Subject: [PATCH 1/3] debug for trace file 1. assume the speeds of the new entered vehicles are all zeros; 2. remove "stationManagement.hasTransmissioinThisSlot", using "stationManagement.transmittingIDsCV2X" instead; --- MainFiles/mainInit.m | 17 ++---- MainFiles/mainPositionUpdate.m | 29 +++++----- MainFilesCV2X/mainCV2XttiStarts.m | 5 +- MatFilesPosition/updatePositionFile.m | 58 +++++++------------ .../BRreassignment3GPPautonomous.m | 8 +-- .../CV2XsensingProcedure.m | 14 ++--- 6 files changed, 51 insertions(+), 80 deletions(-) diff --git a/MainFiles/mainInit.m b/MainFiles/mainInit.m index effe15e..1c262ca 100644 --- a/MainFiles/mainInit.m +++ b/MainFiles/mainInit.m @@ -54,14 +54,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.indexInActiveIDs_ofLTEnodes = zeros(length(stationManagement.activeIDsCV2X),1); -for i=1:length(stationManagement.activeIDsCV2X) - stationManagement.indexInActiveIDs_ofLTEnodes(i) = find(stationManagement.activeIDs==stationManagement.activeIDsCV2X(i)); -end -stationManagement.indexInActiveIDs_of11pnodes = zeros(length(stationManagement.activeIDs11p),1); -for i=1:length(stationManagement.activeIDs11p) - stationManagement.indexInActiveIDs_of11pnodes(i) = find(stationManagement.activeIDs==stationManagement.activeIDs11p(i)); -end +[~, stationManagement.indexInActiveIDs_ofLTEnodes] = ismember(stationManagement.activeIDsCV2X, stationManagement.activeIDs); +[~, stationManagement.indexInActiveIDs_of11pnodes] = ismember(stationManagement.activeIDs11p, stationManagement.activeIDs); %% Number of vehicles at the current time outputValues.Nvehicles = length(stationManagement.activeIDs); @@ -237,16 +231,13 @@ outputValues.enteredInRangeLTE = -1 * ones(simValues.maxID,simValues.maxID,length(phyParams.Raw)); for iRaw = 1:length(phyParams.Raw) valuesEnteredInRange = outputValues.enteredInRangeLTE(:,:,iRaw); - % fixme: when using tracefile, there may not be consecutive - % activeIDs (e.g. max ID in 140 cars is 150). But distanceReal has - % the number of activesIDs' rows and columns - valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X) = (positionManagement.distanceReal(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X)<=phyParams.Raw(iRaw))-1; + valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X) = (positionManagement.distanceReal(stationManagement.indexInActiveIDs_ofLTEnodes, stationManagement.indexInActiveIDs_ofLTEnodes)<=phyParams.Raw(iRaw))-1; outputValues.enteredInRangeLTE(:,:,iRaw) = valuesEnteredInRange - diag(diag(valuesEnteredInRange+1)); end outputValues.enteredInRange11p = -1 * ones(simValues.maxID,simValues.maxID,length(phyParams.Raw)); for iRaw = 1:length(phyParams.Raw) valuesEnteredInRange = outputValues.enteredInRange11p(:,:,iRaw); - valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p) = (positionManagement.distanceReal(stationManagement.activeIDs11p,stationManagement.activeIDs11p)<=phyParams.Raw(iRaw))-1; + valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p) = (positionManagement.distanceReal(stationManagement.indexInActiveIDs_of11pnodes, stationManagement.indexInActiveIDs_of11pnodes)<=phyParams.Raw(iRaw))-1; outputValues.enteredInRange11p(:,:,iRaw) = valuesEnteredInRange - diag(diag(valuesEnteredInRange+1)); end end diff --git a/MainFiles/mainPositionUpdate.m b/MainFiles/mainPositionUpdate.m index f696ac7..551be5c 100644 --- a/MainFiles/mainPositionUpdate.m +++ b/MainFiles/mainPositionUpdate.m @@ -25,14 +25,9 @@ stationManagement.activeIDsCV2X = stationManagement.activeIDsCV2X(stationManagement.activeIDsCV2X>0); stationManagement.activeIDs11p = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)~=100); stationManagement.activeIDs11p = stationManagement.activeIDs11p(stationManagement.activeIDs11p>0); -stationManagement.indexInActiveIDs_ofLTEnodes = zeros(length(stationManagement.activeIDsCV2X),1); -for i=1:length(stationManagement.activeIDsCV2X) - stationManagement.indexInActiveIDs_ofLTEnodes(i) = find(stationManagement.activeIDs==stationManagement.activeIDsCV2X(i)); -end -stationManagement.indexInActiveIDs_of11pnodes = zeros(length(stationManagement.activeIDs11p),1); -for i=1:length(stationManagement.activeIDs11p) - stationManagement.indexInActiveIDs_of11pnodes(i) = find(stationManagement.activeIDs==stationManagement.activeIDs11p(i)); -end +[~, stationManagement.indexInActiveIDs_ofLTEnodes] = ismember(stationManagement.activeIDsCV2X, stationManagement.activeIDs); +[~, stationManagement.indexInActiveIDs_of11pnodes] = ismember(stationManagement.activeIDs11p, stationManagement.activeIDs); + % % For possible DEBUG % figure(300) @@ -56,13 +51,17 @@ ( rand(length(stationManagement.activeIDs(indexNewVehicles)),1) * (2*simParams.coexA_desynchError) - simParams.coexA_desynchError); end end - % Update stationManagement.resReselectionCounterCV2X for vehicles exiting the scenario + % Update stationManagement.resReselectionCounterCV2X for vehicles EXITING the scenario stationManagement.resReselectionCounterCV2X(stationManagement.activeIDsExit) = Inf; - % Update stationManagement.resReselectionCounterCV2X for vehicles entering the scenario + + % Update stationManagement.resReselectionCounterCV2X for vehicles ENTERING the scenario % a) LTE vehicles that enter or are blocked start with a counter set to 0 % b) 11p vehicles are set to Inf - stationManagement.resReselectionCounterCV2X((stationManagement.BRid(:,1)==-1) & (stationManagement.vehicleState==constants.V_STATE_LTE_TXRX)) = 0; - stationManagement.resReselectionCounterCV2X((stationManagement.BRid(:,1)==-1) & (stationManagement.vehicleState~=constants.V_STATE_LTE_TXRX)) = Inf; + indexNewVehicleInAll = zeros(simValues.maxID,1); + indexNewVehicleInAll(stationManagement.activeIDs(indexNewVehicles)) = deal(1); + stationManagement.resReselectionCounterCV2X(indexNewVehicleInAll & (stationManagement.vehicleState==constants.V_STATE_LTE_TXRX)) = 0; + stationManagement.resReselectionCounterCV2X(indexNewVehicleInAll & (stationManagement.vehicleState~=constants.V_STATE_LTE_TXRX)) = Inf; + % Reset stationManagement.errorSCImatrixLTE for new computation of correctly received SCIs %stationManagement.correctSCImatrixCV2X = zeros(length(stationManagement.activeIDsCV2X),length(stationManagement.activeIDsCV2X)-1); end @@ -90,7 +89,7 @@ [positionManagement,stationManagement] = computeNeighbors (stationManagement,positionManagement,phyParams); % Floor coordinates for PRRmap creation (if enabled) -if simParams.typeOfScenario==2 && outParams.printPRRmap % only traffic trace +if simParams.typeOfScenario==constants.SCENARIO_TRACE && outParams.printPRRmap % only traffic trace simValues.XmapFloor = floor(simValues.Xmap); simValues.YmapFloor = floor(simValues.Ymap); end @@ -168,7 +167,7 @@ if ~isempty(stationManagement.activeIDsCV2X) for iRaw = 1:length(phyParams.Raw) valuesEnteredInRange = outputValues.enteredInRangeLTE(:,:,iRaw); - valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X) = (valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X)<0 & positionManagement.distanceReal(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X)<=phyParams.Raw(iRaw))*(1+timeManagement.timeNow)-1; + valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X) = (valuesEnteredInRange(stationManagement.activeIDsCV2X,stationManagement.activeIDsCV2X)<0 & positionManagement.distanceReal(stationManagement.indexInActiveIDs_ofLTEnodes,stationManagement.indexInActiveIDs_ofLTEnodes)<=phyParams.Raw(iRaw))*(1+timeManagement.timeNow)-1; valuesEnteredInRange( positionManagement.distanceReal > phyParams.Raw(iRaw) ) = -1; outputValues.enteredInRangeLTE(:,:,iRaw) = valuesEnteredInRange - (diag(diag(valuesEnteredInRange+1))); end @@ -177,7 +176,7 @@ if ~isempty(stationManagement.activeIDs11p) for iRaw = 1:length(phyParams.Raw) valuesEnteredInRange = outputValues.enteredInRange11p(:,:,iRaw); - valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p) = (valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p)<0 & positionManagement.distanceReal(stationManagement.activeIDs11p,stationManagement.activeIDs11p)<=phyParams.Raw(iRaw))*(1+timeManagement.timeNow)-1; + valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p) = (valuesEnteredInRange(stationManagement.activeIDs11p,stationManagement.activeIDs11p)<0 & positionManagement.distanceReal(stationManagement.indexInActiveIDs_of11pnodes,stationManagement.indexInActiveIDs_of11pnodes)<=phyParams.Raw(iRaw))*(1+timeManagement.timeNow)-1; valuesEnteredInRange( positionManagement.distanceReal > phyParams.Raw(iRaw) ) = -1; outputValues.enteredInRange11p(:,:,iRaw) = valuesEnteredInRange - (diag(diag(valuesEnteredInRange+1))); end diff --git a/MainFilesCV2X/mainCV2XttiStarts.m b/MainFilesCV2X/mainCV2XttiStarts.m index a3de990..3995f88 100644 --- a/MainFilesCV2X/mainCV2XttiStarts.m +++ b/MainFilesCV2X/mainCV2XttiStarts.m @@ -25,7 +25,6 @@ %% From v.5.4.16 stationManagement.transmittingIDsCV2X = []; -stationManagement.hasTransmissionThisSlot=zeros(length(stationManagement.activeIDsCV2X),1); iTransmitting = 1; currentT = (mod((timeManagement.elapsedTime_TTIs-1),appParams.NbeaconsT)+1); idLteHasPck = stationManagement.activeIDsCV2X(stationManagement.pckBuffer(stationManagement.activeIDsCV2X) >= 1); @@ -39,9 +38,7 @@ % printDebugTxRx(timeManagement.timeNow,idLte,'NR Tx started',stationManagement,sinrManagement,outParams); end end -% hasTransmissionThisSlot introduced from version 6.2 -stationManagement.hasTransmissionThisSlot(stationManagement.transmittingIDsCV2X)=1; -%% + timeManagement.timeGeneratedPacketInTxLTE(stationManagement.transmittingIDsCV2X) = timeManagement.timeLastPacket(stationManagement.transmittingIDsCV2X); diff --git a/MatFilesPosition/updatePositionFile.m b/MatFilesPosition/updatePositionFile.m index 464993c..6757559 100644 --- a/MatFilesPosition/updatePositionFile.m +++ b/MatFilesPosition/updatePositionFile.m @@ -7,57 +7,41 @@ fileIndex = find(dataTrace(:,1)==time); IDvehicle = dataTrace(fileIndex,2); -XvehicleReal = dataTrace(fileIndex,3); -YvehicleReal = dataTrace(fileIndex,4); -if length(dataTrace(1,:))>4 - speedNow = dataTrace(fileIndex,5); -end -% Sort IDvehicle, XvehicleReal and YvehicleReal by IDvehicle +% Sort IDvehicle [IDvehicle,indexOrder] = sort(IDvehicle); -XvehicleReal = XvehicleReal(indexOrder); -YvehicleReal = YvehicleReal(indexOrder); -if length(dataTrace(1,:))>4 - speedNow = speedNow(indexOrder); -else - speedNow = (((YvehicleReal - YvehiclePrevious).^2 + (XvehicleReal - XvehiclePrevious).^2).^0.5) / (time-tPrevious); -end -direction = complex((XvehicleReal - XvehiclePrevious),(YvehicleReal - YvehiclePrevious))'; +% IDs of vehicles that are exiting the scenario +IDvehicleExit = setdiff(oldIDvehicle,IDvehicle); +% Indices of vehicles in IDvehicle that are new [~,indexNewVehicles] = setdiff(IDvehicle,oldIDvehicle,'stable'); -% Find IDs of vehicles that are exiting the scenario -IDvehicleExit = setdiff(oldIDvehicle,IDvehicle); - -% Find indices of vehicles in IDvehicle that are both in IDvehicle and OldIDvehicle +% Indices of vehicles in IDvehicle that are both in IDvehicle and OldIDvehicle indexOldVehicles = find(ismember(IDvehicle,oldIDvehicle)); -% Find indices of vehicles in OldIDvehicle that are both in IDvehicle and OldIDvehicle +% Indices of vehicles in OldIDvehicle that are both in IDvehicle and OldIDvehicle indexOldVehiclesToOld = find(ismember(oldIDvehicle,IDvehicle)); -%figure(1) -%plot(XvehicleReal,YvehicleReal,'p'); +% Sort XvehicleReal and YvehicleReal by IDvehicle +XvehicleReal = dataTrace(fileIndex,3); +XvehicleReal = XvehicleReal(indexOrder); -if length(dataTrace(1,:))==4 - speedNow = zeros(length(IDvehicle),1); - for i=1:length(IDvehicle) - iOld = find(oldIDvehicle==IDvehicle(i)); - if ~isempty(iOld) - speedNow(i) = sqrt((XvehicleReal(i)-XvehiclePrevious(iOld)).*(XvehicleReal(i)-XvehiclePrevious(iOld)) + ... - (YvehicleReal(i)-YvehiclePrevious(iOld)).*(YvehicleReal(i)-YvehiclePrevious(iOld)))/(time-timePrevious); - %else - % speedNow(i) = 0; - end +YvehicleReal = dataTrace(fileIndex,4); +YvehicleReal = YvehicleReal(indexOrder); - % if IDvehicle(i)==1 - % figure(2) - % plot(time,speedNow(i),'pr'); - % hold on - % end - end +if size(dataTrace, 2) > 4 + speedNow = dataTrace(fileIndex,5); + speedNow = speedNow(indexOrder); +else + speedNow = zeros(size(IDvehicle)); % assume the speed of new vehicles are all 0 + speedNow(indexOldVehicles) = ((YvehicleReal(indexOldVehicles)-YvehiclePrevious(indexOldVehiclesToOld)).^2 + (XvehicleReal(indexOldVehicles)-XvehiclePrevious(indexOldVehiclesToOld)).^2).^0.5 ./ (time-tPrevious); end +direction = complex(zeros(size(IDvehicle))); % assume the direction of the new vehicles are all 0 +direction(indexOldVehicles) = complex((XvehicleReal(indexOldVehicles) - XvehiclePrevious(indexOldVehiclesToOld)), (YvehicleReal(indexOldVehicles) - YvehiclePrevious(indexOldVehiclesToOld))); + + % Print speed (if enabled) if ~isempty(outParams) && outParams.printSpeed printSpeedToFile(time,IDvehicle,speedNow,simValues.maxID,outParams); diff --git a/MatFilesResourceAllocationCV2X/BRreassignment3GPPautonomous.m b/MatFilesResourceAllocationCV2X/BRreassignment3GPPautonomous.m index 18518ee..1d89096 100644 --- a/MatFilesResourceAllocationCV2X/BRreassignment3GPPautonomous.m +++ b/MatFilesResourceAllocationCV2X/BRreassignment3GPPautonomous.m @@ -65,7 +65,7 @@ % hasNewPacketThisTbeacon checks if any new packets were generated in this slot hasNewPacketThisTbeacon = (timeManagement.timeLastPacket(activeIDsCV2X) > (timeManagement.timeNow-phyParams.TTI-1e-8)); hasFirstResourceThisTbeacon = (subframeNextResource(activeIDsCV2X,1)==currentT); -hasFirstTransmissionThisSlot= hasFirstResourceThisTbeacon & stationManagement.hasTransmissionThisSlot; +hasFirstTransmissionThisSlot = hasFirstResourceThisTbeacon & ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X); % The operand 'any' implies that if any replica is outside T1, T2, then a reallocation is performed scheduledID_PHY = activeIDsCV2X(hasNewPacketThisTbeacon & any(allConditionsMet,2)); @@ -117,7 +117,7 @@ stationManagement.nSPS(activeIDsCV2X) = stationManagement.nSPS(activeIDsCV2X)+hasFirstTransmissionThisSlot; % Evaluates the individual Pkeep according to FD-alg1 stationManagement.probResKeep(keepCheck_MAC)=1-stationManagement.FDcounter(keepCheck_MAC)./stationManagement.nSPS(keepCheck_MAC); -% stationManagement.probResKeep(keepCheck_MAC(stationManagement.probResKeep(keepCheck_MAC)>0.8))=0.8; % modification: sets pk adaptive to max 0.8 + % stationManagement.probResKeep(keepCheck_MAC(stationManagement.probResKeep(keepCheck_MAC)>0.8))=0.8; % modification: sets pk adaptive to max 0.8 keepRand = rand(1,length(keepCheck_MAC)); updateCounter_MAC =[]; updateCounter_MAC = keepCheck_MAC(keepRand < stationManagement.probResKeep(keepCheck_MAC)'); @@ -379,12 +379,12 @@ % The vehicles who selected new resources need to set the flag NEW DATA INDICATOR % Vehicles who performed the re-evaluation do not need to set it, as it is % already at 1, and it will be decremented after the first transmission -stationManagement.newDataIndicator(activeIDsCV2X(scheduledID_PHY_MAC)) = 1; +stationManagement.newDataIndicator(scheduledID_PHY_MAC) = 1; % the vehicles who DID NOT transmit in an allocated resource need to set the flag NEW DATA INDICATOR if simParams.reEvalAfterEmptyResource==true % the product between hasFirstResourceThisTbeacon and ~stationManagement.hasTransmissionThisSlot returns one only as a % consequence to an allocated resource without a packet to transmit - stationManagement.newDataIndicator(activeIDsCV2X(hasFirstResourceThisTbeacon & (~stationManagement.hasTransmissionThisSlot))) = 1; + stationManagement.newDataIndicator(activeIDsCV2X(hasFirstResourceThisTbeacon & (~ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X)))) = 1; end % FD function call diff --git a/MatFilesResourceAllocationCV2X/CV2XsensingProcedure.m b/MatFilesResourceAllocationCV2X/CV2XsensingProcedure.m index d4e3a2b..8a4c3d1 100644 --- a/MatFilesResourceAllocationCV2X/CV2XsensingProcedure.m +++ b/MatFilesResourceAllocationCV2X/CV2XsensingProcedure.m @@ -122,7 +122,7 @@ stationManagement.knownUsedMatrixCV2X(BRtx,idVrx) = 0; end -% % if HARQ is active in 5G -> reserve the next retransmission + % if HARQ is active in 5G -> reserve the next retransmission if phyParams.cv2xNumberOfReplicasMax>1 && hasFirstResourceThisTbeacon && BRnextReservedTransmission~=-1 && simParams.mode5G % BR of the next reserved resource (blind retransmission) stationManagement.knownUsedMatrixCV2X(BRnextReservedTransmission,idVrx) = 1; @@ -151,13 +151,13 @@ end end -% % If overlap of beacon resources is allowed, the SCI -% % information is used to update partially overlapping beacon -% % resources when reserving resources for retransmissions + % If overlap of beacon resources is allowed, the SCI + % information is used to update partially overlapping beacon + % resources when reserving resources for retransmissions if phyParams.BRoverlapAllowed && phyParams.cv2xNumberOfReplicasMax>1 && hasFirstResourceThisTbeacon && BRnextReservedTransmission~=-1 && simParams.mode5G -% % identify subframe of BR -% % Array of BRids in the slot of the retransmission -% % Slot at which the retransmission occurs + % identify subframe of BR + % Array of BRids in the slot of the retransmission + % Slot at which the retransmission occurs retransmitT = ceil(BRnextReservedTransmission/appParams.NbeaconsF); BRids_retransmitSF = ((retransmitT-1)*appParams.NbeaconsF+1):(retransmitT*appParams.NbeaconsF); From e7ce970759843b2a98ea689f89ceb1fdc07e2429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=8D=93=E9=9C=8F=5FFelix?= Date: Mon, 18 Dec 2023 14:58:30 +0800 Subject: [PATCH 2/3] remove duplicate lines --- MatFilesInit/initiateMainSimulationParameters.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MatFilesInit/initiateMainSimulationParameters.m b/MatFilesInit/initiateMainSimulationParameters.m index d0ccd06..2daed16 100644 --- a/MatFilesInit/initiateMainSimulationParameters.m +++ b/MatFilesInit/initiateMainSimulationParameters.m @@ -265,10 +265,6 @@ error('Error: "simParams.rho" cannot be <= 0'); end - % [randomXPosition] - % switch if vehicles are randomly or Uniformly positioned - [simParams, varargin] = addNewParam(simParams, 'randomXPosition', true, 'Randomly/uniformly position', 'bool',fileCfg,varargin{1}); - % [randomXPosition] % switch if vehicles are randomly or Uniformly positioned [simParams, varargin] = addNewParam(simParams, 'randomXPosition', true, 'Randomly/uniformly position', 'bool',fileCfg,varargin{1}); From 9543c756f5ccb3ad727f46524858d4e54d8ad066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=8D=93=E9=9C=8F=5FFelix?= Date: Thu, 21 Dec 2023 00:02:08 +0800 Subject: [PATCH 3/3] trace file work with 11p 1. in LTE, use "stationManagement.hasTransmissionThisSlot" again; 2. 11p could also work with trace file --- MainFiles/mainInit.m | 3 +- MainFiles/mainPositionUpdate.m | 27 +++--- MainFilesCV2X/mainCV2XttiStarts.m | 13 ++- .../checkVehiclesStartReceiving11p.m | 21 ++--- MainFilesIEEE802.11p/updateKPI11p.m | 93 ++++++++----------- .../initiateMainSimulationParameters.m | 2 +- .../BRreassignment3GPPautonomous.m | 4 +- MatFilesUtility/computeNeighbors.m | 86 ++++++++--------- Simulations_test_trace.m | 19 +++- 9 files changed, 126 insertions(+), 142 deletions(-) diff --git a/MainFiles/mainInit.m b/MainFiles/mainInit.m index 1c262ca..4a0faf9 100644 --- a/MainFiles/mainInit.m +++ b/MainFiles/mainInit.m @@ -96,8 +96,7 @@ % Parameter for 11p retransmission KPI calculation, the index of active11p % in the range during earlier retransmission -NactiveIDs11p = length(stationManagement.activeIDs11p); -stationManagement.indexInRaw_earler = zeros(NactiveIDs11p, NactiveIDs11p, length(phyParams.Raw)); % (to, from, idRaw) +stationManagement.indexInRaw_earler = zeros(simValues.maxID, simValues.maxID, length(phyParams.Raw)); % (to, from, idRaw) % HARQ init stationManagement.cv2xNumberOfReplicas = phyParams.cv2xNumberOfReplicasMax * ones(simValues.maxID,1); diff --git a/MainFiles/mainPositionUpdate.m b/MainFiles/mainPositionUpdate.m index 551be5c..0d30809 100644 --- a/MainFiles/mainPositionUpdate.m +++ b/MainFiles/mainPositionUpdate.m @@ -12,31 +12,25 @@ 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 + if ~isempty(stationManagement.activeIDsCV2X) % Update stationManagement.BRid vector (variable number of vehicles in the scenario) [stationManagement.BRid] = updateBRidFile(stationManagement.BRid,stationManagement.activeIDs,indexNewVehicles); end end % Vectors IDvehicleLTE and IDvehicle11p are updated -stationManagement.activeIDsCV2X = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)==100); +stationManagement.activeIDsCV2X = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)==constants.V_STATE_LTE_TXRX); stationManagement.activeIDsCV2X = stationManagement.activeIDsCV2X(stationManagement.activeIDsCV2X>0); -stationManagement.activeIDs11p = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)~=100); +stationManagement.activeIDs11p = stationManagement.activeIDs.*(stationManagement.vehicleState(stationManagement.activeIDs)~=constants.V_STATE_LTE_TXRX); stationManagement.activeIDs11p = stationManagement.activeIDs11p(stationManagement.activeIDs11p>0); [~, stationManagement.indexInActiveIDs_ofLTEnodes] = ismember(stationManagement.activeIDsCV2X, stationManagement.activeIDs); [~, stationManagement.indexInActiveIDs_of11pnodes] = ismember(stationManagement.activeIDs11p, stationManagement.activeIDs); -% % For possible DEBUG -% figure(300) -% plot(timeManagement.timeNextPosUpdate*100*ones(1,length(positionManagement.XvehicleReal)),positionManagement.XvehicleReal,'*'); -% hold on - % Update variables for resource allocation in LTE-V2V -%if simParams.technology ~= 2 % not only 11p -if sum(stationManagement.vehicleState(stationManagement.activeIDs)==100)>0 +if ~isempty(stationManagement.activeIDsCV2X) % if there were active CV2X % if simParams.BRAlgorithm==18 && timeManagement.timeNow > phyParams.Tsf (Vittorio 5.5.3) if simParams.BRAlgorithm==constants.REASSIGN_BR_STD_MODE_4 && timeManagement.timeNow > phyParams.TTI @@ -72,6 +66,11 @@ % 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); + + % update stationManagement + stationManagement.hasTransmissionThisSlot = ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X); + [~, stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE] = ismember(stationManagement.transmittingIDsCV2X, stationManagement.activeIDsCV2X); + [~, stationManagement.indexInActiveIDs_OfTxLTE] = ismember(stationManagement.transmittingIDsCV2X, stationManagement.activeIDs); end % Call function to compute the distances @@ -186,14 +185,14 @@ % Update of parameters related to transmissions in IEEE 802.11p to cope % with vehicles exiting the scenario -%if simParams.technology ~= 1 % not only LTE -if sum(stationManagement.vehicleState(stationManagement.activeIDs)~=100)>0 +if ~isempty(stationManagement.activeIDs11p) timeManagement.timeNextTxRx11p(stationManagement.activeIDsExit) = Inf; sinrManagement.idFromWhichRx11p(stationManagement.activeIDsExit) = stationManagement.activeIDsExit; sinrManagement.instantThisSINRavStarted11p(stationManagement.activeIDsExit) = Inf; stationManagement.vehicleState(stationManagement.activeIDsExit(stationManagement.vehicleState(stationManagement.activeIDsExit)~=100)) = 1; - + stationManagement.indexInRaw_earler(:,stationManagement.activeIDsExit,:) = 0; + % The average SINR of all vehicles is then updated sinrManagement = updateSINR11p(timeManagement,sinrManagement,stationManagement,phyParams); diff --git a/MainFilesCV2X/mainCV2XttiStarts.m b/MainFilesCV2X/mainCV2XttiStarts.m index 3995f88..d2d69df 100644 --- a/MainFilesCV2X/mainCV2XttiStarts.m +++ b/MainFilesCV2X/mainCV2XttiStarts.m @@ -25,6 +25,7 @@ %% From v.5.4.16 stationManagement.transmittingIDsCV2X = []; +stationManagement.hasTransmissionThisSlot=zeros(length(stationManagement.activeIDsCV2X),1); iTransmitting = 1; currentT = (mod((timeManagement.elapsedTime_TTIs-1),appParams.NbeaconsT)+1); idLteHasPck = stationManagement.activeIDsCV2X(stationManagement.pckBuffer(stationManagement.activeIDsCV2X) >= 1); @@ -38,7 +39,9 @@ % printDebugTxRx(timeManagement.timeNow,idLte,'NR Tx started',stationManagement,sinrManagement,outParams); end end - +% hasTransmissionThisSlot introduced from version 6.2 +stationManagement.hasTransmissionThisSlot(ismember(stationManagement.activeIDsCV2X,stationManagement.transmittingIDsCV2X))=1; +%% timeManagement.timeGeneratedPacketInTxLTE(stationManagement.transmittingIDsCV2X) = timeManagement.timeLastPacket(stationManagement.transmittingIDsCV2X); @@ -46,10 +49,10 @@ % Find index of vehicles that are currently transmitting stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE = zeros(length(stationManagement.transmittingIDsCV2X),1); stationManagement.indexInActiveIDs_OfTxLTE = zeros(length(stationManagement.transmittingIDsCV2X),1); - for ix = 1:length(stationManagement.transmittingIDsCV2X) - stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE(ix) = find(stationManagement.activeIDsCV2X == stationManagement.transmittingIDsCV2X(ix)); - stationManagement.indexInActiveIDs_OfTxLTE(ix) = find(stationManagement.activeIDs == stationManagement.transmittingIDsCV2X(ix)); - end + + [~, stationManagement.indexInActiveIDsOnlyLTE_OfTxLTE] = ismember(stationManagement.transmittingIDsCV2X, stationManagement.activeIDsCV2X); + [~, stationManagement.indexInActiveIDs_OfTxLTE] = ismember(stationManagement.transmittingIDsCV2X, stationManagement.activeIDs); + end % Initialization of the received power diff --git a/MainFilesIEEE802.11p/checkVehiclesStartReceiving11p.m b/MainFilesIEEE802.11p/checkVehiclesStartReceiving11p.m index 7b30e65..d9d20b9 100644 --- a/MainFilesIEEE802.11p/checkVehiclesStartReceiving11p.m +++ b/MainFilesIEEE802.11p/checkVehiclesStartReceiving11p.m @@ -26,9 +26,9 @@ (stationManagement.vehicleState(activeIDs)==constants.V_STATE_11P_BACKOFF); notEndingBackoff = timeManagement.timeNextTxRx11p(activeIDs) >= (timeManagement.timeNow+phyParams.tSlot-1e-10); -alreadyReceingAnotherPreamble = ( stationManagement.vehicleState(activeIDs)==constants.V_STATE_11P_RX & ... +alreadyReceingAnotherPreamble = stationManagement.vehicleState(activeIDs)==constants.V_STATE_11P_RX & ... ( (timeManagement.timeNow-sinrManagement.instantThisSINRstarted11p(activeIDs)) < 4e-6 ... - | sinrManagement.idFromWhichRx11p(activeIDs) == activeIDs ) ); + | sinrManagement.idFromWhichRx11p(activeIDs) == activeIDs ); if indexEventInActiveIDs>0 % Normal case - one node is transmitting @@ -39,10 +39,10 @@ % if preambel of the same packet was detected earlier, the following % preamble is automatically detected - decodingThisPreamble = stationManagement.preambleAlreadyDetected(:,indexEventInActiveIDs) | (preambelSINR > phyParams.sinrThreshold11p_preamble); + decodingThisPreamble = stationManagement.preambleAlreadyDetected(activeIDs,indexEventInActiveIDs) | (preambelSINR > phyParams.sinrThreshold11p_preamble); % update detected preamble - stationManagement.preambleAlreadyDetected(:,indexEventInActiveIDs) = decodingThisPreamble; + stationManagement.preambleAlreadyDetected(activeIDs,indexEventInActiveIDs) = decodingThisPreamble; % % Approach 2: I check that the received power is above the sensing % % threshold for decodable signals (-85 dBm in specs) @@ -51,7 +51,7 @@ % % From version 5.3.1, the channel check is added % If the channel is not the same, then C is set to 0 - decodingThisPreamble = decodingThisPreamble & sameChannel(stationManagement.activeIDs); + decodingThisPreamble = decodingThisPreamble & sameChannel(activeIDs); else % Only interference, with no real useful signal % In this case C is always 'false' @@ -110,14 +110,14 @@ % The inteference is saved in sensedPowerByLteNo11p per beacon % resource and needs to be converted into "per subchannel" if ~isempty(sinrManagement.sensedPowerByLteNo11p) - interferenceFromLTEnodesPerSubframe = (sum(sinrManagement.sensedPowerByLteNo11p)/length(sinrManagement.sensedPowerByLteNo11p(:,1)))'; + interferenceFromLTEnodesPerSubframe = (sum(sinrManagement.sensedPowerByLteNo11p)/size(sinrManagement.sensedPowerByLteNo11p,1))'; else interferenceFromLTEnodesPerSubframe = 0; %zeros(length(),1); end % sinrThr=phyParams.LOS(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs).*phyParams.sinrThreshold11p_LOS+... % (1-phyParams.LOS(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs)).*phyParams.sinrThreshold11p_NLOS; % retransmission may should be considered here - decodingThePreamble = (sinrManagement.P_RX_MHz(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs) ./ (phyParams.Pnoise_MHz + (rxPowerTotNow_MHz(stationManagement.activeIDsCV2X)-sinrManagement.P_RX_MHz(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs)) + interferenceFromLTEnodesPerSubframe) > phyParams.sinrThreshold11p_preamble); + decodingThePreamble = (sinrManagement.P_RX_MHz(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs) ./ (phyParams.Pnoise_MHz + (rxPowerTotNow_MHz(stationManagement.indexInActiveIDs_ofLTEnodes)-sinrManagement.P_RX_MHz(stationManagement.indexInActiveIDs_ofLTEnodes,indexEventInActiveIDs)) + interferenceFromLTEnodesPerSubframe) > phyParams.sinrThreshold11p_preamble); ifStartDetecting11p = (stationManagement.vehicleState(stationManagement.activeIDsCV2X)==constants.V_STATE_LTE_TXRX)... & ~sinrManagement.coex_detecting11p(stationManagement.activeIDsCV2X)... & decodingThePreamble; @@ -145,15 +145,14 @@ % only count the first receiving repetition % nodesMightStartTiming = (stationManagement.vehicleState(activeIDs)==3) | ... % (decodingThisPreamble & higherThanThreshold); - nodesMightStartTiming = (activeIDs==indexEventInActiveIDs) | ... - (decodingThisPreamble & higherThanThreshold); + nodesMightStartTiming = (activeIDs==idEvent) | (decodingThisPreamble & higherThanThreshold); % Then the nodes starting the channel busy are calculated ifStartCBR = (timeManagement.cbr11p_timeStartBusy(activeIDs)==-1 & nodesMightStartTiming); % only count the first time that it detect the preamble and sensing the high power at the % same time - ifFirstTimeStartCBR = (ifStartCBR - stationManagement.alreadyStartCBR(:,indexEventInActiveIDs)) > 0; - stationManagement.alreadyStartCBR(:,indexEventInActiveIDs) = stationManagement.alreadyStartCBR(:,indexEventInActiveIDs) | ifStartCBR; + ifFirstTimeStartCBR = (ifStartCBR - stationManagement.alreadyStartCBR(activeIDs,indexEventInActiveIDs)) > 0; + stationManagement.alreadyStartCBR(activeIDs,indexEventInActiveIDs) = stationManagement.alreadyStartCBR(activeIDs,indexEventInActiveIDs) | ifStartCBR; % Time is updated timeManagement.cbr11p_timeStartBusy(activeIDs(ifFirstTimeStartCBR)) = timeManagement.timeNow; diff --git a/MainFilesIEEE802.11p/updateKPI11p.m b/MainFilesIEEE802.11p/updateKPI11p.m index 91ea574..12ac16c 100644 --- a/MainFilesIEEE802.11p/updateKPI11p.m +++ b/MainFilesIEEE802.11p/updateKPI11p.m @@ -8,48 +8,37 @@ % Values are counted within a circle of radius raw % filename = sprintf('%s/_DebugKPI_%d.xls',outParams.outputFolder,outParams.simID); -%% printDebugKPI -% if ~isfile(filename) -% fid = fopen(filename,'w'); -% fprintf(fid,'Time\tEvent\tdistance\tVehicle\treplication_times\tKPI_earlier\tKPI_now\n'); -% -% else -% fid = fopen(filename,'a'); -% end -%% printDebugKPI +indexEventInActiveIDs11p = find(stationManagement.activeIDs11p == idEvent); +activeIDs11p = stationManagement.activeIDs11p; +indexInActiveIDs_of11pnodes = stationManagement.indexInActiveIDs_of11pnodes; -indexEvent11p = find(stationManagement.activeIDs11p == idEvent); - -IDvehicle11p = stationManagement.activeIDs11p; -indexVehicle11p = stationManagement.indexInActiveIDs_of11pnodes; -neighborsID11p = stationManagement.neighborsID11p(indexEvent11p,:)'; -distance11p = positionManagement.distanceReal(stationManagement.vehicleState(stationManagement.activeIDs)~=100,stationManagement.vehicleState(stationManagement.activeIDs)~=100); % Note: I need to work with line vectors, otherwise it works differently when % sinrVector11p is a vector and when sinrVector11p is a scalar - -sinrThr = phyParams.LOS(indexVehicle11p,indexEvent)'.*phyParams.sinrVector11p_LOS(randi(length(phyParams.sinrVector11p_LOS),1,length(indexVehicle11p)))+... -(1-phyParams.LOS(indexVehicle11p,indexEvent)').*(phyParams.sinrVector11p_NLOS(randi(length(phyParams.sinrVector11p_NLOS),1,length(indexVehicle11p)))); +sinrThr = phyParams.LOS(indexInActiveIDs_of11pnodes,indexEvent)'.*phyParams.sinrVector11p_LOS(randi(length(phyParams.sinrVector11p_LOS),1,length(indexInActiveIDs_of11pnodes)))+... +(1-phyParams.LOS(indexInActiveIDs_of11pnodes,indexEvent)').*(phyParams.sinrVector11p_NLOS(randi(length(phyParams.sinrVector11p_NLOS),1,length(indexInActiveIDs_of11pnodes)))); % Update of cumulativeSINR, to account for possible Maximal Ratio Combining +sinrManagement.cumulativeSINR(activeIDs11p, idEvent) =... + stationManagement.preambleAlreadyDetected(activeIDs11p, idEvent).*(sinrManagement.cumulativeSINR(activeIDs11p, idEvent)+sinrManagement.sinrAverage11p(activeIDs11p)); -sinrManagement.cumulativeSINR(IDvehicle11p, idEvent) =... - stationManagement.preambleAlreadyDetected(IDvehicle11p, idEvent).*(sinrManagement.cumulativeSINR(IDvehicle11p, idEvent)+sinrManagement.sinrAverage11p(IDvehicle11p)); % preamble not detected condition -totalSINR = sinrManagement.cumulativeSINR(IDvehicle11p, idEvent) +... - (1-stationManagement.preambleAlreadyDetected(IDvehicle11p, idEvent)).*sinrManagement.sinrAverage11p(IDvehicle11p); +totalSINR = sinrManagement.cumulativeSINR(activeIDs11p, idEvent) +... + (1-stationManagement.preambleAlreadyDetected(activeIDs11p, idEvent)).*sinrManagement.sinrAverage11p(activeIDs11p); % Rx OK for all of the vehicles % earlier - from this packet was first transmitted to the last time % thisTime - during this packet is transmitted this time % now - including all of the history of this packet -rxOK_earlier = stationManagement.pckReceived(indexVehicle11p, idEvent); -rxOK_thisTime = (stationManagement.vehicleState(IDvehicle11p)==constants.V_STATE_11P_RX) .* (sinrManagement.idFromWhichRx11p(IDvehicle11p)==idEvent)... - .* (totalSINR >= sinrThr'); +rxOK_earlier = stationManagement.pckReceived(activeIDs11p, idEvent); +rxOK_thisTime = ... + (stationManagement.vehicleState(activeIDs11p)==constants.V_STATE_11P_RX) & ... + (sinrManagement.idFromWhichRx11p(activeIDs11p)==idEvent) & ... + (totalSINR >= sinrThr'); rxOK_now = rxOK_earlier | rxOK_thisTime; if stationManagement.pckTxOccurring(idEvent) == 1 - notRxOK_earlier = zeros(size(indexVehicle11p)); + notRxOK_earlier = zeros(size(indexInActiveIDs_of11pnodes)); else notRxOK_earlier = ~rxOK_earlier; end @@ -62,7 +51,7 @@ iChannel = stationManagement.vehicleChannel(idEvent); for iPhyRaw = 1:length(phyParams.Raw) - awarenessID11p = stationManagement.awarenessID11p(indexEvent11p,:,iPhyRaw)'; + awarenessID11p = stationManagement.awarenessID11p(indexEventInActiveIDs11p,:,iPhyRaw)'; % Vehicles' ID inside Raw IDIn_thisTime = awarenessID11p(awarenessID11p~=0) .* sameChannel(awarenessID11p(awarenessID11p~=0)); @@ -71,12 +60,12 @@ % earlier - from this packet was first transmitted to the last time % thisTime - during this packet is transmitted this time % now - including all of the history of this packet - indexInRaw_earlier = stationManagement.indexInRaw_earler(:, idEvent, iPhyRaw); - indexInRaw_thisTime = ismember(IDvehicle11p,IDIn_thisTime); + indexInRaw_earlier = stationManagement.indexInRaw_earler(activeIDs11p, idEvent, iPhyRaw); + indexInRaw_thisTime = ismember(activeIDs11p,IDIn_thisTime); indexInRaw_now = indexInRaw_thisTime | indexInRaw_earlier; % Rx OK of "earlier", "this time" and "till now" - rxOKRaw_earlier = indexInRaw_earlier & stationManagement.pckReceived(indexVehicle11p, idEvent); + rxOKRaw_earlier = indexInRaw_earlier & stationManagement.pckReceived(activeIDs11p, idEvent); rxOKRaw_thisTime = indexInRaw_thisTime & rxOK_thisTime; rxOKRaw_now = rxOKRaw_thisTime | rxOKRaw_earlier; % Rx OK of "just this time" @@ -91,7 +80,6 @@ NcorrectlyTxBeacons_earlier = nnz(rxOKRaw_earlier); NcorrectlyTxBeacons_now = nnz(rxOKRaw_now); NcorrectlyTxBeacons_jusTthisTime = nnz(rxOKRaw_justThisTime); - % printDebugKPI(fid,timeManagement.timeNow,'NcorrTxBeacon',phyParams.Raw(iPhyRaw),idEvent,stationManagement.pckTxOccurring(idEvent), NcorrectlyTxBeacons_earlier,NcorrectlyTxBeacons_now); outputValues.NcorrectlyTxBeacons11p(iChannel,pckType,iPhyRaw) =... outputValues.NcorrectlyTxBeacons11p(iChannel,pckType,iPhyRaw) -... @@ -105,7 +93,6 @@ % Number of errors Nerrors_earlier = NneighborsRaw_earlier - NcorrectlyTxBeacons_earlier; Nerrors_now = NneighborsRaw_now - NcorrectlyTxBeacons_now; - % printDebugKPI(fid,timeManagement.timeNow,'Nerrs_Raw',phyParams.Raw(iPhyRaw),idEvent,stationManagement.pckTxOccurring(idEvent), Nerrors_earlier,Nerrors_now); outputValues.Nerrors11p(iChannel,pckType,iPhyRaw) =... outputValues.Nerrors11p(iChannel,pckType,iPhyRaw) -... @@ -118,12 +105,10 @@ outputValues.NtxBeacons11p(iChannel,pckType,iPhyRaw) =... outputValues.NtxBeacons11p(iChannel,pckType,iPhyRaw) -... NneighborsRaw_earlier + NneighborsRaw_now; - % printDebugKPI(fid,timeManagement.timeNow,'NtxBeacons11p',phyParams.Raw(iPhyRaw),idEvent,stationManagement.pckTxOccurring(idEvent), -1,outputValues.NtxBeacons11p(iChannel,pckType,iPhyRaw)); outputValues.NtxBeaconsTOT(iChannel,pckType,iPhyRaw) =... outputValues.NtxBeaconsTOT(iChannel,pckType,iPhyRaw) -... NneighborsRaw_earlier + NneighborsRaw_now; - % printDebugKPI(fid,timeManagement.timeNow,'NtxBeaconsTOT',phyParams.Raw(iPhyRaw),idEvent,stationManagement.pckTxOccurring(idEvent), -1,outputValues.NtxBeaconsTOT(iChannel,pckType,iPhyRaw)); % Compute update delay (if enabled) if outParams.printUpdateDelay @@ -131,13 +116,13 @@ delayMax = length(outputValues.updateDelayCounter11p(1,1,:,1))*outParams.delayResolution; % ID of vehicles that are outside the awareness range of vehicle i - all = (1:length(simValues.updateTimeMatrix11p(:,1,iPhyRaw)))'; + all = (1:simValues.maxID)'; IDOut = setdiff(all,IDIn_thisTime); simValues.updateTimeMatrix11p(idEvent,IDOut,iPhyRaw)=-1; for iRaw = 1:length(IDIn_thisTime) % If the beacon is currently correctly received by the neighbor % inside the awareness range - if find(IDvehicle11p(rxOKRaw_justThisTime)==IDIn_thisTime(iRaw)) + if find(activeIDs11p(rxOKRaw_justThisTime)==IDIn_thisTime(iRaw)) % Store previous timestamp previousTimeStamp = simValues.updateTimeMatrix11p(idEvent,IDIn_thisTime(iRaw),iPhyRaw); % If there was a previous timestamp @@ -156,7 +141,7 @@ end end % Update updateTimeMatrix with timeNow - simValues.updateTimeMatrix11p(idEvent,IDvehicle11p(rxOKRaw_justThisTime),iPhyRaw) = timeManagement.timeNow; + simValues.updateTimeMatrix11p(idEvent,activeIDs11p(rxOKRaw_justThisTime),iPhyRaw) = timeManagement.timeNow; end % Compute data age (if enabled) @@ -171,7 +156,7 @@ for iRaw = 1:length(IDIn_thisTime) % If the beacon is currently correctly received by the neighbor % inside the awareness range - if find(IDvehicle11p(rxOKRaw_justThisTime)==IDIn_thisTime(iRaw)) + if find(activeIDs11p(rxOKRaw_justThisTime)==IDIn_thisTime(iRaw)) % Store previous timestamp previousTimeStamp = simValues.dataAgeTimestampMatrix11p(idEvent,IDIn_thisTime(iRaw),iPhyRaw); % If there was a previous timestamp @@ -190,7 +175,7 @@ end end % Update updateTimeMatrix with timeNow - simValues.dataAgeTimestampMatrix11p(idEvent,IDvehicle11p(rxOKRaw_justThisTime),iPhyRaw) = timeManagement.timeLastPacket(idEvent); + simValues.dataAgeTimestampMatrix11p(idEvent,activeIDs11p(rxOKRaw_justThisTime),iPhyRaw) = timeManagement.timeLastPacket(idEvent); end % Compute packet delay (if enabled) @@ -224,11 +209,11 @@ % update index of activeIDs11p in the range of Raw earlier (during one packet % and it's retransmission) - stationManagement.indexInRaw_earler(:, idEvent, iPhyRaw) = indexInRaw_now; + stationManagement.indexInRaw_earler(activeIDs11p, idEvent, iPhyRaw) = indexInRaw_now; end % update packet Rx OK -stationManagement.pckReceived(indexVehicle11p, idEvent) =... - stationManagement.pckReceived(indexVehicle11p, idEvent) | rxOK_thisTime; +stationManagement.pckReceived(activeIDs11p, idEvent) =... + stationManagement.pckReceived(activeIDs11p, idEvent) | rxOK_thisTime; % Compute power control allocation (if enabled) if outParams.printPowerControl @@ -252,40 +237,36 @@ % Count correct receptions and errors up to the maximum awareness range (if enabled) if outParams.printPacketReceptionRatio if ~simParams.neighborsSelection - AllNeighbors = (IDvehicle11p~=idEvent); + AllNeighbors = (activeIDs11p~=idEvent); else - AllNeighbors = ismember(IDvehicle11p,neighborsID11p); + neighborsID11p = stationManagement.neighborsID11p(indexEventInActiveIDs11p,:)'; + AllNeighbors = ismember(activeIDs11p,neighborsID11p); end -% AllNeighbors(awarenessID11p~=0) = awarenessID11p(awarenessID11p~=0) .* sameChannel(awarenessID11p(awarenessID11p~=0)); + distanceIdEventTo11p = positionManagement.distanceReal(stationManagement.indexInActiveIDs_of11pnodes, indexEvent); + for iRaw = 1:1:floor(phyParams.RawMax11p/outParams.prrResolution) distance = iRaw * outParams.prrResolution; % Correctly decoded beacons - RxOKiRaw = AllNeighbors .* (distance11p(:,indexEvent11p) (timeManagement.timeNow-phyParams.TTI-1e-8)); hasFirstResourceThisTbeacon = (subframeNextResource(activeIDsCV2X,1)==currentT); -hasFirstTransmissionThisSlot = hasFirstResourceThisTbeacon & ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X); +hasFirstTransmissionThisSlot= hasFirstResourceThisTbeacon & stationManagement.hasTransmissionThisSlot; % The operand 'any' implies that if any replica is outside T1, T2, then a reallocation is performed scheduledID_PHY = activeIDsCV2X(hasNewPacketThisTbeacon & any(allConditionsMet,2)); @@ -384,7 +384,7 @@ if simParams.reEvalAfterEmptyResource==true % the product between hasFirstResourceThisTbeacon and ~stationManagement.hasTransmissionThisSlot returns one only as a % consequence to an allocated resource without a packet to transmit - stationManagement.newDataIndicator(activeIDsCV2X(hasFirstResourceThisTbeacon & (~ismember(stationManagement.activeIDsCV2X, stationManagement.transmittingIDsCV2X)))) = 1; + stationManagement.newDataIndicator(activeIDsCV2X(hasFirstResourceThisTbeacon & (~stationManagement.hasTransmissionThisSlot))) = 1; end % FD function call diff --git a/MatFilesUtility/computeNeighbors.m b/MatFilesUtility/computeNeighbors.m index 393bf3f..d433f6b 100644 --- a/MatFilesUtility/computeNeighbors.m +++ b/MatFilesUtility/computeNeighbors.m @@ -8,45 +8,51 @@ % Selection of nodes with received power below a minimum %nonNegligibleReceivedPower = sinrManagement.P_RX_MHz > phyParams.Pnoise_MHz/10; -%% -% LTE -%distanceReal_LTE = positionManagement.distanceReal(:,(stationManagement.vehicleState(stationManagement.activeIDs)==100)); -if sum(stationManagement.vehicleState(stationManagement.activeIDs)==constants.V_STATE_LTE_TXRX)>0 -%if simParams.technology~=2 % Not only 11p - distanceReal_LTE = positionManagement.distanceReal; - % Vehicles from which the received power is below a minimum are set to an infinite distance - %distanceReal_LTE(stationManagement.activeIDs,stationManagement.activeIDs) = distanceReal_LTE(stationManagement.activeIDs,stationManagement.activeIDs)./nonNegligibleReceivedPower; - % Vehciles that are not LTE are set to an infinite distance - distanceReal_LTE(:,(stationManagement.vehicleState(stationManagement.activeIDs)~=100))=Inf; +%% preprocessing distance +if ~isempty(stationManagement.activeIDs) + distanceReal = positionManagement.distanceReal; + + % vehicles with different technologies have infinite distance between each + % other + distanceReal(stationManagement.indexInActiveIDs_ofLTEnodes, stationManagement.indexInActiveIDs_of11pnodes)=Inf; + distanceReal(stationManagement.indexInActiveIDs_of11pnodes, stationManagement.indexInActiveIDs_ofLTEnodes)=Inf; + % The diagonal must be set to 0 - distanceReal_LTE(1:1+length(distanceReal_LTE(1,:)):end) = 0; - % sort - [neighborsDistanceLTE, neighborsIndexLTE] = sort(distanceReal_LTE,2); + distanceReal(1:1+size(distanceReal, 2):end) = 0; + + % sort + [neighborsDistance, neighborsIndex] = sort(distanceReal,2); + % remove the first element per each raw, which is self - neighborsDistanceLTE(:,1) = []; - neighborsIndexLTE(:,1) = []; - neighborsDistanceLTE_ofLTE = neighborsDistanceLTE(stationManagement.vehicleState(stationManagement.activeIDs)==100,:); - neighborsIndexLTE_ofLTE = neighborsIndexLTE(stationManagement.vehicleState(stationManagement.activeIDs)==100,:); + neighborsDistance(:,1) = []; + neighborsIndex(:,1) = []; +end + + +%% If there were active CV2X vehicles +if ~isempty(stationManagement.activeIDsCV2X) + neighborsDistanceLTE2ALL = neighborsDistance(stationManagement.indexInActiveIDs_ofLTEnodes,:); + neighborsIndexLTE2ALL = neighborsIndex(stationManagement.indexInActiveIDs_ofLTEnodes,:); % Vehicles in order of distance %allNeighborsID = IDvehicle(neighborsIndexLTE); - stationManagement.allNeighborsID = stationManagement.activeIDs(neighborsIndexLTE); + stationManagement.allNeighborsID = stationManagement.activeIDs(neighborsIndex); - % Vehicles in the maximum awareness range - stationManagement.neighborsIDLTE = (neighborsDistanceLTE_ofLTE < phyParams.RawMaxCV2X) .*stationManagement.activeIDs(neighborsIndexLTE_ofLTE); + % Vehicles within the maximum awareness range + stationManagement.neighborsIDLTE = (neighborsDistanceLTE2ALL < phyParams.RawMaxCV2X) .* stationManagement.activeIDs(neighborsIndexLTE2ALL); % Vehicles in awareness range if ~isempty(stationManagement.neighborsIDLTE) - stationManagement.awarenessIDLTE = zeros(length(neighborsDistanceLTE_ofLTE(:,1)),length(neighborsDistanceLTE_ofLTE(1,:)),length(phyParams.Raw)); + stationManagement.awarenessIDLTE = zeros([size(neighborsDistanceLTE2ALL), length(phyParams.Raw)]); for iPhyRaw=1:length(phyParams.Raw) - stationManagement.awarenessIDLTE(:,:,iPhyRaw) = (neighborsDistanceLTE_ofLTE < phyParams.Raw(iPhyRaw)) .* stationManagement.neighborsIDLTE; + stationManagement.awarenessIDLTE(:,:,iPhyRaw) = (neighborsDistanceLTE2ALL < phyParams.Raw(iPhyRaw)) .* stationManagement.neighborsIDLTE; end end - % Removal of nodes that are not active - stationManagement.neighborsIDLTE = stationManagement.neighborsIDLTE(:,1:length(stationManagement.activeIDsCV2X)-1); + % Remove nodes that are not active CV2X + stationManagement.neighborsIDLTE(:, length(stationManagement.activeIDsCV2X):end) = []; if ~isempty(stationManagement.neighborsIDLTE) - stationManagement.awarenessIDLTE = stationManagement.awarenessIDLTE(:,1:length(stationManagement.activeIDsCV2X)-1,:); + stationManagement.awarenessIDLTE(:,length(stationManagement.activeIDsCV2X):end,:) = []; else stationManagement.awarenessIDLTE = []; end @@ -59,33 +65,21 @@ % %stationManagement.LTEinterfereingTo11p_ID = (neighborsDistanceLTE_of11p < phyParams.RawMaxCV2X) .*stationManagement.activeIDs(neighborsIndexLTE_of11p); %end end -%% -%% -% 11p -if sum(stationManagement.vehicleState(stationManagement.activeIDs)~=constants.V_STATE_LTE_TXRX)>0 -%if simParams.technology~=1 % Not only LTE - distanceReal_11p = positionManagement.distanceReal; - % Vehciles that are not LTE are set to an infinite distance - distanceReal_11p(:,(stationManagement.vehicleState(stationManagement.activeIDs)==100))=Inf; - % The diagonal must be set to 0 - distanceReal_11p(1:1+length(distanceReal_11p(1,:)):end) = 0; - % sort - [neighborsDistance11p, neighborsIndex11p] = sort(distanceReal_11p,2); - % remove the first element per each raw, which is self - neighborsDistance11p(:,1) = []; - neighborsIndex11p(:,1) = []; - neighborsDistance11p_of11p = neighborsDistance11p(stationManagement.vehicleState(stationManagement.activeIDs)~=100,:); - neighborsIndex11p_of11p = neighborsIndex11p(stationManagement.vehicleState(stationManagement.activeIDs)~=100,:); + +%% If there were active 11p vehicles +if ~isempty(stationManagement.activeIDs11p) + neighborsDistance11p2ALL = neighborsDistance(stationManagement.indexInActiveIDs_of11pnodes,:); + neighborsIndex11p2ALL = neighborsIndex(stationManagement.indexInActiveIDs_of11pnodes,:); % Vehicles in the maximum awareness range - stationManagement.neighborsID11p = (neighborsDistance11p_of11p < phyParams.RawMax11p) .*stationManagement.activeIDs(neighborsIndex11p_of11p); + stationManagement.neighborsID11p = (neighborsDistance11p2ALL < phyParams.RawMax11p) .* stationManagement.activeIDs(neighborsIndex11p2ALL); % Vehicles in awareness range if ~isempty(stationManagement.neighborsID11p) - stationManagement.awarenessID11p = zeros(length(neighborsDistance11p_of11p(:,1)),length(neighborsDistance11p_of11p(1,:)),length(phyParams.Raw)); + stationManagement.awarenessID11p = zeros([size(neighborsDistance11p2ALL), length(phyParams.Raw)]); for iPhyRaw=1:length(phyParams.Raw) - stationManagement.awarenessID11p(:,:,iPhyRaw) = (neighborsDistance11p_of11p < phyParams.Raw(iPhyRaw)) .* stationManagement.neighborsID11p; + stationManagement.awarenessID11p(:,:,iPhyRaw) = (neighborsDistance11p2ALL < phyParams.Raw(iPhyRaw)) .* stationManagement.neighborsID11p; end end @@ -100,6 +94,6 @@ % %stationManagement.LTEinterfereingTo11p_ID = (neighborsDistance11p_ofLTE < phyParams.RawMaxCV2X) .*stationManagement.activeIDs(neighborsIndex11p_ofLTE); %end end -%% + end \ No newline at end of file diff --git a/Simulations_test_trace.m b/Simulations_test_trace.m index aef53a1..caeba3d 100644 --- a/Simulations_test_trace.m +++ b/Simulations_test_trace.m @@ -36,13 +36,22 @@ outputFolder = fullfile(path_task, 'Output', 'test_trace'); % Launches simulation +% WiLabV2Xsim(configFile,... +% 'outputFolder',outputFolder, "filenameTrace", dirTraceFile,... +% 'Technology','5G-V2X', 'MCS_NR',MCS, 'SCS_NR',SCS, 'beaconSizeBytes',packetSize,... +% 'simulationTime',simTime, 'probResKeep',pKeep, 'BwMHz',BandMHz,... +% 'cv2xNumberOfReplicasMax',nTransm,... +% 'allocationPeriod',periodicity, 'sizeSubchannel',sizeSubchannel,... +% 'powerThresholdAutonomous',sensingThreshold, 'Raw',Raw,'FixedPdensity',false,... +% 'dcc_active',false,'cbrActive',true) + +% Launches simulation of IEEE 802.11p WiLabV2Xsim(configFile,... 'outputFolder',outputFolder, "filenameTrace", dirTraceFile,... - 'Technology','5G-V2X', 'MCS_NR',MCS, 'SCS_NR',SCS, 'beaconSizeBytes',packetSize,... - 'simulationTime',simTime, 'probResKeep',pKeep, 'BwMHz',BandMHz,... - 'cv2xNumberOfReplicasMax',nTransm,... - 'allocationPeriod',periodicity, 'sizeSubchannel',sizeSubchannel,... - 'powerThresholdAutonomous',sensingThreshold, 'Raw',Raw,'FixedPdensity',false,... + 'Technology','80211p', 'MCS_11p',7, 'beaconSizeBytes',packetSize,... + 'simulationTime',simTime, 'BwMHz',BandMHz,... + 'allocationPeriod',periodicity, ... + 'Raw',Raw,... 'dcc_active',false,'cbrActive',true)