A Discrete-Event Network Simulator
API
lr-wpan-error-model-plot.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 The Boeing Company
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Gary Pei <guangyu.pei@boeing.com>
18  */
19 #include <ns3/abort.h>
20 #include <ns3/command-line.h>
21 #include <ns3/gnuplot.h>
22 #include <ns3/log.h>
23 #include <ns3/lr-wpan-error-model.h>
24 #include <ns3/nstime.h>
25 #include <ns3/packet.h>
26 #include <ns3/simulator.h>
27 #include <ns3/uinteger.h>
28 
29 #include <fstream>
30 #include <iostream>
31 #include <string>
32 #include <vector>
33 
34 using namespace ns3;
35 
36 NS_LOG_COMPONENT_DEFINE("LrWpanErrorModelPlot");
37 
38 //
39 // Plot 802.15.4 BER curve (compare against Figure E.2 of IEEE-802.15.4-2006)
40 //
41 int
42 main(int argc, char* argv[])
43 {
44  std::ofstream berfile("802.15.4-ber.plt");
45  Ptr<LrWpanErrorModel> lrWpanError = CreateObject<LrWpanErrorModel>();
46 
47  double increment = 0.1;
48  double minSnr = -10; // dB
49  double maxSnr = 5;
50 
51  Gnuplot berplot = Gnuplot("802.15.4-ber.eps");
52  Gnuplot2dDataset berdataset("802.15.4");
53 
54  for (double snr = minSnr; snr <= maxSnr; snr += increment)
55  {
56  double ber = 1.0 - lrWpanError->GetChunkSuccessRate(pow(10.0, snr / 10.0), 1);
57  NS_LOG_DEBUG(snr << "(dB) " << ber << " (BER)");
58  berdataset.Add(snr, ber);
59  }
60 
61  berplot.AddDataset(berdataset);
62 
63  berplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
64  berplot.SetLegend("SNR (dB)", "Bit Error Rate (BER)");
65  berplot.SetExtra("set xrange [-10:15]\n\
66 set yrange [1e-9:1]\n\
67 set log y\n\
68 set grid\n\
69 set style line 1 linewidth 5\n\
70 set style line 2 linewidth 5\n\
71 set style line 3 linewidth 5\n\
72 set style line 4 linewidth 5\n\
73 set style line 5 linewidth 5\n\
74 set style line 6 linewidth 5\n\
75 set style line 7 linewidth 5\n\
76 set style line 8 linewidth 5\n\
77 set style increment user");
78  berplot.GenerateOutput(berfile);
79  berfile.close();
80 
81  return 0;
82 }
Class to represent a 2D points plot.
Definition: gnuplot.h:118
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:373
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:759
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:739
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:727
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:765
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:746
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
Every class exported by the ns3 library is enclosed in the ns3 namespace.