A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lr-wpan-error-model-plot.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 The Boeing Company
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Gary Pei <guangyu.pei@boeing.com>
7
*/
8
#include <ns3/abort.h>
9
#include <ns3/command-line.h>
10
#include <ns3/gnuplot.h>
11
#include <ns3/log.h>
12
#include <ns3/lr-wpan-error-model.h>
13
#include <ns3/nstime.h>
14
#include <ns3/packet.h>
15
#include <ns3/simulator.h>
16
#include <ns3/uinteger.h>
17
18
#include <fstream>
19
#include <iostream>
20
#include <string>
21
#include <vector>
22
23
using namespace
ns3
;
24
using namespace
ns3::lrwpan
;
25
26
NS_LOG_COMPONENT_DEFINE
(
"LrWpanErrorModelPlot"
);
27
28
//
29
// Plot 802.15.4 BER curve (compare against Figure E.2 of IEEE-802.15.4-2006)
30
//
31
int
32
main(
int
argc,
char
* argv[])
33
{
34
std::ofstream berfile(
"802.15.4-ber.plt"
);
35
Ptr<LrWpanErrorModel>
lrWpanError =
CreateObject<LrWpanErrorModel>
();
36
37
double
increment = 0.1;
38
double
minSnr = -10;
// dB
39
double
maxSnr = 5;
40
41
Gnuplot
berplot =
Gnuplot
(
"802.15.4-ber.eps"
);
42
Gnuplot2dDataset
berdataset(
"802.15.4"
);
43
44
for
(
double
snr = minSnr; snr <= maxSnr; snr += increment)
45
{
46
double
ber = 1.0 - lrWpanError->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
47
NS_LOG_DEBUG
(snr <<
"(dB) "
<< ber <<
" (BER)"
);
48
berdataset.Add(snr, ber);
49
}
50
51
berplot.
AddDataset
(berdataset);
52
53
berplot.
SetTerminal
(
"postscript eps color enh \"Times-BoldItalic\""
);
54
berplot.
SetLegend
(
"SNR (dB)"
,
"Bit Error Rate (BER)"
);
55
berplot.
SetExtra
(
"set xrange [-10:15]\n\
56
set yrange [1e-9:1]\n\
57
set log y\n\
58
set grid\n\
59
set style line 1 linewidth 5\n\
60
set style line 2 linewidth 5\n\
61
set style line 3 linewidth 5\n\
62
set style line 4 linewidth 5\n\
63
set style line 5 linewidth 5\n\
64
set style line 6 linewidth 5\n\
65
set style line 7 linewidth 5\n\
66
set style line 8 linewidth 5\n\
67
set style increment user"
);
68
berplot.
GenerateOutput
(berfile);
69
berfile.close();
70
71
return
0;
72
}
ns3::Gnuplot2dDataset
Class to represent a 2D points plot.
Definition
gnuplot.h:105
ns3::Gnuplot
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition
gnuplot.h:359
ns3::Gnuplot::AddDataset
void AddDataset(const GnuplotDataset &dataset)
Definition
gnuplot.cc:785
ns3::Gnuplot::SetLegend
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition
gnuplot.cc:765
ns3::Gnuplot::SetTerminal
void SetTerminal(const std::string &terminal)
Definition
gnuplot.cc:753
ns3::Gnuplot::GenerateOutput
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition
gnuplot.cc:791
ns3::Gnuplot::SetExtra
void SetExtra(const std::string &extra)
Definition
gnuplot.cc:772
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition
log.h:257
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::lrwpan
Definition
lr-wpan-constants.h:23
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lr-wpan
examples
lr-wpan-error-model-plot.cc
Generated on Fri Nov 8 2024 13:59:02 for ns-3 by
1.11.0