A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
spectrum-value.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
3
/*
4
* Copyright (c) 2009 CTTC
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: Nicola Baldo <nbaldo@cttc.es>
20
*/
21
22
#include <ns3/spectrum-value.h>
23
#include <ns3/math.h>
24
#include <ns3/log.h>
25
26
NS_LOG_COMPONENT_DEFINE
(
"SpectrumValue"
);
27
28
29
namespace
ns3 {
30
31
32
SpectrumValue::SpectrumValue
()
33
{
34
}
35
36
SpectrumValue::SpectrumValue
(
Ptr<const SpectrumModel>
sof)
37
: m_spectrumModel (sof),
38
m_values (sof->GetNumBands ())
39
{
40
41
}
42
43
double
&
44
SpectrumValue:: operator[]
(
size_t
index)
45
{
46
return
m_values
.at (index);
47
}
48
49
50
SpectrumModelUid_t
51
SpectrumValue::GetSpectrumModelUid
()
const
52
{
53
return
m_spectrumModel
->
GetUid
();
54
}
55
56
57
Ptr<const SpectrumModel>
58
SpectrumValue::GetSpectrumModel
()
const
59
{
60
return
m_spectrumModel
;
61
}
62
63
64
Values::const_iterator
65
SpectrumValue::ConstValuesBegin
()
const
66
{
67
return
m_values
.begin ();
68
}
69
70
Values::const_iterator
71
SpectrumValue::ConstValuesEnd
()
const
72
{
73
return
m_values
.end ();
74
}
75
76
77
Values::iterator
78
SpectrumValue::ValuesBegin
()
79
{
80
return
m_values
.begin ();
81
}
82
83
Values::iterator
84
SpectrumValue::ValuesEnd
()
85
{
86
return
m_values
.end ();
87
}
88
89
Bands::const_iterator
90
SpectrumValue::ConstBandsBegin
()
const
91
{
92
return
m_spectrumModel
->
Begin
();
93
}
94
95
Bands::const_iterator
96
SpectrumValue::ConstBandsEnd
()
const
97
{
98
return
m_spectrumModel
->
End
();
99
}
100
101
102
void
103
SpectrumValue::Add
(
const
SpectrumValue
&
x
)
104
{
105
Values::iterator it1 =
m_values
.begin ();
106
Values::const_iterator it2 = x.
m_values
.begin ();
107
108
NS_ASSERT
(
m_spectrumModel
== x.
m_spectrumModel
);
109
110
while
(it1 !=
m_values
.end ())
111
{
112
NS_ASSERT
( it2 != x.
m_values
.end ());
113
*it1 += *it2;
114
++it1;
115
++it2;
116
}
117
}
118
119
120
void
121
SpectrumValue::Add
(
double
s)
122
{
123
Values::iterator it1 =
m_values
.begin ();
124
125
while
(it1 !=
m_values
.end ())
126
{
127
*it1 += s;
128
++it1;
129
}
130
}
131
132
133
134
void
135
SpectrumValue::Subtract
(
const
SpectrumValue
&
x
)
136
{
137
Values::iterator it1 =
m_values
.begin ();
138
Values::const_iterator it2 = x.
m_values
.begin ();
139
140
NS_ASSERT
(
m_spectrumModel
== x.
m_spectrumModel
);
141
142
while
(it1 !=
m_values
.end ())
143
{
144
NS_ASSERT
( it2 != x.
m_values
.end ());
145
*it1 -= *it2;
146
++it1;
147
++it2;
148
}
149
}
150
151
152
void
153
SpectrumValue::Subtract
(
double
s)
154
{
155
Add
(-s);
156
}
157
158
159
160
void
161
SpectrumValue::Multiply
(
const
SpectrumValue
&
x
)
162
{
163
Values::iterator it1 =
m_values
.begin ();
164
Values::const_iterator it2 = x.
m_values
.begin ();
165
166
NS_ASSERT
(
m_spectrumModel
== x.
m_spectrumModel
);
167
168
while
(it1 !=
m_values
.end ())
169
{
170
NS_ASSERT
( it2 != x.
m_values
.end ());
171
*it1 *= *it2;
172
++it1;
173
++it2;
174
}
175
}
176
177
178
void
179
SpectrumValue::Multiply
(
double
s)
180
{
181
Values::iterator it1 =
m_values
.begin ();
182
183
while
(it1 !=
m_values
.end ())
184
{
185
*it1 *= s;
186
++it1;
187
}
188
}
189
190
191
192
193
void
194
SpectrumValue::Divide
(
const
SpectrumValue
&
x
)
195
{
196
Values::iterator it1 =
m_values
.begin ();
197
Values::const_iterator it2 = x.
m_values
.begin ();
198
199
NS_ASSERT
(
m_spectrumModel
== x.
m_spectrumModel
);
200
201
while
(it1 !=
m_values
.end ())
202
{
203
NS_ASSERT
( it2 != x.
m_values
.end ());
204
*it1 /= *it2;
205
++it1;
206
++it2;
207
}
208
}
209
210
211
void
212
SpectrumValue::Divide
(
double
s)
213
{
214
NS_LOG_FUNCTION
(
this
<< s);
215
Values::iterator it1 =
m_values
.begin ();
216
217
while
(it1 !=
m_values
.end ())
218
{
219
*it1 /= s;
220
++it1;
221
}
222
}
223
224
225
226
227
void
228
SpectrumValue::ChangeSign
()
229
{
230
Values::iterator it1 =
m_values
.begin ();
231
232
while
(it1 !=
m_values
.end ())
233
{
234
*it1 = -(*it1);
235
++it1;
236
}
237
}
238
239
240
void
241
SpectrumValue::ShiftLeft
(
int
n)
242
{
243
int
i = 0;
244
while
(i < (
int
)
m_values
.size () - n)
245
{
246
m_values
.at (i) =
m_values
.at (i + n);
247
i++;
248
}
249
while
(i < (
int
)
m_values
.size ())
250
{
251
m_values
.at (i) = 0;
252
i++;
253
}
254
}
255
256
257
void
258
SpectrumValue::ShiftRight
(
int
n)
259
{
260
int
i =
m_values
.size () - 1;
261
while
(i - n >= 0)
262
{
263
m_values
.at (i) =
m_values
.at (i - n);
264
i = i - 1;
265
}
266
while
(i >= 0)
267
{
268
m_values
.at (i) = 0;
269
--i;
270
}
271
}
272
273
274
275
void
276
SpectrumValue::Pow
(
double
exp)
277
{
278
NS_LOG_FUNCTION
(
this
<< exp);
279
Values::iterator it1 =
m_values
.begin ();
280
281
while
(it1 !=
m_values
.end ())
282
{
283
*it1 = std::pow (*it1, exp);
284
++it1;
285
}
286
}
287
288
289
void
290
SpectrumValue::Exp
(
double
base)
291
{
292
NS_LOG_FUNCTION
(
this
<< base);
293
Values::iterator it1 =
m_values
.begin ();
294
295
while
(it1 !=
m_values
.end ())
296
{
297
*it1 = std::pow (base, *it1);
298
++it1;
299
}
300
}
301
302
303
void
304
SpectrumValue::Log10
()
305
{
306
NS_LOG_FUNCTION
(
this
);
307
Values::iterator it1 =
m_values
.begin ();
308
309
while
(it1 !=
m_values
.end ())
310
{
311
*it1 = std::log10 (*it1);
312
++it1;
313
}
314
}
315
316
void
317
SpectrumValue::Log2
()
318
{
319
NS_LOG_FUNCTION
(
this
);
320
Values::iterator it1 =
m_values
.begin ();
321
322
while
(it1 !=
m_values
.end ())
323
{
324
*it1 = log2 (*it1);
325
++it1;
326
}
327
}
328
329
330
void
331
SpectrumValue::Log
()
332
{
333
NS_LOG_FUNCTION
(
this
);
334
Values::iterator it1 =
m_values
.begin ();
335
336
while
(it1 !=
m_values
.end ())
337
{
338
*it1 = std::log (*it1);
339
++it1;
340
}
341
}
342
343
double
344
Norm
(
const
SpectrumValue
&
x
)
345
{
346
double
s = 0;
347
Values::const_iterator it1 = x.
ConstValuesBegin
();
348
while
(it1 != x.
ConstValuesEnd
())
349
{
350
s += (*it1) * (*it1);
351
++it1;
352
}
353
return
std::sqrt (s);
354
}
355
356
357
double
358
Sum
(
const
SpectrumValue
&
x
)
359
{
360
double
s = 0;
361
Values::const_iterator it1 = x.
ConstValuesBegin
();
362
while
(it1 != x.
ConstValuesEnd
())
363
{
364
s += (*it1);
365
++it1;
366
}
367
return
s;
368
}
369
370
371
372
double
373
Prod
(
const
SpectrumValue
&
x
)
374
{
375
double
s = 0;
376
Values::const_iterator it1 = x.
ConstValuesBegin
();
377
while
(it1 != x.
ConstValuesEnd
())
378
{
379
s *= (*it1);
380
++it1;
381
}
382
return
s;
383
}
384
385
double
386
Integral
(
const
SpectrumValue
& arg)
387
{
388
double
i = 0;
389
Values::const_iterator vit = arg.
ConstValuesBegin
();
390
Bands::const_iterator bit = arg.
ConstBandsBegin
();
391
while
(vit != arg.
ConstValuesEnd
())
392
{
393
NS_ASSERT
(bit != arg.
ConstBandsEnd
());
394
i += (*vit) * (bit->fh - bit->fl);
395
++vit;
396
++bit;
397
}
398
NS_ASSERT
(bit == arg.
ConstBandsEnd
());
399
return
i;
400
}
401
402
403
404
Ptr<SpectrumValue>
405
SpectrumValue::Copy
()
const
406
{
407
Ptr<SpectrumValue>
p = Create<SpectrumValue> (
m_spectrumModel
);
408
*p = *
this
;
409
return
p;
410
411
// return Copy<SpectrumValue> (*this)
412
}
413
414
415
std::ostream&
416
operator <<
(std::ostream& os,
const
SpectrumValue
& pvf)
417
{
418
Values::const_iterator it1 = pvf.
ConstValuesBegin
();
419
while
(it1 != pvf.
ConstValuesEnd
())
420
{
421
os << *it1 <<
" "
;
422
++it1;
423
}
424
os << std::endl;
425
return
os;
426
}
427
428
429
430
SpectrumValue
431
operator+
(
const
SpectrumValue
& lhs,
const
SpectrumValue
& rhs)
432
{
433
SpectrumValue
res = lhs;
434
res.
Add
(rhs);
435
return
res;
436
}
437
438
439
SpectrumValue
440
operator+
(
const
SpectrumValue
& lhs,
double
rhs)
441
{
442
SpectrumValue
res = lhs;
443
res.
Add
(rhs);
444
return
res;
445
}
446
447
448
SpectrumValue
449
operator+
(
double
lhs,
const
SpectrumValue
& rhs)
450
{
451
SpectrumValue
res = rhs;
452
res.
Add
(lhs);
453
return
res;
454
}
455
456
457
SpectrumValue
458
operator-
(
const
SpectrumValue
& lhs,
const
SpectrumValue
& rhs)
459
{
460
SpectrumValue
res = rhs;
461
res.
ChangeSign
();
462
res.
Add
(lhs);
463
return
res;
464
}
465
466
467
468
SpectrumValue
469
operator-
(
const
SpectrumValue
& lhs,
double
rhs)
470
{
471
SpectrumValue
res = lhs;
472
res.
Subtract
(rhs);
473
return
res;
474
}
475
476
477
SpectrumValue
478
operator-
(
double
lhs,
const
SpectrumValue
& rhs)
479
{
480
SpectrumValue
res = rhs;
481
res.
Subtract
(lhs);
482
return
res;
483
}
484
485
SpectrumValue
486
operator*
(
const
SpectrumValue
& lhs,
const
SpectrumValue
& rhs)
487
{
488
SpectrumValue
res = lhs;
489
res.
Multiply
(rhs);
490
return
res;
491
}
492
493
494
SpectrumValue
495
operator*
(
const
SpectrumValue
& lhs,
double
rhs)
496
{
497
SpectrumValue
res = lhs;
498
res.
Multiply
(rhs);
499
return
res;
500
}
501
502
503
SpectrumValue
504
operator*
(
double
lhs,
const
SpectrumValue
& rhs)
505
{
506
SpectrumValue
res = rhs;
507
res.
Multiply
(lhs);
508
return
res;
509
}
510
511
512
SpectrumValue
513
operator/
(
const
SpectrumValue
& lhs,
const
SpectrumValue
& rhs)
514
{
515
SpectrumValue
res = lhs;
516
res.
Divide
(rhs);
517
return
res;
518
}
519
520
521
SpectrumValue
522
operator/
(
const
SpectrumValue
& lhs,
double
rhs)
523
{
524
SpectrumValue
res = lhs;
525
res.
Divide
(rhs);
526
return
res;
527
}
528
529
530
SpectrumValue
531
operator/
(
double
lhs,
const
SpectrumValue
& rhs)
532
{
533
SpectrumValue
res = rhs;
534
res.
Divide
(lhs);
535
return
res;
536
}
537
538
539
SpectrumValue
540
operator+
(
const
SpectrumValue
& rhs)
541
{
542
return
rhs;
543
}
544
545
SpectrumValue
546
operator-
(
const
SpectrumValue
& rhs)
547
{
548
SpectrumValue
res = rhs;
549
res.
ChangeSign
();
550
return
res;
551
}
552
553
554
SpectrumValue
555
Pow
(
double
lhs,
const
SpectrumValue
& rhs)
556
{
557
SpectrumValue
res = rhs;
558
res.
Exp
(lhs);
559
return
res;
560
}
561
562
563
SpectrumValue
564
Pow
(
const
SpectrumValue
& lhs,
double
rhs)
565
{
566
SpectrumValue
res = lhs;
567
res.
Pow
(rhs);
568
return
res;
569
}
570
571
572
SpectrumValue
573
Log10
(
const
SpectrumValue
& arg)
574
{
575
SpectrumValue
res = arg;
576
res.
Log10
();
577
return
res;
578
}
579
580
SpectrumValue
581
Log2
(
const
SpectrumValue
& arg)
582
{
583
SpectrumValue
res = arg;
584
res.
Log2
();
585
return
res;
586
}
587
588
SpectrumValue
589
Log
(
const
SpectrumValue
& arg)
590
{
591
SpectrumValue
res = arg;
592
res.
Log
();
593
return
res;
594
}
595
596
SpectrumValue&
597
SpectrumValue:: operator+=
(
const
SpectrumValue
& rhs)
598
{
599
Add
(rhs);
600
return
*
this
;
601
}
602
603
SpectrumValue
&
604
SpectrumValue:: operator-=
(
const
SpectrumValue
& rhs)
605
{
606
Subtract
(rhs);
607
return
*
this
;
608
}
609
610
SpectrumValue
&
611
SpectrumValue:: operator*=
(
const
SpectrumValue
& rhs)
612
{
613
Multiply
(rhs);
614
return
*
this
;
615
}
616
617
SpectrumValue
&
618
SpectrumValue:: operator/=
(
const
SpectrumValue
& rhs)
619
{
620
Divide
(rhs);
621
return
*
this
;
622
}
623
624
625
SpectrumValue
&
626
SpectrumValue:: operator+=
(
double
rhs)
627
{
628
Add
(rhs);
629
return
*
this
;
630
}
631
632
SpectrumValue
&
633
SpectrumValue:: operator-=
(
double
rhs)
634
{
635
Subtract
(rhs);
636
return
*
this
;
637
}
638
639
SpectrumValue
&
640
SpectrumValue:: operator*=
(
double
rhs)
641
{
642
Multiply
(rhs);
643
return
*
this
;
644
}
645
646
SpectrumValue
&
647
SpectrumValue:: operator/=
(
double
rhs)
648
{
649
Divide
(rhs);
650
return
*
this
;
651
}
652
653
654
SpectrumValue
&
655
SpectrumValue:: operator=
(
double
rhs)
656
{
657
Values::iterator it1 =
m_values
.begin ();
658
659
while
(it1 !=
m_values
.end ())
660
{
661
*it1 = rhs;
662
++it1;
663
}
664
return
*
this
;
665
}
666
667
668
669
SpectrumValue
670
SpectrumValue:: operator<<
(
int
n)
const
671
{
672
SpectrumValue
res = *
this
;
673
res.
ShiftLeft
(n);
674
return
res;
675
}
676
677
SpectrumValue
678
SpectrumValue:: operator>>
(
int
n)
const
679
{
680
SpectrumValue
res = *
this
;
681
res.
ShiftRight
(n);
682
return
res;
683
}
684
685
686
687
688
}
// namespace ns3
689
src
spectrum
model
spectrum-value.cc
Generated on Fri Dec 21 2012 19:00:46 for ns-3 by
1.8.1.2