author | Mitch Watrous <watrous@u.washington.edu> |
Wed, 18 May 2011 17:24:04 -0700 | |
changeset 7241 | 0a7a16b599e8 |
parent 7142 | 89a701fec3a1 |
child 7385 | 10beb0e53130 |
child 8098 | 575e7f7c6146 |
permissions | -rw-r--r-- |
6349 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2009 CTTC |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License version 2 as |
|
7 |
* published by the Free Software Foundation; |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
* |
|
18 |
* Author: Nicola Baldo <nbaldo@cttc.es> |
|
19 |
*/ |
|
20 |
||
21 |
#ifndef SPECTRUM_VALUE_H |
|
22 |
#define SPECTRUM_VALUE_H |
|
23 |
||
24 |
#include <ns3/ptr.h> |
|
25 |
#include <ns3/simple-ref-count.h> |
|
26 |
#include <ns3/spectrum-model.h> |
|
27 |
#include <ostream> |
|
28 |
#include <vector> |
|
29 |
||
30 |
namespace ns3 { |
|
31 |
||
32 |
||
33 |
typedef std::vector<double> Values; |
|
34 |
||
35 |
/** |
|
7241
0a7a16b599e8
Make some more modules show up on doxygen modules page
Mitch Watrous <watrous@u.washington.edu>
parents:
7142
diff
changeset
|
36 |
* \ingroup spectrum |
0a7a16b599e8
Make some more modules show up on doxygen modules page
Mitch Watrous <watrous@u.washington.edu>
parents:
7142
diff
changeset
|
37 |
* |
6349 | 38 |
* \brief Set of values corresponding to a given SpectrumModel |
39 |
* |
|
40 |
* This class implements a Function Space which can represent any |
|
41 |
* function \f$ g: F \in {\sf |
|
42 |
* R\hspace*{-0.9ex}\rule{0.15ex}{1.5ex}\hspace*{0.9ex}}^N \rightarrow {\sf R\hspace*{-0.9ex}\rule{0.15ex}{1.5ex}\hspace*{0.9ex}} \f$ |
|
43 |
* |
|
44 |
* Every instance of this class represent a particular function \f$ g(F) \f$. |
|
45 |
* The domain of the function space, i.e., \f$ F \f$, is implemented by SetOfFreq. |
|
46 |
* The codomain of the function space is implemented by SetOfValues |
|
47 |
* |
|
48 |
* To every possible value of \f$ F\f$ corresponds a different Function |
|
49 |
* Space. |
|
50 |
* Mathematical operations are defined in this Function Space; these |
|
51 |
* operations are implemented by means of operator overloading. |
|
52 |
* |
|
53 |
* The intended use of this class is to represent frequency-dependent |
|
54 |
* things, such as power spectral densities, frequency-dependent |
|
55 |
* propagation losses, spectral masks, etc. |
|
56 |
*/ |
|
57 |
class SpectrumValue : public SimpleRefCount<SpectrumValue> |
|
58 |
{ |
|
59 |
public: |
|
60 |
/** |
|
61 |
* @brief SpectrumValue constructor |
|
62 |
* |
|
63 |
* @param sm pointer to the SpectrumModel which implements the set of frequencies to which the values |
|
64 |
* will be referring. |
|
65 |
* |
|
66 |
* @warning the intended use if that sm points to a static object |
|
67 |
* which will be there for the whole simulation. This is reasonable |
|
68 |
* since the set of frequencies which are to be used in the |
|
69 |
* simulation is normally known before the simulation starts. Make |
|
70 |
* sure that the SpectrumModel instance which sm points to has already been |
|
71 |
* initialized by the time this method is invoked. The main reason is |
|
72 |
* that if you initialize the SpectrumModel instance afterwards, and |
|
73 |
* the memory for the underlying std::vector gets reallocated, then |
|
74 |
* sm will not be a valid reference anymore. Another reason is that |
|
75 |
* m_values could end up having the wrong size. |
|
76 |
*/ |
|
77 |
SpectrumValue (Ptr<const SpectrumModel> sm); |
|
78 |
||
6355
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
79 |
|
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
80 |
SpectrumValue (); |
7142
89a701fec3a1
run check-style.py on src/spectrum
Nicola Baldo <nicola@baldo.biz>
parents:
6801
diff
changeset
|
81 |
|
6355
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
82 |
|
6349 | 83 |
/** |
84 |
* Access value at given frequency index |
|
85 |
* |
|
86 |
* @param index the given frequency index |
|
87 |
* |
|
88 |
* @return reference to the value |
|
89 |
*/ |
|
90 |
double& operator[] (size_t index); |
|
91 |
||
92 |
||
93 |
||
94 |
/** |
|
95 |
* |
|
96 |
* @return the uid of the embedded SpectrumModel |
|
97 |
*/ |
|
98 |
SpectrumModelUid_t GetSpectrumModelUid () const; |
|
99 |
||
100 |
||
101 |
/** |
|
102 |
* |
|
103 |
* @return the embedded SpectrumModel |
|
104 |
*/ |
|
105 |
Ptr<const SpectrumModel> GetSpectrumModel () const; |
|
106 |
||
107 |
||
108 |
/** |
|
109 |
* |
|
110 |
* |
|
111 |
* @return a const iterator pointing to the beginning of the embedded SpectrumModel |
|
112 |
*/ |
|
113 |
Bands::const_iterator ConstBandsBegin () const; |
|
114 |
||
115 |
/** |
|
116 |
* |
|
117 |
* |
|
118 |
* @return a const iterator pointing to the end of the embedded SpectrumModel |
|
119 |
*/ |
|
120 |
Bands::const_iterator ConstBandsEnd () const; |
|
121 |
||
122 |
||
123 |
/** |
|
124 |
* |
|
125 |
* |
|
126 |
* @return a const iterator pointing to the beginning of the embedded SpectrumModel |
|
127 |
*/ |
|
128 |
Values::const_iterator ConstValuesBegin () const; |
|
129 |
||
130 |
/** |
|
131 |
* |
|
132 |
* |
|
133 |
* @return a const iterator pointing to the end of the embedded SpectrumModel |
|
134 |
*/ |
|
135 |
Values::const_iterator ConstValuesEnd () const; |
|
136 |
||
137 |
/** |
|
138 |
* |
|
139 |
* |
|
140 |
* @return an iterator pointing to the beginning of the embedded SpectrumModel |
|
141 |
*/ |
|
142 |
Values::iterator ValuesBegin (); |
|
143 |
||
144 |
/** |
|
145 |
* |
|
146 |
* |
|
147 |
* @return an iterator pointing to the end of the embedded SpectrumModel |
|
148 |
*/ |
|
149 |
Values::iterator ValuesEnd (); |
|
150 |
||
151 |
||
152 |
||
153 |
/** |
|
154 |
* addition operator |
|
155 |
* |
|
156 |
* @param lhs Left Hand Side of the operator |
|
157 |
* @param rhs Right Hand Side of the operator |
|
158 |
* |
|
159 |
* @return the value of lhs + rhs |
|
160 |
*/ |
|
161 |
friend SpectrumValue operator+ (const SpectrumValue& lhs, const SpectrumValue& rhs); |
|
162 |
||
163 |
||
164 |
/** |
|
165 |
* addition operator |
|
166 |
* |
|
167 |
* @param lhs Left Hand Side of the operator |
|
168 |
* @param rhs Right Hand Side of the operator |
|
169 |
* |
|
170 |
* @return the value of lhs + rhs |
|
171 |
*/ |
|
172 |
friend SpectrumValue operator+ (const SpectrumValue& lhs, double rhs); |
|
173 |
||
174 |
/** |
|
175 |
* addition operator |
|
176 |
* |
|
177 |
* @param lhs Left Hand Side of the operator |
|
178 |
* @param rhs Right Hand Side of the operator |
|
179 |
* |
|
180 |
* @return the value of lhs + rhs |
|
181 |
*/ |
|
182 |
friend SpectrumValue operator+ (double lhs, const SpectrumValue& rhs); |
|
183 |
||
184 |
||
185 |
/** |
|
186 |
* subtraction operator |
|
187 |
* |
|
188 |
* @param lhs Left Hand Side of the operator |
|
189 |
* @param rhs Right Hand Side of the operator |
|
190 |
* |
|
191 |
* @return the value of lhs - rhs |
|
192 |
*/ |
|
193 |
friend SpectrumValue operator- (const SpectrumValue& lhs, const SpectrumValue& rhs); |
|
194 |
||
195 |
/** |
|
196 |
* subtraction operator |
|
197 |
* |
|
198 |
* @param lhs Left Hand Side of the operator |
|
199 |
* @param rhs Right Hand Side of the operator |
|
200 |
* |
|
201 |
* @return the value of lhs - rhs |
|
202 |
*/ |
|
203 |
friend SpectrumValue operator- (const SpectrumValue& lhs, double rhs); |
|
204 |
||
205 |
/** |
|
206 |
* subtraction operator |
|
207 |
* |
|
208 |
* @param lhs Left Hand Side of the operator |
|
209 |
* @param rhs Right Hand Side of the operator |
|
210 |
* |
|
211 |
* @return the value of lhs - rhs |
|
212 |
*/ |
|
6445 | 213 |
friend SpectrumValue operator- (double lhs, const SpectrumValue& rhs); |
6349 | 214 |
|
215 |
/** |
|
216 |
* multiplication component-by-component (Schur product) |
|
217 |
* |
|
218 |
* @param lhs Left Hand Side of the operator |
|
219 |
* @param rhs Right Hand Side of the operator |
|
220 |
* |
|
221 |
* @return the value of lhs * rhs |
|
222 |
*/ |
|
223 |
friend SpectrumValue operator* (const SpectrumValue& lhs, const SpectrumValue& rhs); |
|
224 |
||
225 |
/** |
|
226 |
* multiplication by a scalar |
|
227 |
* |
|
228 |
* @param lhs Left Hand Side of the operator |
|
229 |
* @param rhs Right Hand Side of the operator |
|
230 |
* |
|
231 |
* @return the value of lhs * rhs |
|
232 |
*/ |
|
233 |
friend SpectrumValue operator* (const SpectrumValue& lhs, double rhs); |
|
234 |
||
235 |
/** |
|
236 |
* multiplication of a scalar |
|
237 |
* |
|
238 |
* @param lhs Left Hand Side of the operator |
|
239 |
* @param rhs Right Hand Side of the operator |
|
240 |
* |
|
241 |
* @return the value of lhs * rhs |
|
242 |
*/ |
|
243 |
friend SpectrumValue operator* (double lhs, const SpectrumValue& rhs); |
|
244 |
||
245 |
/** |
|
246 |
* division component-by-component |
|
247 |
* |
|
248 |
* @param lhs Left Hand Side of the operator |
|
249 |
* @param rhs Right Hand Side of the operator |
|
250 |
* |
|
251 |
* @return the value of lhs / rhs |
|
252 |
*/ |
|
253 |
friend SpectrumValue operator/ (const SpectrumValue& lhs, const SpectrumValue& rhs); |
|
254 |
||
255 |
/** |
|
256 |
* division by a scalar |
|
257 |
* |
|
258 |
* @param lhs Left Hand Side of the operator |
|
259 |
* @param rhs Right Hand Side of the operator |
|
260 |
* |
|
261 |
* @return the value of *this / rhs |
|
262 |
*/ |
|
263 |
friend SpectrumValue operator/ (const SpectrumValue& lhs, double rhs); |
|
264 |
||
265 |
/** |
|
266 |
* division of a scalar |
|
267 |
* |
|
268 |
* @param lhs Left Hand Side of the operator |
|
269 |
* @param rhs Right Hand Side of the operator |
|
270 |
* |
|
271 |
* @return the value of *this / rhs |
|
272 |
*/ |
|
273 |
friend SpectrumValue operator/ (double lhs, const SpectrumValue& rhs); |
|
274 |
||
275 |
/** |
|
276 |
* unary plus operator |
|
277 |
* |
|
278 |
* |
|
279 |
* @return the value of *this |
|
280 |
*/ |
|
281 |
friend SpectrumValue operator+ (const SpectrumValue& rhs); |
|
282 |
||
283 |
/** |
|
284 |
* unary minus operator |
|
285 |
* |
|
286 |
* |
|
287 |
* @return the value of - *this |
|
288 |
*/ |
|
289 |
friend SpectrumValue operator- (const SpectrumValue& rhs); |
|
290 |
||
291 |
||
292 |
/** |
|
293 |
* left shift operator |
|
294 |
* |
|
295 |
* @param n position to shift |
|
296 |
* |
|
297 |
* @return the value of *this left shifted by n positions. In other |
|
298 |
* words, the function of the set of frequencies represented by |
|
299 |
* *this is left-shifted in frequency by n positions. |
|
300 |
*/ |
|
301 |
SpectrumValue operator<< (int n) const; |
|
302 |
||
303 |
/** |
|
304 |
* right shift operator |
|
305 |
* |
|
306 |
* @param n position to shift |
|
307 |
* |
|
308 |
* @return the value of *this right shifted by n positions. In other |
|
309 |
* words, the function of the set of frequencies represented by |
|
310 |
* *this is left-shifted in frequency by n positions. |
|
311 |
*/ |
|
312 |
SpectrumValue operator>> (int n) const; |
|
313 |
||
314 |
||
315 |
||
316 |
/** |
|
317 |
* Add the Right Hand Side of the operator to *this, component by component |
|
318 |
* |
|
319 |
* @param rhs the Right Hand Side |
|
320 |
* |
|
321 |
* @return a reference to *this |
|
322 |
*/ |
|
323 |
SpectrumValue& operator+= (const SpectrumValue& rhs); |
|
324 |
||
325 |
/** |
|
326 |
* Subtract the Right Hand Side of the operator from *this, component by component |
|
327 |
* |
|
328 |
* @param rhs the Right Hand Side |
|
329 |
* |
|
330 |
* @return a reference to *this |
|
331 |
*/ |
|
332 |
SpectrumValue& operator-= (const SpectrumValue& rhs); |
|
333 |
||
334 |
/** |
|
335 |
* Multiply *this by the Right Hand Side of the operator, component by component |
|
336 |
* |
|
337 |
* @param rhs the Right Hand Side |
|
338 |
* |
|
339 |
* @return a reference to *this |
|
340 |
*/ |
|
341 |
SpectrumValue& operator*= (const SpectrumValue& rhs); |
|
342 |
||
343 |
/** |
|
344 |
* Divide *this by the Right Hand Side of the operator, component by component |
|
345 |
* |
|
346 |
* @param rhs the Right Hand Side |
|
347 |
* |
|
348 |
* @return a reference to *this |
|
349 |
*/ |
|
350 |
SpectrumValue& operator/= (const SpectrumValue& rhs); |
|
351 |
||
352 |
/** |
|
353 |
* Add the value of the Right Hand Side of the operator to all |
|
354 |
* components of *this |
|
355 |
* |
|
356 |
* @param rhs the Right Hand Side |
|
357 |
* |
|
358 |
* @return a reference to *this |
|
359 |
*/ |
|
360 |
SpectrumValue& operator+= (double rhs); |
|
361 |
||
362 |
/** |
|
363 |
* Subtract the value of the Right Hand Side of the operator from all |
|
364 |
* components of *this |
|
365 |
* |
|
366 |
* @param rhs the Right Hand Side |
|
367 |
* |
|
368 |
* @return a reference to *this |
|
369 |
*/ |
|
370 |
SpectrumValue& operator-= (double rhs); |
|
371 |
||
372 |
/** |
|
373 |
* Multiply every component of *this by the value of the Right Hand |
|
374 |
* Side of the operator |
|
375 |
* |
|
376 |
* @param rhs the Right Hand Side |
|
377 |
* |
|
378 |
* @return a reference to *this |
|
379 |
*/ |
|
380 |
SpectrumValue& operator*= (double rhs); |
|
381 |
||
382 |
/** |
|
383 |
* Divide every component of *this by the value of the Right Hand |
|
384 |
* Side of the operator |
|
385 |
* |
|
386 |
* @param rhs the Right Hand Side |
|
387 |
* |
|
388 |
* @return a reference to *this |
|
389 |
*/ |
|
390 |
SpectrumValue& operator/= (double rhs); |
|
391 |
||
392 |
||
393 |
/** |
|
394 |
* Assign each component of *this to the value of the Right Hand |
|
395 |
* Side of the operator |
|
396 |
* |
|
397 |
* @param rhs |
|
398 |
* |
|
399 |
* @return |
|
400 |
*/ |
|
401 |
SpectrumValue& operator= (double rhs); |
|
402 |
||
403 |
||
404 |
||
405 |
/** |
|
406 |
* |
|
407 |
* @param x the operand |
|
408 |
* |
|
409 |
* @return the euclidean norm, i.e., the sum of the squares of all |
|
410 |
* the values in x |
|
411 |
*/ |
|
412 |
friend double Norm (const SpectrumValue& x); |
|
413 |
||
414 |
||
415 |
/** |
|
416 |
* |
|
417 |
* @param x the operand |
|
418 |
* |
|
419 |
* @return the sum of all |
|
420 |
* the values in x |
|
421 |
*/ |
|
422 |
friend double Sum (const SpectrumValue& x); |
|
423 |
||
424 |
||
425 |
/** |
|
426 |
* @param x the operand |
|
427 |
* |
|
428 |
* @return the product of all |
|
429 |
* the values in x |
|
430 |
*/ |
|
431 |
friend double Prod (const SpectrumValue& x); |
|
432 |
||
433 |
||
434 |
/** |
|
435 |
* |
|
436 |
* |
|
437 |
* @param base the base |
|
438 |
* @param exp the exponent |
|
439 |
* |
|
440 |
* @return each value in base raised to the exponent |
|
441 |
*/ |
|
442 |
friend SpectrumValue Pow (const SpectrumValue& base, double exp); |
|
443 |
||
444 |
||
445 |
/** |
|
446 |
* |
|
447 |
* |
|
448 |
* @param base the base |
|
449 |
* @param exp the exponent |
|
450 |
* |
|
451 |
* @return the value in base raised to each value in the exponent |
|
452 |
*/ |
|
453 |
friend SpectrumValue Pow (double base, const SpectrumValue& exp); |
|
454 |
||
455 |
/** |
|
456 |
* |
|
457 |
* |
|
458 |
* @param arg the argument |
|
459 |
* |
|
460 |
* @return the logarithm in base 10 of all values in the argument |
|
461 |
*/ |
|
462 |
friend SpectrumValue Log10 (const SpectrumValue& arg); |
|
463 |
||
464 |
||
465 |
/** |
|
466 |
* |
|
467 |
* |
|
468 |
* @param arg the argument |
|
469 |
* |
|
470 |
* @return the logarithm in base 2 of all values in the argument |
|
471 |
*/ |
|
472 |
friend SpectrumValue Log2 (const SpectrumValue& arg); |
|
473 |
||
474 |
/** |
|
475 |
* |
|
476 |
* |
|
477 |
* @param arg the argument |
|
478 |
* |
|
479 |
* @return the logarithm in base e of all values in the argument |
|
480 |
*/ |
|
481 |
friend SpectrumValue Log (const SpectrumValue& arg); |
|
482 |
||
483 |
/** |
|
484 |
* |
|
485 |
* @return a Ptr to a copy of this instance |
|
486 |
*/ |
|
487 |
Ptr<SpectrumValue> Copy () const; |
|
488 |
||
489 |
||
490 |
||
491 |
private: |
|
492 |
void Add (const SpectrumValue& x); |
|
493 |
void Add (double s); |
|
494 |
void Subtract (const SpectrumValue& x); |
|
495 |
void Subtract (double s); |
|
496 |
void Multiply (const SpectrumValue& x); |
|
497 |
void Multiply (double s); |
|
498 |
void Divide (const SpectrumValue& x); |
|
499 |
void Divide (double s); |
|
500 |
void ChangeSign (); |
|
501 |
void ShiftLeft (int n); |
|
502 |
void ShiftRight (int n); |
|
503 |
void Pow (double exp); |
|
504 |
void Exp (double base); |
|
505 |
void Log10 (); |
|
506 |
void Log2 (); |
|
507 |
void Log (); |
|
508 |
||
509 |
Ptr<const SpectrumModel> m_spectrumModel; |
|
510 |
||
511 |
||
512 |
/** |
|
513 |
* Set of values which implement the codomain of the functions in |
|
514 |
* the Function Space defined by SpectrumValue. There is no restriction |
|
515 |
* on what these values represent (a transmission power density, a |
|
516 |
* propagation loss, etc.). |
|
517 |
* |
|
518 |
*/ |
|
519 |
Values m_values; |
|
520 |
||
521 |
||
522 |
}; |
|
523 |
||
524 |
std::ostream& operator << (std::ostream& os, const SpectrumValue& pvf); |
|
525 |
||
6355
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
526 |
double Norm (const SpectrumValue& x); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
527 |
double Sum (const SpectrumValue& x); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
528 |
double Prod (const SpectrumValue& x); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
529 |
SpectrumValue Pow (const SpectrumValue& base, double exp); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
530 |
SpectrumValue Pow (double base, const SpectrumValue& exp); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
531 |
SpectrumValue Log10 (const SpectrumValue& arg); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
532 |
SpectrumValue Log2 (const SpectrumValue& arg); |
957e0c6ccb29
fixed spectrum code for python bindings as per Gustavo's suggestion
Nicola Baldo <nicola@baldo.biz>
parents:
6349
diff
changeset
|
533 |
SpectrumValue Log (const SpectrumValue& arg); |
6349 | 534 |
|
535 |
||
536 |
} // namespace ns3 |
|
537 |
||
538 |
||
539 |
#endif /* SPECTRUM_VALUE_H */ |