A Discrete-Event Network Simulator
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
18using 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 */
31int
32main(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);
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 */
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(524e6));
68 tvTransHelper.SetAttribute("ChannelBandwidth", DoubleValue(6e6));
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));
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) * 1e5);
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
98
100
102
103 std::cout << "simulation done!" << std::endl;
104 std::cout << "see spectrum analyzer output file" << std::endl;
105
106 return 0;
107}
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
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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Smart pointer class similar to boost::intrusive_ptr.
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 AddSpectrumPropagationLoss(std::string name, Ts &&... args)
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.
NetDeviceContainer InstallAdjacent(NodeContainer nodes)
Set up and start the TV Transmitter's transmission on the spectrum channel.
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