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-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 set up two 8-VSB
22
* TV transmitters with adjacent channels. Each transmitter's spectrum has a
23
* bandwidth of 6 MHz. The first TV transmitter has a start frequency of
24
* 524 MHz while the second has a start frequency of 530 MHz. These transmitters
25
* model ATSC (North American digital TV standard) channels 23 and 24.
26
*
27
* A spectrum analyzer is used to measure the transmitted spectra from the
28
* TV transmitters. The file "spectrum-analyzer-tv-sim-2-0.tr" contains its
29
* 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
/* nodes and positions */
38
NodeContainer
tvTransmitterNodes
;
39
NodeContainer
spectrumAnalyzerNodes
;
40
NodeContainer
allNodes
;
41
tvTransmitterNodes
.
Create
(2);
42
spectrumAnalyzerNodes
.Create(1);
43
allNodes
.Add(
tvTransmitterNodes
);
44
allNodes
.Add(
spectrumAnalyzerNodes
);
45
MobilityHelper
mobility
;
46
Ptr<ListPositionAllocator>
nodePositionList
=
CreateObject<ListPositionAllocator>
();
47
nodePositionList
->Add(
48
Vector(128000.0, 0.0, 0.0));
// TV Transmitter 1; 128 km away from spectrum analyzer
49
nodePositionList
->Add(
50
Vector(0.0, 24000.0, 0.0));
// TV Transmitter 2; 24 km away from spectrum analyzer
51
nodePositionList
->Add(Vector(0.0, 0.0, 0.0));
// Spectrum Analyzer
52
mobility
.SetPositionAllocator(
nodePositionList
);
53
mobility
.SetMobilityModel(
"ns3::ConstantPositionMobilityModel"
);
54
mobility
.Install(
allNodes
);
55
56
/* channel and propagation */
57
SpectrumChannelHelper
channelHelper
=
SpectrumChannelHelper::Default
();
58
channelHelper
.SetChannel(
"ns3::MultiModelSpectrumChannel"
);
59
// constant path loss added just to show capability to set different propagation loss models
60
// FriisSpectrumPropagationLossModel already added by default in SpectrumChannelHelper
61
channelHelper
.AddSpectrumPropagationLoss(
"ns3::ConstantSpectrumPropagationLossModel"
);
62
Ptr<SpectrumChannel>
channel
=
channelHelper
.Create();
63
64
/* TV transmitter setup */
65
TvSpectrumTransmitterHelper
tvTransHelper
;
66
tvTransHelper
.
SetChannel
(channel);
67
tvTransHelper
.SetAttribute(
"StartFrequency"
,
DoubleValue
(524
e6
));
68
tvTransHelper
.SetAttribute(
"ChannelBandwidth"
,
DoubleValue
(6
e6
));
69
tvTransHelper
.SetAttribute(
"StartingTime"
,
TimeValue
(
Seconds
(0)));
70
tvTransHelper
.SetAttribute(
"TransmitDuration"
,
TimeValue
(
Seconds
(0.2)));
71
// 22.22 dBm/Hz from 1000 kW ERP transmit power, flat 6 MHz PSD spectrum assumed for this
72
// approximation
73
tvTransHelper
.SetAttribute(
"BasePsd"
,
DoubleValue
(22.22));
74
tvTransHelper
.SetAttribute(
"TvType"
,
EnumValue
(
TvSpectrumTransmitter::TVTYPE_8VSB
));
75
tvTransHelper
.SetAttribute(
"Antenna"
,
StringValue
(
"ns3::IsotropicAntennaModel"
));
76
tvTransHelper
.InstallAdjacent(
tvTransmitterNodes
);
77
78
/* frequency range for spectrum analyzer */
79
std::vector<double>
freqs
;
80
freqs
.reserve(200);
81
for
(
int
i
= 0;
i
< 200; ++
i
)
82
{
83
freqs
.push_back((
i
+ 5200) * 1
e5
);
84
}
85
Ptr<SpectrumModel>
spectrumAnalyzerFreqModel
=
Create<SpectrumModel>
(
freqs
);
86
87
/* spectrum analyzer setup */
88
SpectrumAnalyzerHelper
spectrumAnalyzerHelper
;
89
spectrumAnalyzerHelper
.
SetChannel
(channel);
90
spectrumAnalyzerHelper
.SetRxSpectrumModel(
spectrumAnalyzerFreqModel
);
91
spectrumAnalyzerHelper
.SetPhyAttribute(
"NoisePowerSpectralDensity"
,
92
DoubleValue
(1e-15));
// -120 dBm/Hz
93
spectrumAnalyzerHelper
.EnableAsciiAll(
"spectrum-analyzer-tv-sim"
);
94
NetDeviceContainer
spectrumAnalyzerDevices
=
95
spectrumAnalyzerHelper
.Install(
spectrumAnalyzerNodes
);
96
97
Simulator::Stop
(
Seconds
(0.4));
98
99
Simulator::Run
();
100
101
Simulator::Destroy
();
102
103
std::cout <<
"simulation done!"
<< std::endl;
104
std::cout <<
"see spectrum analyzer output file"
<< std::endl;
105
106
return
0;
107
}
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::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::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::TvSpectrumTransmitter::TVTYPE_8VSB
@ TVTYPE_8VSB
Definition
tv-spectrum-transmitter.h:43
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-example.cc
Generated on Mon Dec 15 2025 15:22:03 for ns-3 by
1.9.8