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