A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
18
using 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
*/
31
int
32
main(
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 */
38
RngSeedManager::SetSeed
(1);
39
RngSeedManager::SetRun
(3);
40
41
/* nodes and positions */
42
NodeContainer
spectrumAnalyzerNodes
;
43
spectrumAnalyzerNodes
.
Create
(1);
44
MobilityHelper
mobility
;
45
Ptr<ListPositionAllocator>
nodePositionList
=
CreateObject<ListPositionAllocator>
();
46
Vector
coordinates
=
47
GeographicPositions::GeographicToCartesianCoordinates
(48.86,
48
2.35,
49
0,
50
GeographicPositions::SPHERE
);
51
nodePositionList
->Add(
coordinates
);
// spectrum analyzer
52
mobility
.SetPositionAllocator(
nodePositionList
);
53
mobility
.SetMobilityModel(
"ns3::ConstantPositionMobilityModel"
);
54
mobility
.Install(
spectrumAnalyzerNodes
);
55
56
/* channel and propagation */
57
SpectrumChannelHelper
channelHelper
=
SpectrumChannelHelper::Default
();
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));
69
tvTransHelper
.SetAttribute(
"TvType"
,
EnumValue
(
TvSpectrumTransmitter::TVTYPE_COFDM
));
70
tvTransHelper
.SetAttribute(
"Antenna"
,
StringValue
(
"ns3::IsotropicAntennaModel"
));
71
72
tvTransHelper
.AssignStreams(300);
73
tvTransHelper
.CreateRegionalTvTransmitters(
TvSpectrumTransmitterHelper::REGION_EUROPE
,
74
TvSpectrumTransmitterHelper::DENSITY_MEDIUM
,
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) * 1
e5
);
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
98
Simulator::Stop
(
Seconds
(0.4));
99
100
Simulator::Run
();
101
102
Simulator::Destroy
();
103
104
std::cout <<
"simulation done!"
<< std::endl;
105
std::cout <<
"see spectrum analyzer output file"
<< std::endl;
106
107
return
0;
108
}
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::EnumValue
Hold variables of type enum.
Definition
enum.h:52
ns3::GeographicPositions::SPHERE
@ SPHERE
Definition
geographic-positions.h:70
ns3::GeographicPositions::GeographicToCartesianCoordinates
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...
Definition
geographic-positions.cc:41
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition
mobility-helper.h:33
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition
node-container.cc:73
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::RngSeedManager::SetRun
static void SetRun(uint64_t run)
Set the run number of simulation.
Definition
rng-seed-manager.cc:79
ns3::RngSeedManager::SetSeed
static void SetSeed(uint32_t seed)
Set the seed.
Definition
rng-seed-manager.cc:72
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::SpectrumAnalyzerHelper
Class to allow the Spectrum Analysis.
Definition
spectrum-analyzer-helper.h:32
ns3::SpectrumAnalyzerHelper::SetChannel
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
Definition
spectrum-analyzer-helper.cc:71
ns3::SpectrumChannelHelper
Setup a SpectrumChannel.
Definition
spectrum-helper.h:34
ns3::SpectrumChannelHelper::Default
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
Definition
spectrum-helper.cc:23
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::TimeValue
AttributeValue implementation for Time.
Definition
nstime.h:1431
ns3::TvSpectrumTransmitterHelper
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
Definition
tv-spectrum-transmitter-helper.h:56
ns3::TvSpectrumTransmitterHelper::SetChannel
void SetChannel(Ptr< SpectrumChannel > c)
Set the spectrum channel for the device(s) to transmit on.
Definition
tv-spectrum-transmitter-helper.cc:107
ns3::TvSpectrumTransmitterHelper::DENSITY_MEDIUM
@ DENSITY_MEDIUM
Definition
tv-spectrum-transmitter-helper.h:76
ns3::TvSpectrumTransmitterHelper::REGION_EUROPE
@ REGION_EUROPE
Definition
tv-spectrum-transmitter-helper.h:67
ns3::TvSpectrumTransmitter::TVTYPE_COFDM
@ TVTYPE_COFDM
Definition
tv-spectrum-transmitter.h:44
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
third.channel
channel
Definition
third.py:77
third.mobility
mobility
Definition
third.py:92
src
spectrum
examples
tv-trans-regional-example.cc
Generated on Mon Dec 15 2025 15:22:03 for ns-3 by
1.9.8