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 * 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
23using namespace ns3;
24using namespace ns3::lrwpan;
25
26NS_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//
31int
32main(int argc, char* argv[])
33{
34 std::ofstream berfile("802.15.4-ber.plt");
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\
56set yrange [1e-9:1]\n\
57set log y\n\
58set grid\n\
59set style line 1 linewidth 5\n\
60set style line 2 linewidth 5\n\
61set style line 3 linewidth 5\n\
62set style line 4 linewidth 5\n\
63set style line 5 linewidth 5\n\
64set style line 6 linewidth 5\n\
65set style line 7 linewidth 5\n\
66set style line 8 linewidth 5\n\
67set style increment user");
68 berplot.GenerateOutput(berfile);
69 berfile.close();
70
71 return 0;
72}
Class to represent a 2D points plot.
Definition gnuplot.h:105
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition gnuplot.h:359
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:785
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:765
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:753
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:791
void SetExtra(const std::string &extra)
Definition gnuplot.cc:772
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.