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