sat-link-results-plot.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions
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: Budiarto Herman <budiarto.herman@magister.fi>
19  *
20  */
21 
22 #include "ns3/core-module.h"
23 #include "ns3/gnuplot.h"
24 #include "ns3/satellite-env-variables.h"
25 #include "ns3/satellite-look-up-table.h"
26 #include "ns3/singleton.h"
27 
28 #include <fstream>
29 
37 NS_LOG_COMPONENT_DEFINE("SatLinkResultsPlot");
38 
39 namespace ns3
40 {
41 
61 class SatLinkResultsPlot : public SimpleRefCount<SatLinkResultsPlot>
62 {
63  public:
67  void Run();
68 
69  private:
70  void RunDvbRcs2Qpsk();
71  void RunDvbRcs2Psk8();
72  void RunDvbRcs2Qam16();
73  void RunDvbS2Qpsk();
74  void RunDvbS2Psk8();
75  void RunDvbS2Apsk16();
76  void RunDvbS2Apsk32();
77 
78  Gnuplot2dDataset GetGnuplotDataset(Ptr<SatLookUpTable> table, std::string title);
79  Gnuplot GetGnuplot(std::string outputName, std::string title);
80 
82  double m_minSinrDb;
83  double m_maxSinrDb;
84  std::string m_inputPath;
85 
86 }; // end of class SatLinkResultsPlot
87 
89 {
90  m_resolutionDb = 0.01;
91  m_minSinrDb = 0.0;
92  m_maxSinrDb = 20.0;
93  m_inputPath = Singleton<SatEnvVariables>::Get()->GetDataPath() + "/linkresults/";
94 }
95 
96 void
98 {
100  RunDvbRcs2Psk8();
101  RunDvbRcs2Qam16();
102  RunDvbS2Qpsk();
103  RunDvbS2Psk8();
104  RunDvbS2Apsk16();
105  RunDvbS2Apsk32();
106 }
107 
108 void
110 {
111  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat2.txt");
112  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat3.txt");
113  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat4.txt");
114  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat5.txt");
115  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat6.txt");
116  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat7.txt");
117  Ptr<SatLookUpTable> table7 =
118  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat13.txt");
119  Ptr<SatLookUpTable> table8 =
120  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat14.txt");
121  Ptr<SatLookUpTable> table9 =
122  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat15.txt");
123  Ptr<SatLookUpTable> table10 =
124  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat16.txt");
125  Ptr<SatLookUpTable> table11 =
126  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat17.txt");
127 
128  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 2: 112 bits, QPSK 1/3");
129  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 3: 304 bits, QPSK 1/3");
130  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 4: 472 bits, QPSK 1/2");
131  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 5: 680 bits, QPSK 2/3");
132  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "Waveform 6: 768 bits, QPSK 3/4");
133  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "Waveform 7: 864 bits, QPSK 5/6");
134  Gnuplot2dDataset dataset7 = GetGnuplotDataset(table7, "Waveform 13: 984 bits, QPSK 1/3");
135  Gnuplot2dDataset dataset8 = GetGnuplotDataset(table8, "Waveform 14: 1504 bits, QPSK 1/2");
136  Gnuplot2dDataset dataset9 = GetGnuplotDataset(table9, "Waveform 15: 2112 bits, QPSK 2/3");
137  Gnuplot2dDataset dataset10 = GetGnuplotDataset(table10, "Waveform 16: 2384 bits, QPSK 3/4");
138  Gnuplot2dDataset dataset11 = GetGnuplotDataset(table11, "Waveform 17: 2664 bits, QPSK 5/6");
139 
140  Gnuplot plot = GetGnuplot("rcs2_qpsk", "Link Results for DVB-RCS2 with QPSK");
141  plot.AddDataset(dataset1);
142  plot.AddDataset(dataset2);
143  plot.AddDataset(dataset3);
144  plot.AddDataset(dataset4);
145  plot.AddDataset(dataset5);
146  plot.AddDataset(dataset6);
147  plot.AddDataset(dataset7);
148  plot.AddDataset(dataset8);
149  plot.AddDataset(dataset9);
150  plot.AddDataset(dataset10);
151  plot.AddDataset(dataset11);
152 
153  std::string plotFileName = "rcs2_qpsk.plt";
154  std::ofstream plotFile(plotFileName.c_str());
155  plot.GenerateOutput(plotFile);
156  plotFile.close();
157 
158  std::cout << "Output file written: " << plotFileName << std::endl;
159 
160 } // end of void SatLinkResultsPlot::RunDvbRcs2Qpsk ()
161 
162 void
164 {
165  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat8.txt");
166  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat9.txt");
167  Ptr<SatLookUpTable> table3 =
168  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat10.txt");
169  Ptr<SatLookUpTable> table4 =
170  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat18.txt");
171  Ptr<SatLookUpTable> table5 =
172  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat19.txt");
173  Ptr<SatLookUpTable> table6 =
174  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat20.txt");
175 
176  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 8: 920 bits, 8PSK 2/3");
177  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 9: 1040 bits, 8PSK 3/4");
178  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 10: 1152 bits, 8PSK 5/6");
179  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 18: 2840 bits, 8PSK 2/3");
180  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "Waveform 19: 3200 bits, 8PSK 3/4");
181  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "Waveform 20: 3552 bits, 8PSK 5/6");
182 
183  Gnuplot plot = GetGnuplot("rcs2_8psk", "Link Results for DVB-RCS2 with 8PSK");
184  plot.AddDataset(dataset1);
185  plot.AddDataset(dataset2);
186  plot.AddDataset(dataset3);
187  plot.AddDataset(dataset4);
188  plot.AddDataset(dataset5);
189  plot.AddDataset(dataset6);
190 
191  std::string plotFileName = "rcs2_8psk.plt";
192  std::ofstream plotFile(plotFileName.c_str());
193  plot.GenerateOutput(plotFile);
194  plotFile.close();
195 
196  std::cout << "Output file written: " << plotFileName << std::endl;
197 
198 } // end of void SatLinkResultsPlot::RunDvbRcs2Psk8 ()
199 
200 void
202 {
203  Ptr<SatLookUpTable> table1 =
204  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat11.txt");
205  Ptr<SatLookUpTable> table2 =
206  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat12.txt");
207  Ptr<SatLookUpTable> table3 =
208  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat21.txt");
209  Ptr<SatLookUpTable> table4 =
210  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat22.txt");
211 
212  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 11: 1400 bits, 16QAM 3/4");
213  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 12: 1552 bits, 16QAM 5/6");
214  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 21: 4312 bits, 16QAM 3/4");
215  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 22: 4792 bits, 16QAM 5/6");
216 
217  Gnuplot plot = GetGnuplot("rcs2_16qam", "Link Results for DVB-RCS2 with 16QAM");
218  plot.AddDataset(dataset1);
219  plot.AddDataset(dataset2);
220  plot.AddDataset(dataset3);
221  plot.AddDataset(dataset4);
222 
223  std::string plotFileName = "rcs2_16qam.plt";
224  std::ofstream plotFile(plotFileName.c_str());
225  plot.GenerateOutput(plotFile);
226  plotFile.close();
227 
228  std::cout << "Output file written: " << plotFileName << std::endl;
229 
230 } // end of void SatLinkResultsPlot::RunDvbRcs2Qam16 ()
231 
232 void
234 {
235  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_1_to_2.txt");
236  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_2_to_3.txt");
237  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_3_to_4.txt");
238  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_3_to_5.txt");
239  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_4_to_5.txt");
240  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_5_to_6.txt");
241  Ptr<SatLookUpTable> table7 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_8_to_9.txt");
242  Ptr<SatLookUpTable> table8 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_9_to_10.txt");
243 
244  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "QPSK 1/2");
245  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "QPSK 2/3");
246  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "QPSK 3/4");
247  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "QPSK 3/5");
248  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "QPSK 4/5");
249  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "QPSK 5/6");
250  Gnuplot2dDataset dataset7 = GetGnuplotDataset(table7, "QPSK 8/9");
251  Gnuplot2dDataset dataset8 = GetGnuplotDataset(table8, "QPSK 9/10");
252 
253  Gnuplot plot = GetGnuplot("s2_qpsk", "Link Results for DVB-S2 with QPSK");
254  plot.AddDataset(dataset1);
255  plot.AddDataset(dataset2);
256  plot.AddDataset(dataset3);
257  plot.AddDataset(dataset4);
258  plot.AddDataset(dataset5);
259  plot.AddDataset(dataset6);
260  plot.AddDataset(dataset7);
261  plot.AddDataset(dataset8);
262 
263  std::string plotFileName = "s2_qpsk.plt";
264  std::ofstream plotFile(plotFileName.c_str());
265  plot.GenerateOutput(plotFile);
266  plotFile.close();
267 
268  std::cout << "Output file written: " << plotFileName << std::endl;
269 
270 } // end of void SatLinkResultsPlot::RunDvbS2Qpsk ()
271 
272 void
274 {
275  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_2_to_3.txt");
276  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_3_to_4.txt");
277  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_3_to_5.txt");
278  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_5_to_6.txt");
279  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_8_to_9.txt");
280  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_9_to_10.txt");
281 
282  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "8PSK 2/3");
283  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "8PSK 3/4");
284  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "8PSK 3/5");
285  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "8PSK 5/6");
286  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "8PSK 8/9");
287  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "8PSK 9/10");
288 
289  Gnuplot plot = GetGnuplot("s2_8psk", "Link Results for DVB-S2 with 8PSK");
290  plot.AddDataset(dataset1);
291  plot.AddDataset(dataset2);
292  plot.AddDataset(dataset3);
293  plot.AddDataset(dataset4);
294  plot.AddDataset(dataset5);
295  plot.AddDataset(dataset6);
296 
297  std::string plotFileName = "s2_8psk.plt";
298  std::ofstream plotFile(plotFileName.c_str());
299  plot.GenerateOutput(plotFile);
300  plotFile.close();
301 
302  std::cout << "Output file written: " << plotFileName << std::endl;
303 
304 } // end of void SatLinkResultsPlot::RunDvbS2Psk8 ()
305 
306 void
308 {
309  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_2_to_3.txt");
310  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_3_to_4.txt");
311  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_4_to_5.txt");
312  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_5_to_6.txt");
313  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_8_to_9.txt");
314  Ptr<SatLookUpTable> table6 =
315  CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_9_to_10.txt");
316 
317  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "16APSK 2/3");
318  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "16APSK 3/4");
319  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "16APSK 4/5");
320  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "16APSK 5/6");
321  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "16APSK 8/9");
322  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "16APSK 9/10");
323 
324  Gnuplot plot = GetGnuplot("s2_16apsk", "Link Results for DVB-S2 with 16APSK");
325  plot.AddDataset(dataset1);
326  plot.AddDataset(dataset2);
327  plot.AddDataset(dataset3);
328  plot.AddDataset(dataset4);
329  plot.AddDataset(dataset5);
330  plot.AddDataset(dataset6);
331 
332  std::string plotFileName = "s2_16apsk.plt";
333  std::ofstream plotFile(plotFileName.c_str());
334  plot.GenerateOutput(plotFile);
335  plotFile.close();
336 
337  std::cout << "Output file written: " << plotFileName << std::endl;
338 
339 } // end of void SatLinkResultsPlot::RunDvbS2Apsk16 ()
340 
341 void
343 {
344  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_3_to_4.txt");
345  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_4_to_5.txt");
346  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_5_to_6.txt");
347  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_8_to_9.txt");
348 
349  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "32APSK 3/4");
350  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "32APSK 4/5");
351  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "32APSK 5/6");
352  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "32APSK 8/9");
353 
354  Gnuplot plot = GetGnuplot("s2_32apsk", "Link Results for DVB-S2 with 32APSK");
355  plot.AddDataset(dataset1);
356  plot.AddDataset(dataset2);
357  plot.AddDataset(dataset3);
358  plot.AddDataset(dataset4);
359 
360  std::string plotFileName = "s2_32apsk.plt";
361  std::ofstream plotFile(plotFileName.c_str());
362  plot.GenerateOutput(plotFile);
363  plotFile.close();
364 
365  std::cout << "Output file written: " << plotFileName << std::endl;
366 
367 } // end of void SatLinkResultsPlot::RunDvbS2Apsk32 ()
368 
369 Gnuplot2dDataset
370 SatLinkResultsPlot::GetGnuplotDataset(Ptr<SatLookUpTable> table, std::string title)
371 {
372  Gnuplot2dDataset ret;
373  ret.SetTitle(title);
374  ret.SetStyle(Gnuplot2dDataset::LINES);
375 
376  bool writeFlag = false;
377  double bler;
378 
379  for (double sinr = m_minSinrDb; sinr < m_maxSinrDb; sinr += m_resolutionDb)
380  {
381  bler = table->GetBler(sinr);
382 
383  if (!writeFlag)
384  {
385  if (bler < 1)
386  {
387  // first time error rate is not 100%
388  writeFlag = true; // start writing the plot
389  ret.Add(sinr - m_resolutionDb, 1.0); // also add the previous point
390  ret.Add(sinr, bler);
391  }
392  }
393  else
394  {
395  if (bler < 1e-10)
396  {
397  // close enough to 0% error rate
398  writeFlag = false; // stop writing the plot
399  sinr = m_maxSinrDb; // exit for
400  }
401  else
402  {
403  ret.Add(sinr, bler);
404  }
405  }
406 
407  } // end of for (sinr = m_minSinrDb; sinr < m_maxSinrDb; sinr += m_resolutionDb)
408 
409  return ret;
410 
411 } // end of GetGnuplotDataset
412 
413 Gnuplot
414 SatLinkResultsPlot::GetGnuplot(std::string outputName, std::string title)
415 {
416  Gnuplot ret(outputName + ".png");
417  ret.SetTitle(title);
418  ret.SetTerminal("png");
419  ret.SetLegend("SINR (in dB)", "BLER");
420  ret.AppendExtra("set key bottom left");
421  ret.AppendExtra("set logscale y 10");
422  ret.AppendExtra("set ytics 10");
423  ret.AppendExtra("set mxtics 5");
424  ret.AppendExtra("set grid xtics mxtics ytics");
425  // TODO probably better if the X axis and its labels are on top and maybe emphasize major grid
426  // lines more than minor ones
427  return ret;
428 }
429 
430 } // end of namespace ns3
431 
432 int
433 main(int argc, char* argv[])
434 {
435  ns3::Ptr<ns3::SatLinkResultsPlot> stub;
436  stub = ns3::Create<ns3::SatLinkResultsPlot>();
437  stub->Run();
438 
439  return 0;
440 }
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.