Code_TYMPAN  4.4.0
Industrial site acoustic simulation
spectre.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #undef min // Something defines a min macro on windows, which breaks std::min
17 
18 #include <algorithm>
19 
21 #include "spectre.h"
22 
23 #include <math.h>
24 #include "Tympan/core/exceptions.h"
25 
26 #include <iostream>
27 // using namespace std;
28 
29 // Minimal working frequency
30 double OSpectre::_fMin = 16;
31 
32 // Maximal working frequency
33 double OSpectre::_fMax = 16000;
34 
35 double OSpectreAbstract::_defaultValue = TY_SPECTRE_DEFAULT_VALUE;
36 
37 // Standardized central third-octave frequencies table in Hz.
38 const double OSpectre::_freqNorm[] = {
39  /* 0 */ 16.0, 20.0, 25.0,
40  /* 3 */ 31.5, 40.0, 50.0,
41  /* 6 */ 63.0, 80.0, 100.0,
42  /* 9 */ 125.0, 160.0, 200.0,
43  /* 12 */ 250.0, 315.0, 400.0,
44  /* 15 */ 500.0, 630.0, 800.0,
45  /* 18 */ 1000.0, 1250.0, 1600.0,
46  /* 21 */ 2000.0, 2500.0, 3150.0,
47  /* 24 */ 4000.0, 5000.0, 6300.0,
48  /* 27 */ 8000.0, 10000.0, 12500.0,
49  /* 30 */ 16000.0};
50 
51 std::map<double, int> OSpectre::_mapFreqIndice = setMapFreqIndice();
52 
54  : _valid(true), _type(SPECTRE_TYPE_ATT), _etat(SPECTRE_ETAT_DB), _form(SPECTRE_FORM_UNSHAPED)
55 {
56 }
57 
59  : _valid(true), _type(SPECTRE_TYPE_ATT), _etat(SPECTRE_ETAT_DB), _form(form)
60 {
61 }
62 
64  : _valid(isValid), _type(type), _etat(etat), _form(form)
65 {
66 }
67 
69 {
70  if (this != &other)
71  {
72  _valid = other._valid;
73  _type = other._type;
74  _etat = other._etat;
75  _form = other._form;
76  }
77  return *this;
78 }
79 
81 {
82  if (this != &other)
83  {
84  if (_valid != other._valid)
85  {
86  return false;
87  }
88  if (_type != other._type)
89  {
90  return false;
91  }
92  if (_etat != other._etat)
93  {
94  return false;
95  }
96  if (_form != other._form)
97  {
98  return false;
99  }
100  }
101  return true;
102 }
103 
105 {
106  return !operator==(other);
107 }
108 
109 OSpectreAbstract& OSpectreAbstract::operator+(const double& valeur) const
110 {
112  OSpectreAbstract& s = *sp;
113  s._etat = _etat;
114  s._type = _type; // Copy spectrum fingerprint
115  s._form = _form;
116  for (unsigned int i = 0; i < getNbValues(); i++)
117  {
118  s.getTabValReel()[i] = this->getTabValReel()[i] + valeur;
119  }
120  return s;
121 }
122 
124 {
126  s._etat = _etat;
127  s._type = _type; // Copy spectrum fingerprint
128  s._form = _form;
129  for (unsigned int i = 0; i < getNbValues(); i++)
130  {
131  s.getTabValReel()[i] = this->getTabValReel()[i] + spectre.getTabValReel()[i];
132  }
133  return s;
134 }
135 
137 {
139  s._etat = _etat;
140  s._type = _type; // Copy spectrum fingerprint
141  s._form = _form;
142  for (unsigned int i = 0; i < getNbValues(); i++)
143  {
144  s.getTabValReel()[i] = this->getTabValReel()[i] - spectre.getTabValReel()[i];
145  }
146  return s;
147 }
148 
150 {
152  s._etat = _etat;
153  s._type = _type; // Copy spectrum fingerprint
154  s._form = _form;
155  for (unsigned int i = 0; i < getNbValues(); i++)
156  {
157  s.getTabValReel()[i] = this->getTabValReel()[i] * spectre.getTabValReel()[i];
158  }
159  return s;
160 }
161 
162 OSpectreAbstract& OSpectreAbstract::operator*(const double& coefficient) const
163 {
165  OSpectreAbstract& s = *sp;
166  s._etat = _etat;
167  s._type = _type; // Copy spectrum fingerprint
168  s._form = _form;
169  for (unsigned int i = 0; i < getNbValues(); i++)
170  {
171  s.getTabValReel()[i] = this->getTabValReel()[i] * coefficient;
172  }
173  return s;
174 }
175 
177 {
178  OSpectreAbstract& tempoS1(this->toGPhy());
179  OSpectreAbstract& tempoS2(spectre.toGPhy());
180  OSpectreAbstract& s = tempoS1 + tempoS2;
181  // Copy spectrum fingerprint
182  s._type = _type;
183  // Spectrum is converted again in dB
184  return s.toDB();
185 }
186 
187 unsigned int OSpectreAbstract::getNbValues() const
188 {
189  unsigned int nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
190  switch (_form)
191  {
192  case SPECTRE_FORM_OCT:
193  nbFreq = TY_SPECTRE_OCT_NB_ELMT;
194  break;
195  default:
196  nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
197  break;
198  }
199  return nbFreq;
200 }
201 
202 void OSpectreAbstract::setDefaultValue(const double& valeur)
203 {
205 }
206 
207 void OSpectreAbstract::setDefaultValue(double module[], const unsigned int spectreNbElmt,
208  const double& valeur)
209 {
210  for (unsigned int i = 0; i < spectreNbElmt; i++)
211  {
212  module[i] = valeur;
213  }
214 }
215 
216 void OSpectreAbstract::getRangeValueReal(double* valeurs, const short& nbVal, const short& decalage)
217 {
218  for (short i = 0; i < nbVal; i++)
219  {
220  valeurs[i] = getTabValReel()[i + decalage];
221  }
222 }
223 
225 {
227 
228  s._etat = _etat;
229  s._type = _type; // Copy type
230  s._form = _form; // Copy form
231 
232  for (unsigned int i = 0; i < getNbValues(); i++)
233  {
234  s.getTabValReel()[i] = this->getTabValReel()[i] + spectre.getTabValReel()[i];
235  }
236  return s;
237 }
238 
239 OSpectreAbstract& OSpectreAbstract::sum(const double& value) const
240 {
242  OSpectreAbstract& s = *sp;
243  s.setDefaultValue(value);
244 
245  return sum(s);
246 }
247 
249 {
251 
252  // Copy spectrum fingerprint
253  s._etat = _etat;
254  s._type = _type;
255  for (unsigned int i = 0; i < getNbValues(); i++)
256  {
257  s.getTabValReel()[i] = this->getTabValReel()[i] * spectre.getTabValReel()[i];
258  }
259  return s;
260 }
261 
262 OSpectreAbstract& OSpectreAbstract::mult(const double& coefficient) const
263 {
265  OSpectreAbstract& s = *sp;
266 
267  // Copy spectrum fingerprint
268  s._etat = _etat;
269  s._type = _type;
270  s._form = _form;
271  for (unsigned int i = 0; i < getNbValues(); i++)
272  {
273  s.getTabValReel()[i] = this->getTabValReel()[i] * coefficient;
274  }
275  return s;
276 }
277 
279 {
281 
282  // Copy spectrum fingerprint
283  s._etat = _etat;
284  s._type = _type;
285  for (unsigned int i = 0; i < getNbValues(); i++)
286  {
287  if (spectre.getTabValReel()[i] == 0.0)
288  {
289  s.getTabValReel()[i] = 1E20;
290  s._valid = false;
291  break;
292  }
293 
294  s.getTabValReel()[i] = getTabValReel()[i] / spectre.getTabValReel()[i];
295  }
296  return s;
297 }
298 
299 OSpectreAbstract& OSpectreAbstract::div(const double& coefficient) const
300 {
302  OSpectreAbstract& s = *sp;
303 
304  // Copy spectrum fingerprint
305  s._etat = _etat;
306  s._type = _type;
307  if (coefficient == 0.0) // Division by zero
308  {
309  s._valid = false;
310  }
311  else
312  {
313  for (unsigned int i = 0; i < getNbValues(); i++)
314  {
315  s.getTabValReel()[i] = this->getTabValReel()[i] / coefficient;
316  }
317  }
318  return s;
319 }
320 
322 {
324 
325  // Copy spectrum fingerprint
326  s._etat = _etat;
327  s._type = _type;
328  for (unsigned int i = 0; i < getNbValues(); i++)
329  {
330  s.getTabValReel()[i] = this->getTabValReel()[i] - spectre.getTabValReel()[i];
331  }
332  return s;
333 }
334 
335 OSpectreAbstract& OSpectreAbstract::subst(const double& valeur) const
336 {
338  OSpectreAbstract& s = *sp;
339 
340  // Copy spectrum fingerprint
341  s._etat = _etat;
342  s._type = _type;
343  for (unsigned int i = 0; i < getNbValues(); i++)
344  {
345  s.getTabValReel()[i] = this->getTabValReel()[i] - valeur;
346  }
347  return s;
348 }
349 
350 OSpectreAbstract& OSpectreAbstract::invMult(const double& coefficient) const
351 {
353  OSpectreAbstract& s = *sp;
354 
355  // Copy spectrum fingerprint
356  s._etat = _etat;
357  s._type = _type;
358  for (unsigned int i = 0; i < getNbValues(); i++)
359  {
360  if (getTabValReel()[i] == 0.0)
361  {
362  s.getTabValReel()[i] = 1E20;
363  s._valid = false;
364  break;
365  }
366 
367  s.getTabValReel()[i] = coefficient / getTabValReel()[i];
368  }
369  return s;
370 }
371 
373 {
375  OSpectreAbstract& s = *sp;
376 
377  // Copy spectrum fingerprint
378  s._etat = _etat;
379  s._type = _type;
380  for (unsigned int i = 0; i < getNbValues(); i++)
381  {
382  if (getTabValReel()[i] == 0.0)
383  {
384  s.getTabValReel()[i] = 1E20;
385  s._valid = false;
386  break;
387  }
388 
389  s.getTabValReel()[i] = 1.0 / getTabValReel()[i];
390  }
391  return s;
392 }
393 
394 OSpectreAbstract& OSpectreAbstract::power(const double& puissance) const
395 {
397  OSpectreAbstract& s = *sp;
398 
399  // Copy spectrum fingerprint
400  s._etat = _etat;
401  s._type = _type;
402  for (unsigned int i = 0; i < getNbValues(); i++)
403  {
404  s.getTabValReel()[i] = pow(this->getTabValReel()[i], puissance);
405  }
406  return s;
407 }
408 
409 OSpectreAbstract& OSpectreAbstract::log(const double& base) const
410 {
412  OSpectreAbstract& s = *sp;
413 
414  // Copy spectrum fingerprint
415  s._etat = _etat;
416  s._type = _type;
417  double logBase = ::log(base);
418  for (unsigned int i = 0; i < getNbValues(); i++)
419  {
420  if (getTabValReel()[i] <= 0.0)
421  {
422  s.getTabValReel()[i] = 1E20;
423  s._valid = false;
424  break;
425  }
426 
427  s.getTabValReel()[i] = ::log(getTabValReel()[i]) / logBase;
428  }
429  return s;
430 }
431 
433 {
435  OSpectreAbstract& s = *sp;
436 
437  // Copy spectrum fingerprint
438  s._etat = _etat;
439  s._type = _type;
440  for (unsigned int i = 0; i < getNbValues(); i++)
441  {
442  if (getTabValReel()[i] < 0.0)
443  {
444  s.getTabValReel()[i] = 1E20;
445  s._valid = false;
446  break;
447  }
448 
449  s.getTabValReel()[i] = ::sqrt(getTabValReel()[i]);
450  }
451  return s;
452 }
453 
455 {
457  OSpectreAbstract& s = *sp;
458 
459  // Copy spectrum fingerprint
460  s._etat = _etat;
461  s._type = _type;
462  for (unsigned int i = 0; i < getNbValues(); i++)
463  {
464  s.getTabValReel()[i] = ::exp(coef * getTabValReel()[i]);
465  }
466  return s;
467 }
468 
470 {
472  OSpectreAbstract& s = *sp;
473  // Copy spectrum fingerprint
474  s._etat = _etat;
475  s._type = _type;
476  for (unsigned int i = 0; i < getNbValues(); i++)
477  {
478  s.getTabValReel()[i] = ::sin(this->getTabValReel()[i]);
479  }
480  return s;
481 }
482 
484 {
486  OSpectreAbstract& s = *sp;
487 
488  // Copy spectrum fingerprint
489  s._etat = _etat;
490  s._type = _type;
491  for (unsigned int i = 0; i < getNbValues(); i++)
492  {
493  s.getTabValReel()[i] = ::cos(this->getTabValReel()[i]);
494  }
495  return s;
496 }
497 
499 {
501  OSpectreAbstract& s = *sp;
502  // Copy spectrum fingerprint
503  s._etat = _etat;
504  s._type = _type;
505  for (unsigned int i = 0; i < getNbValues(); i++)
506  {
507  s.getTabValReel()[i] = fabs(getTabValReel()[i]);
508  }
509  return s;
510 }
511 
513 {
515  OSpectreAbstract& s = *sp;
516 
517  // Copy spectrum fingerprint
518  s._etat = _etat;
519  s._type = _type;
520  for (unsigned int i = 0; i < getNbValues(); i++)
521  {
522  s.getTabValReel()[i] = ::sqrt(this->getTabValReel()[i]);
523  }
524  return s;
525 }
526 
528 {
529  double result = 0.0;
530  for (unsigned int i = 0; i < getNbValues(); i++)
531  {
532  result = std::max(this->getTabValReel()[i], result);
533  }
534  return result;
535 }
536 
537 OSpectreAbstract& OSpectreAbstract::seuillage(const double& min, const double max)
538 {
540  OSpectreAbstract& s = *sp;
541 
542  // Copy spectrum fingerprint
543  s._etat = _etat;
544  s._type = _type;
545  // If min<=max, we return original spectrum
546  if (min >= max)
547  {
548  return *this;
549  }
550  for (unsigned int i = 0; i < getNbValues(); i++)
551  {
552  s.getTabValReel()[i] = getTabValReel()[i] <= min ? min : getTabValReel()[i];
553  s.getTabValReel()[i] = s.getTabValReel()[i] >= max ? max : s.getTabValReel()[i];
554  }
555  return s;
556 }
557 
559 {
560  double somme = 0;
561  for (unsigned int i = 0; i < getNbValues(); i++)
562  {
563  somme += getTabValReel()[i];
564  }
565  return somme;
566 }
567 
568 const double OSpectreAbstract::sigma() const
569 {
570  double somme = 0;
571  for (unsigned int i = 0; i < getNbValues(); i++)
572  {
573  somme += getTabValReel()[i];
574  }
575  return somme;
576 }
577 
579 {
581  OSpectreAbstract& s = *sp;
582 
583  // Copy spectrum fingerprint
584  s._etat = _etat;
585  s._type = _type;
586  s._valid = _valid;
587  s._form = _form;
588  for (unsigned int i = 0; i < getNbValues(); i++)
589  {
590  s.getTabValReel()[i] = std::round(getTabValReel()[i] * 100) / 100;
591  }
592  return s;
593 }
594 
596 {
598  OSpectreAbstract& s = *sp;
599 
600  // If spectrum is already in dB state, we just copy values
601  if (_etat == SPECTRE_ETAT_DB)
602  {
603  s = *this;
604  return s;
605  }
606  unsigned int i = 0;
607  s._type = _type; // Copy type
608  s._form = _form;
609  double coef = 1.0;
610  double epsilon = EPSILON_15;
611  switch (_type)
612  {
613  case SPECTRE_TYPE_LP:
614  coef = 4.0e-10;
615  break;
616  case SPECTRE_TYPE_LW:
617  coef = 1.0e-12;
618  epsilon = EPSILON_22;
619  break;
620  case SPECTRE_TYPE_ATT:
621  default:
622  coef = 1.0;
623  break;
624  }
625  double dBVal = 0.0;
626  for (i = 0; i < getNbValues(); i++)
627  {
628  // avoid -infinite result
629  double val = getTabValReel()[i];
630  if (val < epsilon)
631  {
632  val = epsilon;
633  }
634 
635  dBVal = 10.0 * log10((val) / coef);
636  s.getTabValReel()[i] = dBVal;
637  }
638  s._etat = SPECTRE_ETAT_DB; // Indicate explicitly dB state
639  return s;
640 }
641 
643 {
645  OSpectreAbstract& s = *sp;
646 
647  if (_etat == SPECTRE_ETAT_LIN) // If spectrum is already in LIN state, we just copy values
648  {
649  s = *this;
650  return s;
651  }
652  unsigned int i = 0;
653  double coef = 1.0;
654  s._type = _type; // Copy type
655  s._form = _form; // Copy form
656  switch (_type)
657  {
658  case SPECTRE_TYPE_LP:
659  coef = 4.0e-10;
660  break;
661  case SPECTRE_TYPE_LW:
662  coef = 1.0e-12;
663  break;
664  case SPECTRE_TYPE_ATT:
665  default:
666  coef = 1.0;
667  break;
668  }
669  double powVal = 0.0;
670  for (i = 0; i < getNbValues(); i++)
671  {
672  powVal = pow(10.0, this->getTabValReel()[i] / 10.0) * coef;
673  s.getTabValReel()[i] = powVal;
674  }
675  s._etat = SPECTRE_ETAT_LIN; // Indicate explicitly 'Physical Measure' state
676  return s;
677 }
678 
680 {
681  OSpectreAbstract& s = this->toDB();
682  double valeurGlob = 0.0;
683  for (unsigned int i = 0; i < getNbValues(); i++)
684  {
685  valeurGlob = valeurGlob + pow(10, (s.getTabValReel()[i] / 10));
686  }
687  valeurGlob = 10 * log10(valeurGlob);
688  return valeurGlob;
689 }
690 
692 {
693 
694  double ret = -1.0;
695  if (getNbValues() == TY_SPECTRE_DEFAULT_NB_ELMT && this->getForm() == SPECTRE_FORM_TIERS)
696  {
697  OSpectreAbstract& s(this->toDB() + OSpectre::pondA());
698  ret = s.valGlobDBLin();
699  }
700  else
701  {
702  OSpectreAbstract& s1 = this->toDB();
704  ret = s.valGlobDBLin();
705  }
706  return ret;
707 }
708 
710 {
711  // The return spectrum must be of type OSpectre
713  OSpectreAbstract& s = *sp;
714 
715  if (_form == SPECTRE_FORM_TIERS) // If object is already in third-octave
716  {
717  s = *this;
718  return s;
719  }
720  else if (_form != SPECTRE_FORM_OCT) // If spectrum is not in octave
721  {
722  s._valid = false;
723  return s;
724  }
725  s._type = _type;
727  {
728  const OSpectreAbstract& travail = *this;
729  short indice = 2;
730  short nbOctValue = 9;
731  double valeur = 0.0;
732  for (short i = 0; i < nbOctValue; i++, indice += 3)
733  {
734  valeur = travail.getTabValReel()[i];
735  s.getTabValReel()[indice] = valeur;
736  s.getTabValReel()[indice + 1] = valeur;
737  s.getTabValReel()[indice + 2] = valeur;
738  }
739  s.getTabValReel()[0] = s.getTabValReel()[2];
740  s.getTabValReel()[1] = s.getTabValReel()[2];
741  s.getTabValReel()[29] = s.getTabValReel()[28];
742  s.getTabValReel()[30] = s.getTabValReel()[28];
743  s._etat = SPECTRE_ETAT_DB;
744  }
745  else
746  {
747  OSpectreAbstract& travail = this->toGPhy();
748  short indice = 2;
749  short nbOctValue = 9;
750  double valeur = 0.0;
751  double coef = 3.0;
752  if (_type == SPECTRE_TYPE_ATT)
753  {
754  coef = 1.0;
755  }
756  for (short i = 0; i < nbOctValue; i++, indice += 3)
757  {
758  valeur = travail.getTabValReel()[i] / coef;
759  s.getTabValReel()[indice] = valeur;
760  s.getTabValReel()[indice + 1] = valeur;
761  s.getTabValReel()[indice + 2] = valeur;
762  }
763  if (_type == SPECTRE_TYPE_ATT)
764  {
765  s.getTabValReel()[0] = 1;
766  s.getTabValReel()[1] = 1;
767  s.getTabValReel()[29] = 1;
768  s.getTabValReel()[30] = 1;
769  }
770  else if (_type == SPECTRE_TYPE_LP)
771  {
772  s.getTabValReel()[0] = 1.0E-15;
773  s.getTabValReel()[1] = 1.0E-15;
774  s.getTabValReel()[29] = 1.0E-15;
775  s.getTabValReel()[30] = 1.0E-15;
776  }
777  s = s.toDB();
778  }
779  s._form = SPECTRE_FORM_TIERS; // Indicate explicitly thrid-octave form
780  return s;
781 }
782 
784 {
786  if (_form == SPECTRE_FORM_OCT) // If spectrum already is in octave
787  {
788  s = *this;
789  return s;
790  }
791  else if (_form != SPECTRE_FORM_TIERS) // If spectrum is not in thrid-octave
792  {
793  s._valid = false;
794  return s;
795  }
796  s._etat = SPECTRE_ETAT_LIN; // s is in lin state too at this moment
797  s._type = _type;
799  {
800  const OSpectreAbstract& travail = *this;
801  unsigned int indiceDepart = 2;
802  unsigned int indice = 0;
803  double valeur = 0.0;
804  for (unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
805  {
806  valeur = (travail.getTabValReel()[i] + travail.getTabValReel()[i + 1] +
807  travail.getTabValReel()[i + 2]) /
808  3; // Absorptions mean
809  s.getTabValReel()[indice] = valeur;
810  }
811  s._etat = SPECTRE_ETAT_DB;
812  }
813  else
814  {
815  OSpectreAbstract& travail = this->toGPhy();
816  unsigned int indiceDepart = 2;
817  unsigned int indice = 0;
818  double valeur = 0.0;
819  double coef = 1.0;
820  if (_type == SPECTRE_TYPE_ATT)
821  {
822  coef = 3.0;
823  }
824  for (unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
825  {
826  valeur = (travail.getTabValReel()[i] + travail.getTabValReel()[i + 1] +
827  travail.getTabValReel()[i + 2]) /
828  coef;
829  s.getTabValReel()[indice] = valeur;
830  }
831  s = s.toDB();
832  }
833  s._form = SPECTRE_FORM_OCT; // Indicate explicitly octave form
834  return s;
835 }
836 
838 {
839  std::cout << "Spectrum values: ";
840  for (unsigned int i = 0; i < getNbValues(); i++)
841  {
842  std::cout << getTabValReel()[i] << " ";
843  }
844  std::cout << std::endl;
845 }
846 
848 {
850  return *s;
851 }
852 
854 {
855  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
856  {
857  _module[i] = _defaultValue;
858  }
859 }
860 
862 {
863  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
864  {
865  _module[i] = defaultValue;
866  }
867 }
868 
869 OSpectre::OSpectre(const double* valeurs, unsigned nbVal, unsigned decalage)
871 {
872  unsigned int i = 0;
873  // First init values
874  for (i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
875  {
876  _module[i] = _defaultValue;
877  }
878  unsigned int maxInd = std::min(nbVal + decalage, TY_SPECTRE_DEFAULT_NB_ELMT);
879  for (i = decalage; i < maxInd; i++)
880  {
881  _module[i] = valeurs[i - decalage];
882  }
883 }
884 
886 {
887  *this = other;
888 }
889 
891 {
892  *this = other;
893 }
894 
896 
898 {
899  if (this != &other)
900  {
902  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
903  {
904  _module[i] = other._module[i];
905  }
906  }
907  return *this;
908 }
909 
911 {
912  if (this != &other)
913  {
914  const OSpectre* sp;
915  // If other of type OSpectre just cast it
916  sp = dynamic_cast<const OSpectre*>(&other);
917  // If not, try to cast to an OSpectreOctave and convert to third-octave band
918  if (sp == nullptr)
919  {
920  const OSpectreOctave* spo = dynamic_cast<const OSpectreOctave*>(&other);
921  if (spo != nullptr)
922  {
923  OSpectre s = spo->toTOct();
924  sp = &s;
925  }
926  // If neither conversions are possible raise error
927  else
928  {
929  std::ostringstream oss;
930  oss << "Impossible to convert from " << other.getForm() << " to OSpectre";
931  assert(false && oss.str().c_str());
932  }
933  }
934  *this = *sp;
935  }
936  return *this;
937 }
938 
939 bool OSpectre::operator==(const OSpectre& other) const
940 {
941  if (this != &other)
942  {
943  if ((OSpectreAbstract::operator!=(other)))
944  {
945  return false;
946  }
947  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
948  {
949  if (_module[i] != other._module[i])
950  {
951  return false;
952  }
953  }
954  }
955  return true;
956 }
957 
958 bool OSpectre::operator!=(const OSpectre& other) const
959 {
960  return !operator==(other);
961 }
962 
964 {
965  return new OSpectre();
966 }
967 
968 void OSpectre::setValue(const double& freq, const double& reel /*=0.0*/)
969 {
970  int indice = _mapFreqIndice[freq];
971  _module[indice] = reel;
972 }
973 
974 double OSpectre::getValueReal(double freq)
975 {
976  int indice = _mapFreqIndice[freq];
977  return _module[indice];
978 }
979 
980 // Static functions
981 
982 std::map<double, int> OSpectre::setMapFreqIndice()
983 {
984  std::map<double, int> mapFI;
985  double value = 0.0;
986  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
987  {
988  value = _freqNorm[i];
989  mapFI[value] = i;
990  }
991  return mapFI;
992 }
993 
995 {
996  OTabFreq tabFreqExact;
997  for (int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
998  {
999  tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), i - 18));
1000  }
1001  return tabFreqExact;
1002 }
1003 
1005 {
1006  OSpectre tabFreqExact;
1007  for (int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1008  {
1009  tabFreqExact._module[i] = 1000.0 * pow(pow(10.0, 0.1), i - 18);
1010  }
1011  return tabFreqExact;
1012 }
1013 
1015 {
1016  OSpectre s;
1017  OTabFreq tabFreqExact = getTabFreqExact();
1018  long v1 = 12200 * 12200;
1019  double v2 = 20.6 * 20.6;
1020  double v3 = 107.7 * 107.7;
1021  double v4 = 737.9 * 737.9;
1022  double f2 = 1000.0 * 1000.0; // squared frequency
1023  double v1000 =
1024  (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::sqrt((f2 + v3) * (f2 + v4))); // reference at 1000 Hz
1025  double valeur = 0.0;
1026  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1027  {
1028  f2 = tabFreqExact[i] * tabFreqExact[i];
1029  valeur = (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::sqrt((f2 + v3) * (f2 + v4)));
1030  valeur = 20 * log10(valeur / v1000);
1031  s._module[i] = valeur;
1032  }
1033  return s;
1034 }
1035 
1037 {
1038  OSpectre s;
1039  OTabFreq tabFreqExact = getTabFreqExact();
1040  long v1 = 12200 * 12200;
1041  double v2 = 20.6 * 20.6;
1042  double v3 = 158.5 * 158.5;
1043  double f = 1000.0;
1044  double f2 = f * f; // squared frequency
1045  double v1000 = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::sqrt(f2 + v3)); // reference at 1000 Hz
1046  double valeur = 0.0;
1047  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1048  {
1049  f = tabFreqExact[i];
1050  f2 = f * f;
1051  valeur = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::sqrt(f2 + v3));
1052  valeur = 20 * log10(valeur / v1000);
1053  s._module[i] = valeur;
1054  }
1055  return s;
1056 }
1057 
1059 {
1060  OSpectre s;
1061  OTabFreq tabFreqExact = getTabFreqExact();
1062  long v1 = 12200 * 12200;
1063  double v2 = 20.6 * 20.6;
1064  double f2 = 1000.0 * 1000.0; // squared frequency
1065  double v1000 = (v1 * f2) / ((f2 + v1) * (f2 + v2)); // reference at 1000 Hz
1066  double valeur = 0.0;
1067  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1068  {
1069  f2 = tabFreqExact[i] * tabFreqExact[i];
1070  valeur = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1071  valeur = 20 * log10(valeur / v1000);
1072  s._module[i] = valeur;
1073  }
1074  return s;
1075 }
1076 
1078 {
1079  OSpectre s;
1080  // Copy spectrum fingerprint
1081  s._etat = SPECTRE_ETAT_LIN;
1082  s._type = SPECTRE_TYPE_AUTRE;
1083  OTabFreq tabFreqExact = getTabFreqExact();
1084  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1085  {
1086  s._module[i] = c / tabFreqExact[i];
1087  }
1088  return s;
1089 }
1090 
1092 {
1093  if ((_etat == SPECTRE_ETAT_LIN) || (_form == SPECTRE_FORM_OCT))
1094  {
1095  return false;
1096  }
1097  const double seuil = 315;
1098  double a = NAN, b = NAN, c = NAN, d = NAN, e = NAN, ab = NAN, de = NAN, diffG = NAN, diffD = NAN,
1099  freq = NAN, tolerence = NAN;
1100  a = _module[0];
1101  b = _module[1];
1102  c = _module[2];
1103  d = _module[3];
1104  e = _module[4];
1105  tolerence = 10.0;
1106  for (unsigned int i = 5; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1107  {
1108  ab = 10 * ::log10(((::pow(10, a / 10.0) + ::pow(10, b / 10.0)) / 2.0));
1109  de = 10 * ::log10(((::pow(10, d / 10.0) + ::pow(10, e / 10.0)) / 2.0));
1110  diffG = c - ab;
1111  diffD = c - de;
1112  freq = OSpectre::_freqNorm[i - 3];
1113  if (freq > seuil)
1114  {
1115  tolerence = 5.0;
1116  }
1117  if ((diffG > tolerence) && (diffD > tolerence))
1118  {
1119  return true;
1120  }
1121  a = b;
1122  b = c;
1123  c = d;
1124  d = e;
1125  e = _module[i];
1126  }
1127  return false;
1128 }
1129 
1131 {
1132  OSpectre s(valInit);
1133  s._etat = SPECTRE_ETAT_LIN;
1134  return s;
1135 }
1136 
1138 {
1139  OSpectre s;
1140  s._form = SPECTRE_FORM_OCT;
1141  return s;
1143 
1144 ::std::ostream& operator<<(::std::ostream& os, const OSpectre& s)
1145 {
1146  os << "Spectrum["
1147  << "type=" << s.getType() << ", state=" << s.getEtat() << "]" << std::endl;
1148  os << " (";
1149  for (unsigned i = 0; i < s.getNbValues(); ++i)
1150  {
1151  os << s.getTabValReel()[i] << ", ";
1152  }
1153  os << ")" << std::endl;
1154  return os;
1155 }
1156 
1157 /* OSpectreComplex ************************************************************/
1158 
1160 {
1161  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1162  {
1163  _phase[i] = 0.0;
1164  }
1165 }
1166 
1167 OSpectreComplex::OSpectreComplex(const TYComplex& defaultValue) : OSpectre(defaultValue.real())
1168 {
1169  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1170  {
1171  _phase[i] = defaultValue.imag();
1172  }
1173 }
1174 
1176 {
1177  *this = other;
1178 }
1179 
1181 {
1182  OSpectre::operator=(other);
1183  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1184  {
1185  _phase[i] = 0.0;
1186  }
1187 }
1188 
1189 OSpectreComplex::OSpectreComplex(const OSpectre& spectre1, const OSpectre& spectre2)
1190 {
1191  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1192  {
1193  _module[i] = (spectre1.getTabValReel())[i];
1194  _phase[i] = (spectre2.getTabValReel())[i];
1195  }
1196 }
1197 
1199 
1201 {
1202  if (this != &other)
1203  {
1204  OSpectre::operator=(other);
1205 
1206  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1207  {
1208  _phase[i] = other._phase[i];
1209  }
1210  }
1211  return *this;
1212 }
1213 
1215 {
1216  if (this != &other)
1217  {
1218  const OSpectreComplex* sc;
1219  sc = dynamic_cast<const OSpectreComplex*>(&other);
1220 
1221  // If other of type OSpectreComplex just cast it
1222  if (sc != nullptr)
1223  {
1224  *this = *sc;
1225  }
1226  // If not, convert from an OSpectre and init phase values to zero
1227  else
1228  {
1229  OSpectre::operator=(other);
1230  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1231  {
1232  _phase[i] = 0;
1233  }
1234  }
1235  }
1236  return *this;
1237 }
1238 
1240 {
1241  if (this != &other)
1242  {
1243  if ((OSpectre::operator!=(other)))
1244  {
1245  return false;
1246  }
1247 
1248  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1249  if (_phase[i] != other._phase[i])
1250  {
1251  return false;
1252  }
1253  }
1254  return true;
1255 }
1256 
1258 {
1259  return !operator==(other);
1260 }
1261 
1263 {
1265  // Copy spectrum fingerprint
1266  s._etat = _etat;
1267  s._type = _type;
1268  // A complex number is defined as z = a + ib
1269  std::complex<double> z1; // This is the original one
1270  std::complex<double> z2; // This is the one we add
1271  std::complex<double> z3; // This is the returned complex number i.e. the result
1272  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1273  {
1274  z1 = std::polar(_module[i], _phase[i]);
1275  z2 = std::polar(spectre._module[i], spectre._phase[i]);
1276  z3 = z1 + z2;
1277 
1278  s._module[i] = std::abs(z3);
1279  s._phase[i] = std::arg(z3);
1280  }
1281  return s;
1282 }
1283 
1285 {
1286  // Product of two complex in modulus/phase
1287  // = modulus product and phases sum
1289  // Copy spectrum fingerprint
1290  s._etat = _etat;
1291  s._type = _type;
1292  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1293  {
1294  s._module[i] = _module[i] * spectre._module[i];
1295  s._phase[i] = _phase[i] + spectre._phase[i];
1296  }
1297  return s;
1298 }
1299 
1301 {
1302  // Product of two complex in modulus/phase
1303  // = modulus product and phases sum
1305  // Copy spectrum fingerprint
1306  s._etat = _etat;
1307  s._type = _type;
1308  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1309  {
1310  s._module[i] = _module[i] * (spectre.getTabValReel())[i];
1311  s._phase[i] = _phase[i];
1312  }
1313  return s;
1314 }
1315 
1316 OSpectreComplex OSpectreComplex::operator*(const double& coefficient) const
1317 {
1319  // Copy spectrum fingerprint
1320  s._etat = _etat;
1321  s._type = _type;
1322  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1323  {
1324  s._module[i] = _module[i] * coefficient;
1325  s._phase[i] = _phase[i];
1326  }
1327  return s;
1328 }
1329 
1331 {
1332  // Quotient of two complex in modulus/phase
1333  // = modulus quotient and phases difference
1335  // Copy spectrum fingerprint
1336  s._etat = _etat;
1337  s._type = _type;
1338  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1339  {
1340  s._module[i] = _module[i] / spectre._module[i];
1341  s._phase[i] = _phase[i] - spectre._phase[i];
1342  }
1343  return s;
1344 }
1345 
1346 void OSpectreComplex::setValue(const double& freq, const double& reel, const double& imag)
1347 {
1348  int indice = _mapFreqIndice[freq];
1349  _module[indice] = reel;
1350  _phase[indice] = imag;
1351 }
1352 
1353 void OSpectreComplex::setValue(const double& freq, const TYComplex& cplx)
1354 {
1355  setValue(freq, cplx.real(), cplx.imag());
1356 }
1357 
1358 double OSpectreComplex::getValueImag(double freq, bool* pValid)
1359 {
1360  int indice = _mapFreqIndice[freq];
1361  return _phase[indice];
1362 }
1363 
1365 {
1366  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1367  {
1368  _phase[i] = spectre.getTabValReel()[i];
1369  }
1370 }
1371 
1372 void OSpectreComplex::setPhase(const double& valeur)
1373 {
1374  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1375  {
1376  _phase[i] = valeur;
1377  }
1378 }
1379 
1381 {
1383  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1384  {
1385  s.getTabValReel()[i] = _phase[i];
1386  }
1387  return s;
1388 }
1389 
1391 {
1393  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1394  {
1395  s.getTabValReel()[i] = _module[i];
1396  }
1397  return s;
1398 }
1399 
1401 {
1403  double module = NAN, phase = NAN, reel = NAN, imag = NAN;
1404  // Copy spectrum fingerprint
1405  s._etat = _etat;
1406  s._type = _type;
1407  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1408  {
1409  reel = this->_module[i];
1410  imag = this->_phase[i];
1411  module = ::sqrt(reel * reel + imag * imag);
1412  phase = atan2(imag, reel);
1413  s._module[i] = module;
1414  s._phase[i] = phase;
1415  }
1416  return s;
1417 }
1418 
1420 {
1422  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1423  {
1424  s._phase[i] = 0.0;
1425  }
1426  return s;
1427 }
1428 
1429 /* OSpectreOctave ************************************************************/
1430 // Standardized central octave frequencies table in Hz.
1431 const double OSpectreOctave::_freqNorm[] = {31.5, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0};
1432 
1433 const double OSpectreOctave::_AWeighting[] = {-39.4, -26.2, -16.1, -8.6, -3.2, 0.0, 1.2, 1.0, -1.1};
1434 
1435 std::map<double, int> OSpectreOctave::_mapFreqIndice = setMapFreqIndice();
1436 
1438 {
1439  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1440  {
1441  _module[i] = _defaultValue;
1442  }
1443 }
1444 
1446  : OSpectreAbstract(isValid, type, etat, SPECTRE_FORM_OCT)
1447 {
1448  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1449  {
1450  _module[i] = _defaultValue;
1451  }
1452 }
1453 
1455 {
1456  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1457  {
1458  _module[i] = defaultValue;
1459  }
1460 }
1461 
1462 OSpectreOctave::OSpectreOctave(const double* valeurs, unsigned nbVal, unsigned decalage)
1464 {
1465  unsigned int i;
1466  // D'abord on initialise les valeurs
1467  for (i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1468  {
1469  _module[i] = _defaultValue;
1470  }
1471  unsigned int maxInd = std::min(nbVal + decalage, TY_SPECTRE_OCT_NB_ELMT);
1472  for (i = decalage; i < maxInd; i++)
1473  {
1474  _module[i] = valeurs[i - decalage];
1475  }
1476 }
1477 
1479 {
1480  *this = other;
1481 }
1482 
1484 {
1485  *this = other;
1486 }
1487 
1489 {
1490  OSpectreAbstract& s = other.toOct();
1491  _valid = s.isValid();
1492  _type = s.getType();
1493  _etat = s.getEtat();
1494  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1495  {
1496  _module[i] = s.getTabValReel()[i];
1497  }
1498 }
1499 
1501 
1503 {
1504  if (this != &other)
1505  {
1507  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1508  {
1509  _module[i] = other._module[i];
1510  }
1511  }
1512  return *this;
1513 }
1514 
1516 {
1517  if (this != &other)
1518  {
1519 
1520  const OSpectreOctave* so;
1521  // If other if of octave form then build OSpectreOctave from values
1522  if (other.getForm() == SPECTRE_FORM_OCT)
1523  {
1524  so = dynamic_cast<const OSpectreOctave*>(&other);
1525  }
1526  else if (other.getForm() == SPECTRE_FORM_TIERS)
1527  // If other is third-octave form then convert other to octave before building from values
1528  {
1529  OSpectreAbstract& otherOctave = other.toOct();
1530  // In this case toOct() returns an OSPectre object so we need to convert it
1531  const OSpectre* s = dynamic_cast<const OSpectre*>(&otherOctave);
1532  const OSpectreOctave so1{*s};
1533  so = &so1;
1534  }
1535  else
1536  {
1537  std::ostringstream oss;
1538  oss << "Impossible to convert from " << other.getForm() << " to OSpectreOctave";
1539  assert(false && oss.str().c_str());
1540  }
1541  if (so != nullptr)
1542  {
1543  *this = *so;
1544  }
1545  else
1546  {
1547  assert(false && "Invalid OSpectreOctave object during conversion");
1548  }
1549  }
1550  return *this;
1551 }
1552 
1554 {
1555  if (this != &other)
1556  {
1557  if ((OSpectreAbstract::operator!=(other)))
1558  {
1559  return false;
1560  }
1561  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1562  {
1563  if (_module[i] != other._module[i])
1564  {
1565  return false;
1566  }
1567  }
1568  }
1569  return true;
1570 }
1571 
1573 {
1574  return !operator==(other);
1575 }
1576 
1578 {
1579  return new OSpectreOctave();
1580 }
1581 
1582 void OSpectreOctave::setValue(const double& freq, const double& reel /*=0.0*/)
1583 {
1584  int indice = _mapFreqIndice[freq];
1585  _module[indice] = reel;
1586 }
1587 
1588 // Static functions
1589 
1591 {
1592  OTabFreq tabFreqExact;
1593  short indice = 2;
1594  for (int i = 0; i < (int)TY_SPECTRE_OCT_NB_ELMT; i++, indice += 3)
1595  {
1596  tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), indice + 1 - 18));
1597  }
1598  return tabFreqExact;
1599 }
1600 
1602 {
1603  return OSpectreOctave{_AWeighting, 9, 0};
1604 }
1605 
1607 {
1608  OSpectreOctave s;
1609  // Copy spectrum fingerprint
1610  s._etat = SPECTRE_ETAT_LIN;
1611  s._type = SPECTRE_TYPE_AUTRE;
1612  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1613  {
1614  s._module[i] = c / _freqNorm[i];
1615  }
1616  return s;
1617 }
1618 
1619 std::map<double, int> OSpectreOctave::setMapFreqIndice()
1620 {
1621  std::map<double, int> mapFI;
1622  double value = 0.0;
1623  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1624  {
1625  value = _freqNorm[i];
1626  mapFI[value] = i;
1627  }
1628  return mapFI;
1629 }
1630 
1632 {
1633  OSpectreOctave s(valInit);
1634  s._etat = SPECTRE_ETAT_LIN;
1635  return s;
1636 }
NxReal s
Definition: NxVec3.cpp:317
NxReal c
Definition: NxVec3.cpp:317
#define min(a, b)
Store acoustic power values for different frequencies.
Definition: spectre.h:83
OSpectreAbstract & power(const double &puissance) const
Return a spectrum as this spectrum raised to a double power.
Definition: spectre.cpp:394
OSpectreAbstract & sum(const OSpectreAbstract &spectre) const
Arithmetic sum of two spectrums in one-third Octave.
Definition: spectre.cpp:224
OSpectreAbstract & subst(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
Definition: spectre.cpp:321
virtual bool operator==(const OSpectreAbstract &other) const
operator==
Definition: spectre.cpp:80
bool _valid
Spectrum validity.
Definition: spectre.h:313
double valMax()
Return the maximum value of a spectrum.
Definition: spectre.cpp:527
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
Definition: spectre.cpp:691
static double _defaultValue
Default value for the spectrum.
Definition: spectre.h:308
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:642
virtual double * getTabValReel()=0
Get the array of real values - Pure virtual method.
OSpectreAbstract & seuillage(const double &min=-200.0, const double max=200.0)
Limit the spectrum values (min and max)
Definition: spectre.cpp:537
OSpectreAbstract & exp(const double coef=1.0)
Compute e^(coef * spectre) of this spectrum.
Definition: spectre.cpp:454
OSpectreAbstract & operator+(const double &valeur) const
Add a constant value to all the spectrum.
Definition: spectre.cpp:109
OSpectreAbstract & log(const double &base=10.0) const
Compute the log base n of this spectrum (n=10 by default).
Definition: spectre.cpp:409
unsigned int getNbValues() const
Number of values in the spectrum.
Definition: spectre.cpp:187
OSpectreAbstract & invMult(const double &coefficient=1.0) const
Division of a double constant by this spectrum.
Definition: spectre.cpp:350
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
Definition: spectre.cpp:679
OSpectreAbstract & operator*(const OSpectreAbstract &spectre) const
Multiplication by a Spectre spectrum.
Definition: spectre.cpp:149
OSpectreAbstract()
Methods.
Definition: spectre.cpp:53
double sigma()
Sum the values of the spectrum.
Definition: spectre.cpp:558
virtual void printme() const
Print the spectrum.
Definition: spectre.cpp:837
OSpectreAbstract & abs() const
Return the absolute value of this spectrum.
Definition: spectre.cpp:498
TYSpectreForm _form
Representation of the spectrum: one-third Octave, Octave, constant delta f, unstructured.
Definition: spectre.h:322
OSpectreAbstract & toTOct() const
Converts to one-third Octave.
Definition: spectre.cpp:709
OSpectreAbstract & div(const OSpectreAbstract &spectre) const
Division of two spectrums.
Definition: spectre.cpp:278
OSpectreAbstract & sqrt() const
Return the root square of a spectrum.
Definition: spectre.cpp:512
OSpectreAbstract & racine() const
Compute the root square of this spectrum.
Definition: spectre.cpp:432
OSpectreAbstract & sin() const
Compute the sin of this spectrum.
Definition: spectre.cpp:469
void getRangeValueReal(double *valeurs, const short &nbVal, const short &decalage)
Definition: spectre.cpp:216
virtual OSpectreAbstract & operator=(const OSpectreAbstract &other)
operator=
Definition: spectre.cpp:68
virtual bool operator!=(const OSpectreAbstract &other) const
operator !=
Definition: spectre.cpp:104
void setDefaultValue(const double &valeur=TY_SPECTRE_DEFAULT_VALUE)
Definition: spectre.cpp:202
TYSpectreForm getForm() const
Get the spectrum form.
Definition: spectre.h:175
TYSpectreEtat _etat
Spectrum state (physical quantity or dB).
Definition: spectre.h:319
static OSpectreAbstract & makeOctSpect()
Make a spectrum in Octave.
Definition: spectre.cpp:847
OSpectreAbstract & operator-(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
Definition: spectre.cpp:136
OSpectreAbstract & cos() const
Compute the cos of this spectrum.
Definition: spectre.cpp:483
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:595
OSpectreAbstract & toOct() const
Converts to Octave.
Definition: spectre.cpp:783
OSpectreAbstract & round()
Definition: spectre.cpp:578
OSpectreAbstract & mult(const OSpectreAbstract &spectre) const
Multiplication of two spectrums.
Definition: spectre.cpp:248
TYSpectreType _type
Spectrum type.
Definition: spectre.h:316
OSpectreAbstract & sumdB(const OSpectreAbstract &spectre) const
Energetic sum of two spectrums.
Definition: spectre.cpp:176
virtual OSpectreAbstract * getConcreteInstance() const =0
Return an instance of a concrete class of the same type as current.
OSpectreAbstract & inv() const
Division of one by this spectrum.
Definition: spectre.cpp:372
OSpectreComplex & operator=(const OSpectreComplex &other)
operators
Definition: spectre.cpp:1200
void setPhase(const OSpectre &spectre)
Definition: spectre.cpp:1364
bool operator!=(const OSpectreComplex &other) const
Definition: spectre.cpp:1257
double getValueImag(double freq, bool *pValid=0)
Definition: spectre.cpp:1358
void setValue(const double &freq, const double &reel, const double &imag=0.0)
Definition: spectre.cpp:1346
double _phase[TY_SPECTRE_DEFAULT_NB_ELMT]
Array of the imaginary numbers (phase)
Definition: spectre.h:578
OSpectre getModule() const
Definition: spectre.cpp:1390
OSpectreComplex toModulePhase() const
Conversion to module/phase.
Definition: spectre.cpp:1400
OSpectre getPhase() const
Definition: spectre.cpp:1380
static OSpectreComplex getCplxSpectre(const double &valInit=1.0E-20)
Build a OSpectreComplex complex spectrum.
Definition: spectre.cpp:1419
OSpectreComplex operator+(const OSpectreComplex &spectre) const
Definition: spectre.cpp:1262
bool operator==(const OSpectreComplex &other) const
Definition: spectre.cpp:1239
OSpectreComplex operator/(const OSpectreComplex &spectre) const
Divide a complex spectrum by another one.
Definition: spectre.cpp:1330
OSpectreComplex operator*(const OSpectreComplex &spectre) const
Product of two complex spectrums (module/phase)
Definition: spectre.cpp:1284
virtual ~OSpectreComplex()
Definition: spectre.cpp:1198
virtual ~OSpectreOctave()
Definition: spectre.cpp:1500
OSpectreAbstract * getConcreteInstance() const override
Return an instance of a concrete class of the same type as current.
Definition: spectre.cpp:1577
static OSpectreOctave getLambda(const double &c)
Definition: spectre.cpp:1606
static OSpectreOctave pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1601
double _module[TY_SPECTRE_OCT_NB_ELMT]
Real values array for module.
Definition: spectre.h:678
static const double _AWeighting[TY_SPECTRE_OCT_NB_ELMT]
A weighting for ponderation A computation.
Definition: spectre.h:673
static OSpectreOctave getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
Definition: spectre.cpp:1631
bool operator!=(const OSpectreOctave &other) const
Definition: spectre.cpp:1572
void setValue(const double &freq, const double &reel=0.0)
Definition: spectre.cpp:1582
bool operator==(const OSpectreOctave &other) const
Definition: spectre.cpp:1553
static OTabFreq getTabFreqExact()
Definition: spectre.cpp:1590
static const double _freqNorm[TY_SPECTRE_OCT_NB_ELMT]
Array of center frequencies (Hz) normalized in one-third Octave.
Definition: spectre.h:670
static std::map< double, int > setMapFreqIndice()
Build frequency/index map.
Definition: spectre.cpp:1619
static std::map< double, int > _mapFreqIndice
Mapping between frequency and array index.
Definition: spectre.h:667
OSpectreOctave & operator=(const OSpectreOctave &other)
operators
Definition: spectre.cpp:1502
static OSpectre getOSpectreFreqExact()
Return the spectrum of the exact frequencies.
Definition: spectre.cpp:1004
virtual bool operator!=(const OSpectre &other) const
operator !=
Definition: spectre.cpp:958
OSpectre & operator=(const OSpectre &other)
operator=
Definition: spectre.cpp:897
static OSpectre getLambda(const double &c)
Definition: spectre.cpp:1077
static std::map< double, int > _mapFreqIndice
Mapping between frequency and array index.
Definition: spectre.h:465
static std::map< double, int > setMapFreqIndice()
Construction du tableau frequence/indice.
Definition: spectre.cpp:982
void setValue(const double &freq, const double &reel=0.0)
Definition: spectre.cpp:968
double _module[TY_SPECTRE_DEFAULT_NB_ELMT]
Real values array for module.
Definition: spectre.h:468
OSpectreAbstract * getConcreteInstance() const override
Return an instance of a concrete class of the same type as current.
Definition: spectre.cpp:963
static double _fMin
Minimal frequency.
Definition: spectre.h:459
static OSpectre getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
Definition: spectre.cpp:1130
double * getTabValReel() override
Definition: spectre.h:357
static const double _freqNorm[]
Array of center frequencies (Hz) normalized in one-third Octave.
Definition: spectre.h:456
virtual ~OSpectre()
Destructor.
Definition: spectre.cpp:895
bool isTonalite() const
Existence d'une tonalite marquee.
Definition: spectre.cpp:1091
static OSpectre pondC()
Build a weighted spectrum C.
Definition: spectre.cpp:1058
virtual bool operator==(const OSpectre &other) const
operator==
Definition: spectre.cpp:939
static OSpectre pondB()
Build a weighted spectrum B.
Definition: spectre.cpp:1036
static OSpectre pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1014
OSpectre()
Default constructor, the spectrum module is defined by the _defaultValue.
Definition: spectre.cpp:853
double getValueReal(double freq)
Definition: spectre.cpp:974
static double _fMax
Maximal frequency.
Definition: spectre.h:462
static OSpectre makeOctSpect()
Make a spectrum in Octave.
Definition: spectre.cpp:1137
static OTabFreq getTabFreqExact()
Definition: spectre.cpp:994
Utilities to handle exceptions and to pretty-print value.
std::complex< double > TYComplex
Definition: macros.h:25
Math library.
#define EPSILON_15
Definition: mathlib.h:59
#define EPSILON_22
Definition: mathlib.h:65
::std::ostream & operator<<(::std::ostream &os, const OSpectre &s)
Definition: spectre.cpp:1144
std::vector< double > OTabFreq
Frequencies collection.
Definition: spectre.h:60
TYSpectreEtat
Spectrum state (dB/Physical Measure).
Definition: spectre.h:44
@ SPECTRE_ETAT_LIN
Definition: spectre.h:46
@ SPECTRE_ETAT_DB
Definition: spectre.h:45
TYSpectreForm
Spectrum representation.
Definition: spectre.h:36
@ SPECTRE_FORM_TIERS
Definition: spectre.h:37
@ SPECTRE_FORM_OCT
Definition: spectre.h:38
@ SPECTRE_FORM_UNSHAPED
Definition: spectre.h:40
#define CHECK_FORM_AND_GET_CONCRETE_INSTANCE
Definition: spectre.h:67
TYSpectreType
Spectrum type.
Definition: spectre.h:27
@ SPECTRE_TYPE_LW
Definition: spectre.h:30
@ SPECTRE_TYPE_LP
Definition: spectre.h:31
@ SPECTRE_TYPE_AUTRE
Definition: spectre.h:32
@ SPECTRE_TYPE_ATT
Definition: spectre.h:28
@ SPECTRE_TYPE_ABSO
Definition: spectre.h:29