V2Xgithub / WiLabV2Xsim

V2X simulator
GNU General Public License v3.0
79 stars 32 forks source link

a question about how to use simulator #7

Closed badvibes4ever0105 closed 1 year ago

badvibes4ever0105 commented 2 years ago

I want to get the same picture as figure 7 in Performance Analysis of Sidelink 5G-V2X Mode 2 Through an Open-Source Simulator.For example,I want to get the outcome when scs equals to 30 through Simulations.m,it will occur an error in matlab when I change scs 15 to 30.I have tried hard to figure it out what happens to the matlab code for several days but I still fail it.Do I also need to change values of parameters besides scs to make Simulations.m work without any error?I would appreciate a lot if you would give me the reply as soon as possible.

joshsmith1999 commented 2 years ago

''' close all % Close all open figures clear % Reset variables clc % Clear the command window

%% Simulation for different SCS simTime = 10; % simulation time

packetSize=350; % 350B packet size nTransm=1; % Number of transmission for each packet sizeSubchannel=10; % Number of Resource Blocks for each subchannel Raw = 150; % Range of Awarness for evaluation of metrics rho = 100; % density of vehicles speed=70; % Average speed speedStDev=7; % Standard deviation speed pKeep=0.4; % keep probability periodicity=0.1; % periodic generation every 100ms sensingThreshold=-126; % threshold to detect resources as busy BandMHz=10;

% Configuration file configFile = 'Highway3GPP.cfg';

% OutputFolder outputFolder = sprintf('Output/NRV2X_SCS');

% SCS_NR=15kHz 30kHz 60kHz for SCS = [15 30 60] WiLabV2Xsim(configFile, 'outputFolder',outputFolder,'Technology','5G-V2X','MCS_NR',21,'SCS_NR',SCS,'beaconSizeBytes',packetSize,... 'simulationTime',simTime,'rho',rho,'probResKeep',pKeep,'BwMHz',BandMHz,'vMean',speed,'vStDev',speedStDev,... 'cv2xNumberOfReplicasMax',nTransm,'allocationPeriod',periodicity,'sizeSubchannel',sizeSubchannel,... 'powerThresholdAutonomous',sensingThreshold,'Raw',Raw,'FixedPdensity',false,'dcc_active',false,'cbrActive',true) end ''' Perhaps you can try it.

badvibes4ever0105 commented 2 years ago

Thanks a lot.I use the data in packet_reception_ratio_i_5G.xls(i=1~3) and plot the result shown as below through excel after running the matlab code above.I think it is a quite different from figure 7 and I want to know the reason causing this problem.By the way,I also want to get the matlab code of figure 9 and figure 11 in Performance Analysis of Sidelink 5G-V2X Mode 2 Through an Open-Source Simulator.I would appreciate a lot if you would give me the reply as soon as possible. figure7

VittorioTodisco commented 2 years ago

Thank you, @joshsmith1999, for providing the simulation settings, which are close to the one used in the article.

Two little notes:

  1. As you increase the SCS, you might want to reduce the number of DMRS symbols you use. You can do that in the simulator by setting nDMRS_NR, which regulates each resource block's total DMRS resource elements. This marginal affects the coding rate, but it can affect whether you can or not transmit a given packet size with a specific MCS. As the SCS increase, the time slot duration decrease, so fewer DMRS are needed. Generally, we set the following: 15kHz -> nDMRS=24 30kHz -> nDMRS=18 60kHz -> nDMRS=12

  2. In the settings, we specify the power density, which is 13dBm/MHz. But in the simulation you run, you set 'FixedPdensity'=false; it should be true instead if you want to obtain the same results.

With 'FixedPdensity'=false, each transmission will always use 23dBm independently of the bandwidth that a message requires.

With 'FixedPdensity'=true, the power density is constant. This means that with the above settings of MCS and packet size:

SCS=60kHz each transmission uses the whole 10MHz, so each transmission has EIRP = 23dBm SCS=30kHz each transmission uses two subchannels of 2MHz, so each transmission has EIRP = 19dBm SCS=15kHz each transmission uses one subchannel of 2MHz, so each transmission has EIRP = 16dBm

Therefore, with a constant power density, lower SCS transmit with slightly less power. Instead, with fixed power, all SCSs use the same transmission power, but as the SCS increase, the noise floor increases as transmissions require more bandwidth.

Despite these differences, you can see that even with your setting, you can see a gain at short distances for SCS=60kHz. The use of a higher numerology removes the orthogonality in the frequency domain and eliminates the impact of the IBE. Then, with your settings, the gain is lost at long distances as transmissions with SCS=60kHz have higher noise and fewer overall resources for transmissions. In 100ms, you have 500 resources for SCS=15kHz: 5 in the frequency domain and 100 in the time domain. Total 500. For SCS=60kHz, you have one resource in the frequency domain and 400 in the time domain. Total 400.

I hope my answer clears your doubts. Here is a rapid simulation replicating the paper results by changing the parameter mentioned.

git_SCS

badvibes4ever0105 commented 2 years ago

Thanks for the answer.However,I still have some problems about it.I have set the nDMRS and 'FixedPdensity'=true and I am not sure about my code becasue I am just a beginner in matlab and sorry for the inconvenience. code:

close all % Close all open figures clear % Reset variables clc % Clear the command window

%% Simulation for different SCS simTime = 10; % simulation time

packetSize=350; % 350B packet size nTransm=1; % Number of transmission for each packet sizeSubchannel=10; % Number of Resource Blocks for each subchannel Raw = 150; % Range of Awarness for evaluation of metrics rho = 100; % density of vehicles speed=70; % Average speed speedStDev=7; % Standard deviation speed pKeep=0.4; % keep probability periodicity=0.1; % periodic generation every 100ms sensingThreshold=-126; % threshold to detect resources as busy BandMHz=10;

% Configuration file configFile = 'Highway3GPP.cfg';

% OutputFolder outputFolder = sprintf('Output/NRV2X_SCS');

% SCS_NR=15kHz 30kHz 60kHz for SCS = [15 30 60] if SCS==15 nDMRS=24; elseif SCS==30 nDMRS=18; elseif SCS==60 nDMRS=12; end

WiLabV2Xsim(configFile, 'outputFolder',outputFolder,'Technology','5G-V2X','MCS_NR',21,'SCS_NR',SCS,'beaconSizeBytes',packetSize,... 'simulationTime',simTime,'rho',rho,'probResKeep',pKeep,'BwMHz',BandMHz,'vMean',speed,'vStDev',speedStDev,... 'cv2xNumberOfReplicasMax',nTransm,'allocationPeriod',periodicity,'sizeSubchannel',sizeSubchannel,... 'powerThresholdAutonomous',sensingThreshold,'Raw',Raw,'FixedPdensity',true,'dcc_active',false,'cbrActive',true,'nDMRS_NR',nDMRS) end

%% PLOT of results

figure hold on grid on

for iCycle=1:3 SCS=15*(2^(iCycle-1))

% Loads packet reception ratio output file xMode2_periodic=load(outputFolder + "/packet_receptionratio"+num2str(iCycle)+"_5G.xls");

% PRR plot % it takes the first column and the last column plot(xMode2_periodic(:,1),xMode2_periodic(:,end),'linewidth',2.5,'displayName',"SCS=" + num2str(SCS)+"kHz")

end

xlim([0 160]) legend() title("B=10MHz,350B,MCS=21,100 vehicles/km,FixedPdensity=true") legend('Location','southwest') xlabel("Distance [m]") ylabel("PRR")

result: oneone

joshsmith1999 commented 2 years ago

Thanks you very much, @VittorioTodisco . I realized my mistakes in the simulation. The lack of my knowledge of V2X communication leads to my mistakes in the simulation. After correct settings,I get this result: Figure7 And I don't know whether the setting for removing IBE is correct: I uncomment the following four lines: https://github.com/V2Xgithub/WiLabV2Xsim/blob/d82dc1bb6c6845db74741f99f64508f87897ec80/MatFilesUtilityLTE/IBEcalculation.m#L7 Line8-Line11

Thank you very much for providing such a great simulator and I am now using it to carry out my research.

badvibes4ever0105 commented 2 years ago

@joshsmith1999 Excuse me.I run this code and occur an error in the command window and how do I fix it. error

joshsmith1999 commented 2 years ago

@joshsmith1999 Excuse me.I run this code and occur an error in the command window and how do I fix it. error

In 'IBEcalculation.m', did you just uncomment these four lines: % IBEmatrix = eye(appParams.NbeaconsF,appParams.NbeaconsF); % IBEmatrixData = eye(appParams.NbeaconsF,appParams.NbeaconsF); % IBEmatrixControl = IBEmatrixData; % return Have you changed anything else?

badvibes4ever0105 commented 2 years ago

It always occurs an error whether I uncomment those four lines or not.

joshsmith1999 commented 2 years ago

it always occurs an error whether I uncommemt those four lines or not. 'IBEcalculation.m' is only a function, you should run the script such as 'Simulation.m' .

joshsmith1999 commented 2 years ago

It always occurs an error whether I uncomment those four lines or not.

You should carefully read the following documents before formal simulation: WiLabV2Xsim Table of input parameters v6.1.pdf WiLabV2Xsim v6.1 Tutorial_v0.pdf Maybe it will help you!

wzf-cn commented 2 years ago

Hi @joshsmith1999 ,

To remove the IBE, what you did is right: uncomment the lines 8-11 in "IBEcalculation.m".

But make sure you remember this modification and revise them when you want to keep the IBE. This is a mistake I made earlier.

joshsmith1999 commented 2 years ago

Hi @joshsmith1999 ,

To remove the IBE, what you did is right: uncomment the lines 8-11 in "IBEcalculation.m".

But make sure you remember this modification and revise them when you want to keep the IBE. This is a mistake I made earlier.

Thanks for your reply, I will remember it. Thank you very much!!!

badvibes4ever0105 commented 2 years ago

it always occurs an error whether I uncommemt those four lines or not. 'IBEcalculation.m' is only a function, you should run the script such as 'Simulation.m' .

Sorry,I still can't get it.Do I just type the function mentioned in the back of the code which was written by me 3 days ago or what?I did this and it still can't work.I have tried every effort to make it work but I still can't understand how to use the simulator after I read both WiLabV2Xsim Table of input parameters v6.1.pdf and WiLabV2Xsim v6.1 Tutorial_v0.pdf.However,I just can't understand how to only run the Simulation.m to get the figure 7,9,and 11 in Performance Analysis of Sidelink 5G-V2X Mode 2 Through an Open-Source Simulator and this is my goal.For example,Simulation.m is for different MCS but figure 7 is for different SCS so the code shouldn't be the same.I just only want to plot the figure 7,9,and 11.Sorry for the inconvenience,I am just a senior in the university and my professor thought that only revise the values of parameters in Simulation.m without revising the matlab code so he want me to use the simulator to plot those figures but it didn't seem to be what he thought.I feel helpless because I don't have any teammate to finish this task together so I only can ask you for help.

wzf-cn commented 2 years ago

Hi @badvibes4ever0105 ,

When you want to run the script, you could do one of the following:

  1. return to this script tag in MatLab, and then click "run";
  2. or, type the name of this script in the command window (as long as this script is in the working path of MatLab).

you could set different parameters when using the simulator, the "Simulation.m" is just an example of how to use this simulator. 1. you could set parameters into a config file, and pass this file into the entrance of the simulator "WiLabV2Xsim.m";

badvibes4ever0105 commented 2 years ago

擷取

Hi @badvibes4ever0105 ,

When you want to run the script, you could do one of the following:

  1. return to this script tag in MatLab, and then click "run";
  2. or, type the name of this script in the command window (as long as this script is in the working path of MatLab).

you could set different parameters when using the simulator, the "Simulation.m" is just an example of how to use this simulator. 1. you could set parameters into a config file, and pass this file into the entrance of the simulator "WiLabV2Xsim.m";

  • note: the useful line in the config file looks like this one:

    [seed] 3 [vMean] 20

  1. or, just pass the (name, value) pair to the function "WiLabV2Xsim" directly, as "Simulation.m" did.

I know how to run the script such as 'Simulation.m' but i can't run the function 'IBEcalculation.m' with the script.I just want to know what happens to this .

wzf-cn commented 2 years ago

When you try to run a function like "IBEcalcuation.m", you must pass some parameters as required. For example, please see the first line of this function: https://github.com/V2Xgithub/WiLabV2Xsim/blob/4350eb63ac091f8769de44ec3d03ad252146fcff/MatFilesUtilityLTE/IBEcalculation.m#L1 It requires three parameters: "simParams", "phyParams", "appParams".

If you want to run this "IBEcalcuation.m" directly, you need build the same parameters first as the simulator does, and then call this function. run something like:

simParams=.....;
phyParams=.....;
appParams=.....;
IBEcalcuation(simParams, phyParams, appParams)
badvibes4ever0105 commented 2 years ago

Sorry,I don't know what is the meaning of "simParams", "phyParams", "appParams" individually so I don't know what value should I use for "simParams", "phyParams", "appParams" individually.

joshsmith1999 commented 2 years ago

Sorry,I don't know what is the meaning of "simParams", "phyParams", "appParams" individually so I don't know what value should I use for "simParams", "phyParams", "appParams" individually.

“simParams" , "phyParams" ,"appParams" are struct incluing a series of properties that can be modified. You can look up them in the folder named ”MatFilesinit" For example, "simParams.simulationTime": you can find the property in 'MatFilesinit\initiateMainSimulationParameters.m' https://github.com/V2Xgithub/WiLabV2Xsim/blob/4350eb63ac091f8769de44ec3d03ad252146fcff/MatFilesInit/initiateMainSimulationParameters.m#L24 You can change simulationTime by these methods:

  1. Directly change the values in the addNewParam();
  2. configFiles(stored in the folder "ConfigFiles");
  3. command line(eg. WiLabV2Xsim('simulationTime', 10));
badvibes4ever0105 commented 2 years ago

Sorry,I don't know what is the meaning of "simParams", "phyParams", "appParams" individually so I don't know what value should I use for "simParams", "phyParams", "appParams" individually.

“simParams" , "phyParams" ,"appParams" are struct incluing a series of properties that can be modified. You can look up them in the folder named ”MatFilesinit" For example, "simParams.simulationTime": you can find the property in 'MatFilesinit\initiateMainSimulationParameters.m'

https://github.com/V2Xgithub/WiLabV2Xsim/blob/4350eb63ac091f8769de44ec3d03ad252146fcff/MatFilesInit/initiateMainSimulationParameters.m#L24

You can change simulationTime by these methods:

  1. Directly change the values in the addNewParam();
  2. configFiles(stored in the folder "ConfigFiles");
  3. command line(eg. WiLabV2Xsim('simulationTime', 10));

I want to plot the figure.7 and this is my result. code: one command window: two I don't know whether I understand your explanation or not.

wzf-cn commented 2 years ago

This link could be helpful https://www.mathworks.com/matlabcentral/answers/96005-why-do-i-get-the-error-undefined-function-or-variable

badvibes4ever0105 commented 1 year ago

I have tried every solution in the link but I still failed it code: 1 command window: 2 I want to ask whether my code is correct to plot figure 7 or not .

wzf-cn commented 1 year ago

sorry, your code may not be correct to plot figure 7. The answers and link earlier are trying to help you figure out what happened in that function, as you asked.

And if you want to plot figure 7, you need:

  1. comment or uncomment lines 8-11 of the file "IBEcalculation.m" for using IBE or not using IBE (https://github.com/V2Xgithub/WiLabV2Xsim/blob/d82dc1bb6c6845db74741f99f64508f87897ec80/MatFilesUtilityLTE/IBEcalculation.m#L7);
  2. set other related parameters in the config file or pass them into the function "WiLabV2Xsim.m" as the "Simulations.m" does;
  3. run simulations, collect results, and plot them.
badvibes4ever0105 commented 1 year ago

@wzf-cn Thanks,I find the problems and plot figure 7 successfully.Moreover,I want to plot figure 9 and what kind of parameters should I change to simulate the situation where M=20% and M=50%.

VittorioTodisco commented 1 year ago

The function BRreassignment3GPPautonomous.m handles the selection of new resources for LTE and NR-V2X. That function is evaluated at every slot. If a vehicle is transmitting, its reselection counter is decremented by one.

When the reselection counter of a vehicle expires, a new resource might be selected, according to the keep probability.

When the reselection counter reaches 1, the vehicle randomly decide if the resource will be kept or if a new resource must be selected. If the resource is kept the reselection counter is initialised again to a higher value. Instead, if a new resource must be selected the reselection counter goes to zero.

The new allocation occurs when the vehicle generate a packet. So, in order to have a new allocation a vehicle must have: 1) a new packet generated during this slot 2) reselection counter equals zero

After this small introduction, at line 299 of BRreselection3GPPautonomous.m you will find:

% Find number of remaining resources
    %
    %testMBest_5G is left to test the possibility to reintroduce L2 
    % if testMBest_5G is removed, set MBest to sum(usableBRs)
    MBest = ceil(nPossibleAllocations * simParams.testMBest_5G);
    MBest=min(MBest,sum(usableBRs));

Therefore the parameter to reintroduce L2 in NR is: simParams.testMBest_5G The default value is one, so NR generally considers all the available resources. If you want to reintroduce L2 set the parameter to 0.2,0.5…

Rolich commented 1 year ago

Good afternoon!

I have a few questions about simulator:

  1. In your simulation (from article), the noise floor is set to 9 dBm? [F_dB]
  2. What value is used for Range of Awarness [raw]?
  3. How can I connect trace files to implement car traffic mobility? What is the structure of the text file that is fed to the input of the modeling system?
badvibes4ever0105 commented 1 year ago

@VittorioTodisco Thanks,I plot figure 9 successfully.Moreover,I want to plot figure 11 and what kind of parameters should I change to simulate the situation where (1).Mode 2 (2).L2,M=20% (3).averaged RSRP (4). L2,M=20% averaged RSRP (5).Mode 2 coherent arrivals individually.

VittorioTodisco commented 1 year ago

@Rolich

  1. In the setting table of the article we wrote [F_dB]=9dB. At the moment I don't have the possibility to check. Unfortunately, we did not include the value of F_dB in the mainOut file. We will update this aspect soon. Nevertheless, we only use two values: 6dB and 9dB. You should obtain the same curve from figure 9 with one of the two settings.

  2. The value of Range of Awarness for the article was 300. Nevertheless, is better to use a set of values i.e. try to set raw=[50,150,300]. In any case, the value of raw is not essential to plot the figures of this article as we only consider the PRR. It is instead necessary when you consider outputs like the data age and the wireless blind spot probability.

VittorioTodisco commented 1 year ago

@badvibes4ever0105

In figure 11 we are considering a different type of traffic which we call incoherent generation and it is shown in the diagram of figure 4. With the incoherent generation, we imagine that a vehicle chooses a certain RRI (i.e. 200ms) but then generates packets periodically with a shorter periodicity (100ms in the article). In this way, each transmission reserves a future occupation that is then not used, and each transmission occurs without a previous reservation. When you allocate a new resource with LTE mode 4, the allocation can avoid collision even with this type of "incoherent generation". LTE mode 4 considers resources as busy by averaging the past sensed values over the whole sensing window (the sensend value at time t_a will be averaged among the sensed value at time t_a-100ms, t_a-200ms ..., t_a-1000ms). In NR, instead, this procedure is removed. Therefore resources are considered busy only on the information from the SCI associated with power above the threshold.

To generate this type of traffic set:

allocationPeriod=0.2; % this set the RRI to 200ms generationInterval=0.1; % this set the generation interval (periodic part)

Remember to add these when you call the WiLabV2Xsim function.

Now you have to simulate: Mode 2 with incoherent traffic as described above Mode 2 with L2 20% (as you did previously for figure 9)

To reintroduce the averaging process you need to comment a few lines in BRreassignment3GPPautonomous.m:

https://github.com/V2Xgithub/WiLabV2Xsim/blob/4350eb63ac091f8769de44ec3d03ad252146fcff/MatFilesResourceAllocationCV2X/BRreassignment3GPPautonomous.m#L190

if simParams.mode5G==0 % 4G procedure
    % Select the sensing matrix only for those vehicles that perform reallocation
    % and calculate the average of the measured power over the sensing window
    sensingMatrixScheduled = sum(stationManagement.sensingMatrixCV2X(:,:,scheduledID(indexSensingV)),1)/length(stationManagement.sensingMatrixCV2X(:,1,1));
    % "sensingMatrixScheduled" is a '1 x NbeaconIntervals' vector
else%if simParams.mode5G==1
    % Select the sensing matrix only for those vehicles that perform reallocation
    % Selects only the first row, which includes the slots relative to
    % the last 'averageTbeacon'
    % In 5G the average process is removed and the senging is
    % performed only on the basis of the decoded SCIs.

    sensingMatrixScheduled = stationManagement.sensingMatrixCV2X(1,:,scheduledID(indexSensingV));

end

You can comment the whole block apart from Line 193. This will reintroduce the averaging also in 5G. (Remember to uncomment again after you perfomed the simulation).

Finally to simulate Mode 2 with coherent arrivals just set allocationPeriod=0.2 and generationInterval=0.2

wzf-cn commented 1 year ago

The codes for plotting related figures have been uploaded with the simulator.

Please check the folder codeForPaper