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  double coef = 1.0;
609  double epsilon = EPSILON_15;
610  switch (_type)
611  {
612  case SPECTRE_TYPE_LP:
613  coef = 4.0e-10;
614  break;
615  case SPECTRE_TYPE_LW:
616  coef = 1.0e-12;
617  epsilon = EPSILON_22;
618  break;
619  case SPECTRE_TYPE_ATT:
620  default:
621  coef = 1.0;
622  break;
623  }
624  double dBVal = 0.0;
625  for (i = 0; i < getNbValues(); i++)
626  {
627  // avoid -infinite result
628  double val = getTabValReel()[i];
629  if (val < epsilon)
630  {
631  val = epsilon;
632  }
633 
634  dBVal = 10.0 * log10((val) / coef);
635  s.getTabValReel()[i] = dBVal;
636  }
637  s._etat = SPECTRE_ETAT_DB; // Indicate explicitly dB state
638  return s;
639 }
640 
642 {
644  OSpectreAbstract& s = *sp;
645 
646  if (_etat == SPECTRE_ETAT_LIN) // If spectrum is already in LIN state, we just copy values
647  {
648  s = *this;
649  return s;
650  }
651  unsigned int i = 0;
652  double coef = 1.0;
653  s._type = _type; // Copy type
654  s._form = _form; // Copy form
655  switch (_type)
656  {
657  case SPECTRE_TYPE_LP:
658  coef = 4.0e-10;
659  break;
660  case SPECTRE_TYPE_LW:
661  coef = 1.0e-12;
662  break;
663  case SPECTRE_TYPE_ATT:
664  default:
665  coef = 1.0;
666  break;
667  }
668  double powVal = 0.0;
669  for (i = 0; i < getNbValues(); i++)
670  {
671  powVal = pow(10.0, this->getTabValReel()[i] / 10.0) * coef;
672  s.getTabValReel()[i] = powVal;
673  }
674  s._etat = SPECTRE_ETAT_LIN; // Indicate explicitly 'Physical Measure' state
675  return s;
676 }
677 
679 {
680  OSpectreAbstract& s = this->toDB();
681  double valeurGlob = 0.0;
682  for (unsigned int i = 0; i < getNbValues(); i++)
683  {
684  valeurGlob = valeurGlob + pow(10, (s.getTabValReel()[i] / 10));
685  }
686  valeurGlob = 10 * log10(valeurGlob);
687  return valeurGlob;
688 }
689 
691 {
692 
693  double ret = -1.0;
694  if (getNbValues() == TY_SPECTRE_DEFAULT_NB_ELMT && this->getForm() == SPECTRE_FORM_TIERS)
695  {
696  OSpectreAbstract& s(this->toDB() + OSpectre::pondA());
697  ret = s.valGlobDBLin();
698  }
699  else
700  {
701  OSpectreAbstract& s1 = this->toDB();
703  ret = s.valGlobDBLin();
704  }
705  return ret;
706 }
707 
709 {
710  // The return spectrum must be of type OSpectre
712  OSpectreAbstract& s = *sp;
713 
714  if (_form == SPECTRE_FORM_TIERS) // If object is already in third-octave
715  {
716  s = *this;
717  return s;
718  }
719  else if (_form != SPECTRE_FORM_OCT) // If spectrum is not in octave
720  {
721  s._valid = false;
722  return s;
723  }
724  s._type = _type;
726  {
727  const OSpectreAbstract& travail = *this;
728  short indice = 2;
729  short nbOctValue = 9;
730  double valeur = 0.0;
731  for (short i = 0; i < nbOctValue; i++, indice += 3)
732  {
733  valeur = travail.getTabValReel()[i];
734  s.getTabValReel()[indice] = valeur;
735  s.getTabValReel()[indice + 1] = valeur;
736  s.getTabValReel()[indice + 2] = valeur;
737  }
738  s.getTabValReel()[0] = s.getTabValReel()[2];
739  s.getTabValReel()[1] = s.getTabValReel()[2];
740  s.getTabValReel()[29] = s.getTabValReel()[28];
741  s.getTabValReel()[30] = s.getTabValReel()[28];
742  s._etat = SPECTRE_ETAT_DB;
743  }
744  else
745  {
746  OSpectreAbstract& travail = this->toGPhy();
747  short indice = 2;
748  short nbOctValue = 9;
749  double valeur = 0.0;
750  double coef = 3.0;
751  if (_type == SPECTRE_TYPE_ATT)
752  {
753  coef = 1.0;
754  }
755  for (short i = 0; i < nbOctValue; i++, indice += 3)
756  {
757  valeur = travail.getTabValReel()[i] / coef;
758  s.getTabValReel()[indice] = valeur;
759  s.getTabValReel()[indice + 1] = valeur;
760  s.getTabValReel()[indice + 2] = valeur;
761  }
762  if (_type == SPECTRE_TYPE_ATT)
763  {
764  s.getTabValReel()[0] = 1;
765  s.getTabValReel()[1] = 1;
766  s.getTabValReel()[29] = 1;
767  s.getTabValReel()[30] = 1;
768  }
769  else if (_type == SPECTRE_TYPE_LP)
770  {
771  s.getTabValReel()[0] = 1.0E-15;
772  s.getTabValReel()[1] = 1.0E-15;
773  s.getTabValReel()[29] = 1.0E-15;
774  s.getTabValReel()[30] = 1.0E-15;
775  }
776  s = s.toDB();
777  }
778  s._form = SPECTRE_FORM_TIERS; // Indicate explicitly thrid-octave form
779  return s;
780 }
781 
783 {
785  if (_form == SPECTRE_FORM_OCT) // If spectrum already is in octave
786  {
787  s = *this;
788  return s;
789  }
790  else if (_form != SPECTRE_FORM_TIERS) // If spectrum is not in thrid-octave
791  {
792  s._valid = false;
793  return s;
794  }
795  s._etat = SPECTRE_ETAT_LIN; // s is in lin state too at this moment
796  s._type = _type;
798  {
799  const OSpectreAbstract& travail = *this;
800  unsigned int indiceDepart = 2;
801  unsigned int indice = 0;
802  double valeur = 0.0;
803  for (unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
804  {
805  valeur = (travail.getTabValReel()[i] + travail.getTabValReel()[i + 1] +
806  travail.getTabValReel()[i + 2]) /
807  3; // Absorptions mean
808  s.getTabValReel()[indice] = valeur;
809  }
810  s._etat = SPECTRE_ETAT_DB;
811  }
812  else
813  {
814  OSpectreAbstract& travail = this->toGPhy();
815  unsigned int indiceDepart = 2;
816  unsigned int indice = 0;
817  double valeur = 0.0;
818  double coef = 1.0;
819  if (_type == SPECTRE_TYPE_ATT)
820  {
821  coef = 3.0;
822  }
823  for (unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
824  {
825  valeur = (travail.getTabValReel()[i] + travail.getTabValReel()[i + 1] +
826  travail.getTabValReel()[i + 2]) /
827  coef;
828  s.getTabValReel()[indice] = valeur;
829  }
830  s = s.toDB();
831  }
832  s._form = SPECTRE_FORM_OCT; // Indicate explicitly octave form
833  return s;
834 }
835 
837 {
838  std::cout << "Spectrum values: ";
839  for (unsigned int i = 0; i < getNbValues(); i++)
840  {
841  std::cout << getTabValReel()[i] << " ";
842  }
843  std::cout << std::endl;
844 }
845 
847 {
849  return *s;
850 }
851 
853 {
854  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
855  {
856  _module[i] = _defaultValue;
857  }
858 }
859 
861 {
862  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
863  {
864  _module[i] = defaultValue;
865  }
866 }
867 
868 OSpectre::OSpectre(const double* valeurs, unsigned nbVal, unsigned decalage)
870 {
871  unsigned int i = 0;
872  // First init values
873  for (i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
874  {
875  _module[i] = _defaultValue;
876  }
877  unsigned int maxInd = std::min(nbVal + decalage, TY_SPECTRE_DEFAULT_NB_ELMT);
878  for (i = decalage; i < maxInd; i++)
879  {
880  _module[i] = valeurs[i - decalage];
881  }
882 }
883 
885 {
886  *this = other;
887 }
888 
890 {
891  *this = other;
892 }
893 
895 
897 {
898  if (this != &other)
899  {
901  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
902  {
903  _module[i] = other._module[i];
904  }
905  }
906  return *this;
907 }
908 
910 {
911  if (this != &other)
912  {
913  const OSpectre* sp;
914  // If other of type OSpectre just cast it
915  sp = dynamic_cast<const OSpectre*>(&other);
916  // If not, try to cast to an OSpectreOctave and convert to third-octave band
917  if (sp == nullptr)
918  {
919  const OSpectreOctave* spo = dynamic_cast<const OSpectreOctave*>(&other);
920  if (spo != nullptr)
921  {
922  OSpectre s = spo->toTOct();
923  sp = &s;
924  }
925  // If neither conversions are possible raise error
926  else
927  {
928  std::ostringstream oss;
929  oss << "Impossible to convert from " << other.getForm() << " to OSpectre";
930  assert(false && oss.str().c_str());
931  }
932  }
933  *this = *sp;
934  }
935  return *this;
936 }
937 
938 bool OSpectre::operator==(const OSpectre& other) const
939 {
940  if (this != &other)
941  {
942  if ((OSpectreAbstract::operator!=(other)))
943  {
944  return false;
945  }
946  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
947  {
948  if (_module[i] != other._module[i])
949  {
950  return false;
951  }
952  }
953  }
954  return true;
955 }
956 
957 bool OSpectre::operator!=(const OSpectre& other) const
958 {
959  return !operator==(other);
960 }
961 
963 {
964  return new OSpectre();
965 }
966 
967 void OSpectre::setValue(const double& freq, const double& reel /*=0.0*/)
968 {
969  int indice = _mapFreqIndice[freq];
970  _module[indice] = reel;
971 }
972 
973 double OSpectre::getValueReal(double freq)
974 {
975  int indice = _mapFreqIndice[freq];
976  return _module[indice];
977 }
978 
979 // Static functions
980 
981 std::map<double, int> OSpectre::setMapFreqIndice()
982 {
983  std::map<double, int> mapFI;
984  double value = 0.0;
985  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
986  {
987  value = _freqNorm[i];
988  mapFI[value] = i;
989  }
990  return mapFI;
991 }
992 
994 {
995  OTabFreq tabFreqExact;
996  for (int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
997  {
998  tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), i - 18));
999  }
1000  return tabFreqExact;
1001 }
1002 
1004 {
1005  OSpectre tabFreqExact;
1006  for (int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1007  {
1008  tabFreqExact._module[i] = 1000.0 * pow(pow(10.0, 0.1), i - 18);
1009  }
1010  return tabFreqExact;
1011 }
1012 
1014 {
1015  OSpectre s;
1016  OTabFreq tabFreqExact = getTabFreqExact();
1017  long v1 = 12200 * 12200;
1018  double v2 = 20.6 * 20.6;
1019  double v3 = 107.7 * 107.7;
1020  double v4 = 737.9 * 737.9;
1021  double f2 = 1000.0 * 1000.0; // squared frequency
1022  double v1000 =
1023  (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::sqrt((f2 + v3) * (f2 + v4))); // reference at 1000 Hz
1024  double valeur = 0.0;
1025  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1026  {
1027  f2 = tabFreqExact[i] * tabFreqExact[i];
1028  valeur = (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::sqrt((f2 + v3) * (f2 + v4)));
1029  valeur = 20 * log10(valeur / v1000);
1030  s._module[i] = std::round(valeur * 10) / 10;
1031  }
1032  return s;
1033 }
1034 
1036 {
1037  OSpectre s;
1038  OTabFreq tabFreqExact = getTabFreqExact();
1039  long v1 = 12200 * 12200;
1040  double v2 = 20.6 * 20.6;
1041  double v3 = 158.5 * 158.5;
1042  double f = 1000.0;
1043  double f2 = f * f; // squared frequency
1044  double v1000 = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::sqrt(f2 + v3)); // reference at 1000 Hz
1045  double valeur = 0.0;
1046  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1047  {
1048  f = tabFreqExact[i];
1049  f2 = f * f;
1050  valeur = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::sqrt(f2 + v3));
1051  valeur = 20 * log10(valeur / v1000);
1052  s._module[i] = valeur;
1053  }
1054  return s;
1055 }
1056 
1058 {
1059  OSpectre s;
1060  OTabFreq tabFreqExact = getTabFreqExact();
1061  long v1 = 12200 * 12200;
1062  double v2 = 20.6 * 20.6;
1063  double f2 = 1000.0 * 1000.0; // squared frequency
1064  double v1000 = (v1 * f2) / ((f2 + v1) * (f2 + v2)); // reference at 1000 Hz
1065  double valeur = 0.0;
1066  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1067  {
1068  f2 = tabFreqExact[i] * tabFreqExact[i];
1069  valeur = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1070  valeur = 20 * log10(valeur / v1000);
1071  s._module[i] = valeur;
1072  }
1073  return s;
1074 }
1075 
1077 {
1078  OSpectre s;
1079  // Copy spectrum fingerprint
1080  s._etat = SPECTRE_ETAT_LIN;
1081  s._type = SPECTRE_TYPE_AUTRE;
1082  OTabFreq tabFreqExact = getTabFreqExact();
1083  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1084  {
1085  s._module[i] = c / tabFreqExact[i];
1086  }
1087  return s;
1088 }
1089 
1091 {
1092  if ((_etat == SPECTRE_ETAT_LIN) || (_form == SPECTRE_FORM_OCT))
1093  {
1094  return false;
1095  }
1096  const double seuil = 315;
1097  double a = NAN, b = NAN, c = NAN, d = NAN, e = NAN, ab = NAN, de = NAN, diffG = NAN, diffD = NAN,
1098  freq = NAN, tolerence = NAN;
1099  a = _module[0];
1100  b = _module[1];
1101  c = _module[2];
1102  d = _module[3];
1103  e = _module[4];
1104  tolerence = 10.0;
1105  for (unsigned int i = 5; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1106  {
1107  ab = 10 * ::log10(((::pow(10, a / 10.0) + ::pow(10, b / 10.0)) / 2.0));
1108  de = 10 * ::log10(((::pow(10, d / 10.0) + ::pow(10, e / 10.0)) / 2.0));
1109  diffG = c - ab;
1110  diffD = c - de;
1111  freq = OSpectre::_freqNorm[i - 3];
1112  if (freq > seuil)
1113  {
1114  tolerence = 5.0;
1115  }
1116  if ((diffG > tolerence) && (diffD > tolerence))
1117  {
1118  return true;
1119  }
1120  a = b;
1121  b = c;
1122  c = d;
1123  d = e;
1124  e = _module[i];
1125  }
1126  return false;
1127 }
1128 
1130 {
1131  OSpectre s(valInit);
1132  s._etat = SPECTRE_ETAT_LIN;
1133  return s;
1134 }
1135 
1137 {
1138  OSpectre s;
1139  s._form = SPECTRE_FORM_OCT;
1140  return s;
1142 
1143 ::std::ostream& operator<<(::std::ostream& os, const OSpectre& s)
1144 {
1145  os << "Spectrum["
1146  << "type=" << s.getType() << ", state=" << s.getEtat() << "]" << std::endl;
1147  os << " (";
1148  for (unsigned i = 0; i < s.getNbValues(); ++i)
1149  {
1150  os << s.getTabValReel()[i] << ", ";
1151  }
1152  os << ")" << std::endl;
1153  return os;
1154 }
1155 
1156 /* OSpectreComplex ************************************************************/
1157 
1159 {
1160  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1161  {
1162  _phase[i] = 0.0;
1163  }
1164 }
1165 
1166 OSpectreComplex::OSpectreComplex(const TYComplex& defaultValue) : OSpectre(defaultValue.real())
1167 {
1168  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1169  {
1170  _phase[i] = defaultValue.imag();
1171  }
1172 }
1173 
1175 {
1176  *this = other;
1177 }
1178 
1180 {
1181  OSpectre::operator=(other);
1182  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1183  {
1184  _phase[i] = 0.0;
1185  }
1186 }
1187 
1188 OSpectreComplex::OSpectreComplex(const OSpectre& spectre1, const OSpectre& spectre2)
1189 {
1190  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1191  {
1192  _module[i] = (spectre1.getTabValReel())[i];
1193  _phase[i] = (spectre2.getTabValReel())[i];
1194  }
1195 }
1196 
1198 
1200 {
1201  if (this != &other)
1202  {
1203  OSpectre::operator=(other);
1204 
1205  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1206  {
1207  _phase[i] = other._phase[i];
1208  }
1209  }
1210  return *this;
1211 }
1212 
1214 {
1215  if (this != &other)
1216  {
1217  const OSpectreComplex* sc;
1218  sc = dynamic_cast<const OSpectreComplex*>(&other);
1219 
1220  // If other of type OSpectreComplex just cast it
1221  if (sc != nullptr)
1222  {
1223  *this = *sc;
1224  }
1225  // If not, convert from an OSpectre and init phase values to zero
1226  else
1227  {
1228  OSpectre::operator=(other);
1229  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1230  {
1231  _phase[i] = 0;
1232  }
1233  }
1234  }
1235  return *this;
1236 }
1237 
1239 {
1240  if (this != &other)
1241  {
1242  if ((OSpectre::operator!=(other)))
1243  {
1244  return false;
1245  }
1246 
1247  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1248  if (_phase[i] != other._phase[i])
1249  {
1250  return false;
1251  }
1252  }
1253  return true;
1254 }
1255 
1257 {
1258  return !operator==(other);
1259 }
1260 
1262 {
1264  // Copy spectrum fingerprint
1265  s._etat = _etat;
1266  s._type = _type;
1267  // A complex number is defined as z = a + ib
1268  std::complex<double> z1; // This is the original one
1269  std::complex<double> z2; // This is the one we add
1270  std::complex<double> z3; // This is the returned complex number i.e. the result
1271  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1272  {
1273  z1 = std::polar(_module[i], _phase[i]);
1274  z2 = std::polar(spectre._module[i], spectre._phase[i]);
1275  z3 = z1 + z2;
1276 
1277  s._module[i] = std::abs(z3);
1278  s._phase[i] = std::arg(z3);
1279  }
1280  return s;
1281 }
1282 
1284 {
1285  // Product of two complex in modulus/phase
1286  // = modulus product and phases sum
1288  // Copy spectrum fingerprint
1289  s._etat = _etat;
1290  s._type = _type;
1291  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1292  {
1293  s._module[i] = _module[i] * spectre._module[i];
1294  s._phase[i] = _phase[i] + spectre._phase[i];
1295  }
1296  return s;
1297 }
1298 
1300 {
1301  // Product of two complex in modulus/phase
1302  // = modulus product and phases sum
1304  // Copy spectrum fingerprint
1305  s._etat = _etat;
1306  s._type = _type;
1307  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1308  {
1309  s._module[i] = _module[i] * (spectre.getTabValReel())[i];
1310  s._phase[i] = _phase[i];
1311  }
1312  return s;
1313 }
1314 
1315 OSpectreComplex OSpectreComplex::operator*(const double& coefficient) const
1316 {
1318  // Copy spectrum fingerprint
1319  s._etat = _etat;
1320  s._type = _type;
1321  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1322  {
1323  s._module[i] = _module[i] * coefficient;
1324  s._phase[i] = _phase[i];
1325  }
1326  return s;
1327 }
1328 
1330 {
1331  // Quotient of two complex in modulus/phase
1332  // = modulus quotient and phases difference
1334  // Copy spectrum fingerprint
1335  s._etat = _etat;
1336  s._type = _type;
1337  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1338  {
1339  s._module[i] = _module[i] / spectre._module[i];
1340  s._phase[i] = _phase[i] - spectre._phase[i];
1341  }
1342  return s;
1343 }
1344 
1345 void OSpectreComplex::setValue(const double& freq, const double& reel, const double& imag)
1346 {
1347  int indice = _mapFreqIndice[freq];
1348  _module[indice] = reel;
1349  _phase[indice] = imag;
1350 }
1351 
1352 void OSpectreComplex::setValue(const double& freq, const TYComplex& cplx)
1353 {
1354  setValue(freq, cplx.real(), cplx.imag());
1355 }
1356 
1357 double OSpectreComplex::getValueImag(double freq, bool* pValid)
1358 {
1359  int indice = _mapFreqIndice[freq];
1360  return _phase[indice];
1361 }
1362 
1364 {
1365  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1366  {
1367  _phase[i] = spectre.getTabValReel()[i];
1368  }
1369 }
1370 
1371 void OSpectreComplex::setPhase(const double& valeur)
1372 {
1373  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1374  {
1375  _phase[i] = valeur;
1376  }
1377 }
1378 
1380 {
1382  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1383  {
1384  s.getTabValReel()[i] = _phase[i];
1385  }
1386  return s;
1387 }
1388 
1390 {
1392  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1393  {
1394  s.getTabValReel()[i] = _module[i];
1395  }
1396  return s;
1397 }
1398 
1400 {
1402  double module = NAN, phase = NAN, reel = NAN, imag = NAN;
1403  // Copy spectrum fingerprint
1404  s._etat = _etat;
1405  s._type = _type;
1406  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1407  {
1408  reel = this->_module[i];
1409  imag = this->_phase[i];
1410  module = ::sqrt(reel * reel + imag * imag);
1411  phase = atan2(imag, reel);
1412  s._module[i] = module;
1413  s._phase[i] = phase;
1414  }
1415  return s;
1416 }
1417 
1419 {
1421  for (unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1422  {
1423  s._phase[i] = 0.0;
1424  }
1425  return s;
1426 }
1427 
1428 /* OSpectreOctave ************************************************************/
1429 // Standardized central octave frequencies table in Hz.
1430 const double OSpectreOctave::_freqNorm[] = {31.5, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0};
1431 
1432 const double OSpectreOctave::_AWeighting[] = {-39.4, -26.2, -16.1, -8.6, -3.2, 0.0, 1.2, 1.0, -1.1};
1433 
1434 std::map<double, int> OSpectreOctave::_mapFreqIndice = setMapFreqIndice();
1435 
1437 {
1438  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1439  {
1440  _module[i] = _defaultValue;
1441  }
1442 }
1443 
1445  : OSpectreAbstract(isValid, type, etat, SPECTRE_FORM_OCT)
1446 {
1447  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1448  {
1449  _module[i] = _defaultValue;
1450  }
1451 }
1452 
1454 {
1455  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1456  {
1457  _module[i] = defaultValue;
1458  }
1459 }
1460 
1461 OSpectreOctave::OSpectreOctave(const double* valeurs, unsigned nbVal, unsigned decalage)
1463 {
1464  unsigned int i;
1465  // D'abord on initialise les valeurs
1466  for (i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1467  {
1468  _module[i] = _defaultValue;
1469  }
1470  unsigned int maxInd = std::min(nbVal + decalage, TY_SPECTRE_OCT_NB_ELMT);
1471  for (i = decalage; i < maxInd; i++)
1472  {
1473  _module[i] = valeurs[i - decalage];
1474  }
1475 }
1476 
1478 {
1479  *this = other;
1480 }
1481 
1483 {
1484  *this = other;
1485 }
1486 
1488 {
1489  OSpectreAbstract& s = other.toOct();
1490  _valid = s.isValid();
1491  _type = s.getType();
1492  _etat = s.getEtat();
1493  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1494  {
1495  _module[i] = s.getTabValReel()[i];
1496  }
1497 }
1498 
1500 
1502 {
1503  if (this != &other)
1504  {
1506  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1507  {
1508  _module[i] = other._module[i];
1509  }
1510  }
1511  return *this;
1512 }
1513 
1515 {
1516  if (this != &other)
1517  {
1518 
1519  const OSpectreOctave* so;
1520  // If other if of octave form then build OSpectreOctave from values
1521  if (other.getForm() == SPECTRE_FORM_OCT)
1522  {
1523  so = dynamic_cast<const OSpectreOctave*>(&other);
1524  }
1525  else if (other.getForm() == SPECTRE_FORM_TIERS)
1526  // If other is third-octave form then convert other to octave before building from values
1527  {
1528  OSpectreAbstract& otherOctave = other.toOct();
1529  // In this case toOct() returns an OSPectre object so we need to convert it
1530  const OSpectre* s = dynamic_cast<const OSpectre*>(&otherOctave);
1531  const OSpectreOctave so1{*s};
1532  so = &so1;
1533  }
1534  else
1535  {
1536  std::ostringstream oss;
1537  oss << "Impossible to convert from " << other.getForm() << " to OSpectreOctave";
1538  assert(false && oss.str().c_str());
1539  }
1540  if (so != nullptr)
1541  {
1542  *this = *so;
1543  }
1544  else
1545  {
1546  assert(false && "Invalid OSpectreOctave object during conversion");
1547  }
1548  }
1549  return *this;
1550 }
1551 
1553 {
1554  if (this != &other)
1555  {
1556  if ((OSpectreAbstract::operator!=(other)))
1557  {
1558  return false;
1559  }
1560  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1561  {
1562  if (_module[i] != other._module[i])
1563  {
1564  return false;
1565  }
1566  }
1567  }
1568  return true;
1569 }
1570 
1572 {
1573  return !operator==(other);
1574 }
1575 
1577 {
1578  return new OSpectreOctave();
1579 }
1580 
1581 void OSpectreOctave::setValue(const double& freq, const double& reel /*=0.0*/)
1582 {
1583  int indice = _mapFreqIndice[freq];
1584  _module[indice] = reel;
1585 }
1586 
1587 // Static functions
1588 
1590 {
1591  OTabFreq tabFreqExact;
1592  short indice = 2;
1593  for (int i = 0; i < (int)TY_SPECTRE_OCT_NB_ELMT; i++, indice += 3)
1594  {
1595  tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), indice + 1 - 18));
1596  }
1597  return tabFreqExact;
1598 }
1599 
1601 {
1602  return OSpectreOctave{_AWeighting, 9, 0};
1603 }
1604 
1606 {
1607  OSpectreOctave s;
1608  // Copy spectrum fingerprint
1609  s._etat = SPECTRE_ETAT_LIN;
1610  s._type = SPECTRE_TYPE_AUTRE;
1611  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1612  {
1613  s._module[i] = c / _freqNorm[i];
1614  }
1615  return s;
1616 }
1617 
1618 std::map<double, int> OSpectreOctave::setMapFreqIndice()
1619 {
1620  std::map<double, int> mapFI;
1621  double value = 0.0;
1622  for (unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1623  {
1624  value = _freqNorm[i];
1625  mapFI[value] = i;
1626  }
1627  return mapFI;
1628 }
1629 
1631 {
1632  OSpectreOctave s(valInit);
1633  s._etat = SPECTRE_ETAT_LIN;
1634  return s;
1635 }
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:690
static double _defaultValue
Default value for the spectrum.
Definition: spectre.h:308
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:641
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:678
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:836
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:708
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:846
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:782
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:1199
void setPhase(const OSpectre &spectre)
Definition: spectre.cpp:1363
bool operator!=(const OSpectreComplex &other) const
Definition: spectre.cpp:1256
double getValueImag(double freq, bool *pValid=0)
Definition: spectre.cpp:1357
void setValue(const double &freq, const double &reel, const double &imag=0.0)
Definition: spectre.cpp:1345
double _phase[TY_SPECTRE_DEFAULT_NB_ELMT]
Array of the imaginary numbers (phase)
Definition: spectre.h:578
OSpectre getModule() const
Definition: spectre.cpp:1389
OSpectreComplex toModulePhase() const
Conversion to module/phase.
Definition: spectre.cpp:1399
OSpectre getPhase() const
Definition: spectre.cpp:1379
static OSpectreComplex getCplxSpectre(const double &valInit=1.0E-20)
Build a OSpectreComplex complex spectrum.
Definition: spectre.cpp:1418
OSpectreComplex operator+(const OSpectreComplex &spectre) const
Definition: spectre.cpp:1261
bool operator==(const OSpectreComplex &other) const
Definition: spectre.cpp:1238
OSpectreComplex operator/(const OSpectreComplex &spectre) const
Divide a complex spectrum by another one.
Definition: spectre.cpp:1329
OSpectreComplex operator*(const OSpectreComplex &spectre) const
Product of two complex spectrums (module/phase)
Definition: spectre.cpp:1283
virtual ~OSpectreComplex()
Definition: spectre.cpp:1197
virtual ~OSpectreOctave()
Definition: spectre.cpp:1499
OSpectreAbstract * getConcreteInstance() const override
Return an instance of a concrete class of the same type as current.
Definition: spectre.cpp:1576
static OSpectreOctave getLambda(const double &c)
Definition: spectre.cpp:1605
static OSpectreOctave pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1600
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:1630
bool operator!=(const OSpectreOctave &other) const
Definition: spectre.cpp:1571
void setValue(const double &freq, const double &reel=0.0)
Definition: spectre.cpp:1581
bool operator==(const OSpectreOctave &other) const
Definition: spectre.cpp:1552
static OTabFreq getTabFreqExact()
Definition: spectre.cpp:1589
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:1618
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:1501
static OSpectre getOSpectreFreqExact()
Return the spectrum of the exact frequencies.
Definition: spectre.cpp:1003
virtual bool operator!=(const OSpectre &other) const
operator !=
Definition: spectre.cpp:957
OSpectre & operator=(const OSpectre &other)
operator=
Definition: spectre.cpp:896
static OSpectre getLambda(const double &c)
Definition: spectre.cpp:1076
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:981
void setValue(const double &freq, const double &reel=0.0)
Definition: spectre.cpp:967
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:962
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:1129
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:894
bool isTonalite() const
Existence d'une tonalite marquee.
Definition: spectre.cpp:1090
static OSpectre pondC()
Build a weighted spectrum C.
Definition: spectre.cpp:1057
virtual bool operator==(const OSpectre &other) const
operator==
Definition: spectre.cpp:938
static OSpectre pondB()
Build a weighted spectrum B.
Definition: spectre.cpp:1035
static OSpectre pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1013
OSpectre()
Default constructor, the spectrum module is defined by the _defaultValue.
Definition: spectre.cpp:852
double getValueReal(double freq)
Definition: spectre.cpp:973
static double _fMax
Maximal frequency.
Definition: spectre.h:462
static OSpectre makeOctSpect()
Make a spectrum in Octave.
Definition: spectre.cpp:1136
static OTabFreq getTabFreqExact()
Definition: spectre.cpp:993
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:1143
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