A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tv-trans-regional-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
7 */
8
9#include <ns3/core-module.h>
10#include <ns3/mobility-module.h>
11#include <ns3/spectrum-analyzer-helper.h>
12#include <ns3/spectrum-helper.h>
13#include <ns3/tv-spectrum-transmitter-helper.h>
14
15#include <iostream>
16#include <stdlib.h>
17
18using namespace ns3;
19
20/**
21 * This example uses the TvSpectrumTransmitterHelper class to generate a random
22 * number of COFDM TV transmitters within a 250 km radius around latitude
23 * 48.86 degrees and longitude 2.35 degrees (Paris, France). The transmitters'
24 * frequencies and bandwidths correspond to the European TV channel allocations.
25 * These TV transmitters model the digital DVB-T standard.
26 *
27 * A spectrum analyzer is used to measure the transmitted spectra from the
28 * TV transmitters. The file "spectrum-analyzer-tv-sim-regional-0-0.tr" contains
29 * its output post simulation (and can be plotted with Gnuplot or MATLAB).
30 */
31int
32main(int argc, char** argv)
33{
34 CommandLine cmd(__FILE__);
35 cmd.Parse(argc, argv);
36
37 /* random seed and run number; adjust these to change random draws */
40
41 /* nodes and positions */
42 NodeContainer spectrumAnalyzerNodes;
43 spectrumAnalyzerNodes.Create(1);
46 Vector coordinates =
48 2.35,
49 0,
51 nodePositionList->Add(coordinates); // spectrum analyzer
52 mobility.SetPositionAllocator(nodePositionList);
53 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
54 mobility.Install(spectrumAnalyzerNodes);
55
56 /* channel and propagation */
58 channelHelper.SetChannel("ns3::MultiModelSpectrumChannel");
59 Ptr<SpectrumChannel> channel = channelHelper.Create();
60
61 /* TV transmitter setup */
62 TvSpectrumTransmitterHelper tvTransHelper;
63 tvTransHelper.SetChannel(channel);
64 tvTransHelper.SetAttribute("StartingTime", TimeValue(Seconds(0.1)));
65 tvTransHelper.SetAttribute("TransmitDuration", TimeValue(Seconds(0.1)));
66 // 7.96 dBm/Hz from 50 kW ERP transmit power, flat 8 MHz PSD spectrum assumed for this
67 // approximation
68 tvTransHelper.SetAttribute("BasePsd", DoubleValue(7.96));
70 tvTransHelper.SetAttribute("Antenna", StringValue("ns3::IsotropicAntennaModel"));
71
72 tvTransHelper.AssignStreams(300);
75 48.86,
76 2.35,
77 0,
78 250000);
79
80 /* frequency range for spectrum analyzer */
81 std::vector<double> freqs;
82 for (int i = 0; i < 6860; i = i + 5)
83 {
84 freqs.push_back((i + 1740) * 1e5);
85 }
86 Ptr<SpectrumModel> spectrumAnalyzerFreqModel = Create<SpectrumModel>(freqs);
87
88 /* spectrum analyzer setup */
89 SpectrumAnalyzerHelper spectrumAnalyzerHelper;
90 spectrumAnalyzerHelper.SetChannel(channel);
91 spectrumAnalyzerHelper.SetRxSpectrumModel(spectrumAnalyzerFreqModel);
92 spectrumAnalyzerHelper.SetPhyAttribute("NoisePowerSpectralDensity",
93 DoubleValue(4.14e-21)); // approx -174 dBm/Hz
94 spectrumAnalyzerHelper.EnableAsciiAll("spectrum-analyzer-tv-sim-regional");
95 NetDeviceContainer spectrumAnalyzerDevices =
96 spectrumAnalyzerHelper.Install(spectrumAnalyzerNodes);
97
99
101
103
104 std::cout << "simulation done!" << std::endl;
105 std::cout << "see spectrum analyzer output file" << std::endl;
106
107 return 0;
108}
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
static Vector GeographicToCartesianCoordinates(double latitude, double longitude, double altitude, EarthSpheroidType sphType)
Converts earth geographic/geodetic coordinates (latitude and longitude in degrees) with a given altit...
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Class to allow the Spectrum Analysis.
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Setup a SpectrumChannel.
Ptr< SpectrumChannel > Create() const
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void SetChannel(std::string type, Ts &&... args)
Hold variables of type string.
Definition string.h:45
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
void SetChannel(Ptr< SpectrumChannel > c)
Set the spectrum channel for the device(s) to transmit on.
int64_t AssignStreams(int64_t streamNum)
Assigns the stream number for the uniform random number generator to use.
void CreateRegionalTvTransmitters(Region region, Density density, double originLatitude, double originLongitude, double maxAltitude, double maxRadius)
Generates and installs (starts transmission on the spectrum channel) a random number of TV transmitte...
void SetAttribute(std::string name, const AttributeValue &val)
Set attribute for each TvSpectrumTransmitter instance to be created.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition third.py:77
mobility
Definition third.py:92