A Discrete-Event Network Simulator
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 * 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
34using namespace ns3;
35using namespace ns3::lrwpan;
36
37NS_LOG_COMPONENT_DEFINE("LrWpanErrorModelPlot");
38
39//
40// Plot 802.15.4 BER curve (compare against Figure E.2 of IEEE-802.15.4-2006)
41//
42int
43main(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\
67set yrange [1e-9:1]\n\
68set log y\n\
69set grid\n\
70set style line 1 linewidth 5\n\
71set style line 2 linewidth 5\n\
72set style line 3 linewidth 5\n\
73set style line 4 linewidth 5\n\
74set style line 5 linewidth 5\n\
75set style line 6 linewidth 5\n\
76set style line 7 linewidth 5\n\
77set style line 8 linewidth 5\n\
78set style increment user");
79 berplot.GenerateOutput(berfile);
80 berfile.close();
81
82 return 0;
83}
Class to represent a 2D points plot.
Definition: gnuplot.h:116
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:370
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:796
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:776
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:764
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:802
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:783
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.