45 1000.0, 1250.0, 1600.0,
46 2000.0, 2500.0, 3150.0,
47 4000.0, 5000.0, 6300.0,
48 8000.0, 10000.0, 12500.0,
64 : _valid(isValid), _type(type), _etat(etat), _form(form)
184 unsigned int nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
188 nbFreq = TY_SPECTRE_OCT_NB_ELMT;
191 nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
203 const double& valeur)
205 for (
unsigned int i = 0; i < spectreNbElmt; i++)
213 for (
short i = 0; i < nbVal; i++)
238 s.setDefaultValue(value);
284 s.getTabValReel()[i] = 1E20;
302 if (coefficient == 0.0)
357 s.getTabValReel()[i] = 1E20;
379 s.getTabValReel()[i] = 1E20;
412 double logBase =
::log(base);
417 s.getTabValReel()[i] = 1E20;
439 s.getTabValReel()[i] = 1E20;
548 s.getTabValReel()[i] =
s.getTabValReel()[i] >= max ? max :
s.getTabValReel()[i];
585 s.getTabValReel()[i] = std::round(
getTabValReel()[i] * 100) / 100;
627 dBVal = 10.0 * log10((val) / coef);
628 s.getTabValReel()[i] = dBVal;
665 s.getTabValReel()[i] = powVal;
674 double valeurGlob = 0.0;
677 valeurGlob = valeurGlob + pow(10, (
s.getTabValReel()[i] / 10));
679 valeurGlob = 10 * log10(valeurGlob);
690 ret =
s.valGlobDBLin();
696 ret =
s.valGlobDBLin();
722 short nbOctValue = 9;
724 for (
short i = 0; i < nbOctValue; i++, indice += 3)
727 s.getTabValReel()[indice] = valeur;
728 s.getTabValReel()[indice + 1] = valeur;
729 s.getTabValReel()[indice + 2] = valeur;
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];
741 short nbOctValue = 9;
748 for (
short i = 0; i < nbOctValue; i++, indice += 3)
751 s.getTabValReel()[indice] = valeur;
752 s.getTabValReel()[indice + 1] = valeur;
753 s.getTabValReel()[indice + 2] = valeur;
757 s.getTabValReel()[0] = 1;
758 s.getTabValReel()[1] = 1;
759 s.getTabValReel()[29] = 1;
760 s.getTabValReel()[30] = 1;
786 unsigned int indiceDepart = 2;
787 unsigned int indice = 0;
789 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
794 s.getTabValReel()[indice] = valeur;
801 unsigned int indiceDepart = 2;
802 unsigned int indice = 0;
809 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
814 s.getTabValReel()[indice] = valeur;
824 cout <<
"Spectrum values: ";
840 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
848 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
859 for (i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
863 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_DEFAULT_NB_ELMT);
864 for (i = decalage; i < maxInd; i++)
866 _module[i] = valeurs[i - decalage];
887 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
901 sp =
dynamic_cast<const OSpectre*
>(&other);
914 std::ostringstream oss;
915 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectre";
916 assert(
false && oss.str().c_str());
928 if ((OSpectreAbstract::operator!=(other)))
932 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
969 std::map<double, int> mapFI;
971 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
982 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
984 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), i - 18));
992 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
994 tabFreqExact.
_module[i] = 1000.0 * pow(pow(10.0, 0.1), i - 18);
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;
1009 (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::
sqrt((f2 + v3) * (f2 + v4)));
1010 double valeur = 0.0;
1011 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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;
1025 long v1 = 12200 * 12200;
1026 double v2 = 20.6 * 20.6;
1027 double v3 = 158.5 * 158.5;
1030 double v1000 = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1031 double valeur = 0.0;
1032 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1034 f = tabFreqExact[i];
1036 valeur = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1037 valeur = 20 * log10(valeur / v1000);
1038 s._module[i] = valeur;
1047 long v1 = 12200 * 12200;
1048 double v2 = 20.6 * 20.6;
1049 double f2 = 1000.0 * 1000.0;
1050 double v1000 = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1051 double valeur = 0.0;
1052 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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;
1069 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1071 s._module[i] =
c / tabFreqExact[i];
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;
1091 for (
unsigned int i = 5; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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));
1102 if ((diffG > tolerence) && (diffD > tolerence))
1132 <<
"type=" <<
s.getType() <<
", state=" <<
s.getEtat() <<
"]" << std::endl;
1134 for (
unsigned i = 0; i <
s.getNbValues(); ++i)
1136 os <<
s.getTabValReel()[i] <<
", ";
1138 os <<
")" << std::endl;
1146 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1154 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1156 _phase[i] = defaultValue.imag();
1168 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1176 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1191 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1215 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1228 if ((OSpectre::operator!=(other)))
1233 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1254 std::complex<double> z1;
1255 std::complex<double> z2;
1256 std::complex<double> z3;
1257 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1263 s._module[i] = std::abs(z3);
1264 s._phase[i] = std::arg(z3);
1277 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1293 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1307 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1309 s._module[i] =
_module[i] * coefficient;
1323 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1340 setValue(freq, cplx.real(), cplx.imag());
1351 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1359 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1368 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1370 s.getTabValReel()[i] =
_phase[i];
1378 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1388 double module = NAN, phase = NAN, reel = NAN, imag = NAN;
1392 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1396 module =
::sqrt(reel * reel + imag * imag);
1397 phase = atan2(imag, reel);
1398 s._module[i] = module;
1399 s._phase[i] = phase;
1407 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1424 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1433 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1441 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1452 for (i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1456 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_OCT_NB_ELMT);
1457 for (i = decalage; i < maxInd; i++)
1459 _module[i] = valeurs[i - decalage];
1479 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1492 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1522 std::ostringstream oss;
1523 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectreOctave";
1524 assert(
false && oss.str().c_str());
1532 assert(
false &&
"Invalid OSpectreOctave object during conversion");
1542 if ((OSpectreAbstract::operator!=(other)))
1546 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1579 for (
int i = 0; i < (int)TY_SPECTRE_OCT_NB_ELMT; i++, indice += 3)
1581 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), indice + 1 - 18));
1583 return tabFreqExact;
1597 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1606 std::map<double, int> mapFI;
1608 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
Store acoustic power values for different frequencies.
OSpectreAbstract & power(const double &puissance) const
Return a spectrum as this spectrum raised to a double power.
OSpectreAbstract & sum(const OSpectreAbstract &spectre) const
Arithmetic sum of two spectrums in one-third Octave.
OSpectreAbstract & subst(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
virtual bool operator==(const OSpectreAbstract &other) const
operator==
bool _valid
Spectrum validity.
double valMax()
Return the maximum value of a spectrum.
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
static double _defaultValue
Default value for the spectrum.
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
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)
OSpectreAbstract & exp(const double coef=1.0)
Compute e^(coef * spectre) of this spectrum.
OSpectreAbstract & operator+(const double &valeur) const
Add a constant value to all the spectrum.
OSpectreAbstract & log(const double &base=10.0) const
Compute the log base n of this spectrum (n=10 by default).
unsigned int getNbValues() const
Number of values in the spectrum.
OSpectreAbstract & invMult(const double &coefficient=1.0) const
Division of a double constant by this spectrum.
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
OSpectreAbstract & operator*(const OSpectreAbstract &spectre) const
Multiplication by a Spectre spectrum.
OSpectreAbstract()
Methods.
double sigma()
Sum the values of the spectrum.
virtual void printme() const
Print the spectrum.
OSpectreAbstract & abs() const
Return the absolute value of this spectrum.
TYSpectreForm _form
Representation of the spectrum: one-third Octave, Octave, constant delta f, unstructured.
OSpectreAbstract & toTOct() const
Converts to one-third Octave.
OSpectreAbstract & div(const OSpectreAbstract &spectre) const
Division of two spectrums.
OSpectreAbstract & sqrt() const
Return the root square of a spectrum.
OSpectreAbstract & racine() const
Compute the root square of this spectrum.
OSpectreAbstract & sin() const
Compute the sin of this spectrum.
void getRangeValueReal(double *valeurs, const short &nbVal, const short &decalage)
virtual OSpectreAbstract & operator=(const OSpectreAbstract &other)
operator=
virtual bool operator!=(const OSpectreAbstract &other) const
operator !=
void setDefaultValue(const double &valeur=TY_SPECTRE_DEFAULT_VALUE)
TYSpectreForm getForm() const
Get the spectrum form.
TYSpectreEtat _etat
Spectrum state (physical quantity or dB).
static OSpectreAbstract & makeOctSpect()
Make a spectrum in Octave.
OSpectreAbstract & operator-(const OSpectreAbstract &spectre) const
Arithmetic subtraction of two spectrums in one-third Octave.
OSpectreAbstract & cos() const
Compute the cos of this spectrum.
OSpectreAbstract & toDB() const
Converts to dB.
OSpectreAbstract & toOct() const
Converts to Octave.
OSpectreAbstract & round()
OSpectreAbstract & mult(const OSpectreAbstract &spectre) const
Multiplication of two spectrums.
TYSpectreType _type
Spectrum type.
OSpectreAbstract & sumdB(const OSpectreAbstract &spectre) const
Energetic sum of two spectrums.
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.
OSpectreComplex & operator=(const OSpectreComplex &other)
operators
void setPhase(const OSpectre &spectre)
bool operator!=(const OSpectreComplex &other) const
double getValueImag(double freq, bool *pValid=0)
void setValue(const double &freq, const double &reel, const double &imag=0.0)
double _phase[TY_SPECTRE_DEFAULT_NB_ELMT]
Array of the imaginary numbers (phase)
OSpectre getModule() const
OSpectreComplex toModulePhase() const
Conversion to module/phase.
OSpectre getPhase() const
static OSpectreComplex getCplxSpectre(const double &valInit=1.0E-20)
Build a OSpectreComplex complex spectrum.
OSpectreComplex operator+(const OSpectreComplex &spectre) const
bool operator==(const OSpectreComplex &other) const
OSpectreComplex operator/(const OSpectreComplex &spectre) const
Divide a complex spectrum by another one.
OSpectreComplex operator*(const OSpectreComplex &spectre) const
Product of two complex spectrums (module/phase)
virtual ~OSpectreComplex()
virtual ~OSpectreOctave()
OSpectreAbstract * getConcreteInstance() const override
Return an instance of a concrete class of the same type as current.
static OSpectreOctave getLambda(const double &c)
static OSpectreOctave pondA()
Build a weighted spectrum A.
double _module[TY_SPECTRE_OCT_NB_ELMT]
Real values array for module.
static const double _AWeighting[TY_SPECTRE_OCT_NB_ELMT]
A weighting for ponderation A computation.
static OSpectreOctave getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
bool operator!=(const OSpectreOctave &other) const
void setValue(const double &freq, const double &reel=0.0)
bool operator==(const OSpectreOctave &other) const
static OTabFreq getTabFreqExact()
static const double _freqNorm[TY_SPECTRE_OCT_NB_ELMT]
Array of center frequencies (Hz) normalized in one-third Octave.
static std::map< double, int > setMapFreqIndice()
Build frequency/index map.
static std::map< double, int > _mapFreqIndice
Mapping between frequency and array index.
OSpectreOctave & operator=(const OSpectreOctave &other)
operators
static OSpectre getOSpectreFreqExact()
Return the spectrum of the exact frequencies.
virtual bool operator!=(const OSpectre &other) const
operator !=
OSpectre & operator=(const OSpectre &other)
operator=
static OSpectre getLambda(const double &c)
static std::map< double, int > _mapFreqIndice
Mapping between frequency and array index.
static std::map< double, int > setMapFreqIndice()
Construction du tableau frequence/indice.
void setValue(const double &freq, const double &reel=0.0)
double _module[TY_SPECTRE_DEFAULT_NB_ELMT]
Real values array for module.
OSpectreAbstract * getConcreteInstance() const override
Return an instance of a concrete class of the same type as current.
static double _fMin
Minimal frequency.
static OSpectre getEmptyLinSpectre(const double &valInit=1.0E-20)
Create a physical quantity spectrum.
double * getTabValReel() override
static const double _freqNorm[]
Array of center frequencies (Hz) normalized in one-third Octave.
virtual ~OSpectre()
Destructor.
bool isTonalite() const
Existence d'une tonalite marquee.
static OSpectre pondC()
Build a weighted spectrum C.
virtual bool operator==(const OSpectre &other) const
operator==
static OSpectre pondB()
Build a weighted spectrum B.
static OSpectre pondA()
Build a weighted spectrum A.
OSpectre()
Default constructor, the spectrum module is defined by the _defaultValue.
double getValueReal(double freq)
static double _fMax
Maximal frequency.
static OSpectre makeOctSpect()
Make a spectrum in Octave.
static OTabFreq getTabFreqExact()
Utilities to handle exceptions and to pretty-print value.
std::complex< double > TYComplex
::std::ostream & operator<<(::std::ostream &os, const OSpectre &s)
std::vector< double > OTabFreq
Frequencies collection.
TYSpectreEtat
Spectrum state (dB/Physical Measure).
TYSpectreForm
Spectrum representation.
#define CHECK_FORM_AND_GET_CONCRETE_INSTANCE
TYSpectreType
Spectrum type.