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)
189 unsigned int nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
193 nbFreq = TY_SPECTRE_OCT_NB_ELMT;
196 nbFreq = TY_SPECTRE_DEFAULT_NB_ELMT;
208 const double& valeur)
210 for (
unsigned int i = 0; i < spectreNbElmt; i++)
218 for (
short i = 0; i < nbVal; i++)
243 s.setDefaultValue(value);
289 s.getTabValReel()[i] = 1E20;
307 if (coefficient == 0.0)
362 s.getTabValReel()[i] = 1E20;
384 s.getTabValReel()[i] = 1E20;
417 double logBase =
::log(base);
422 s.getTabValReel()[i] = 1E20;
444 s.getTabValReel()[i] = 1E20;
553 s.getTabValReel()[i] =
s.getTabValReel()[i] >= max ? max :
s.getTabValReel()[i];
590 s.getTabValReel()[i] = std::round(
getTabValReel()[i] * 100) / 100;
635 dBVal = 10.0 * log10((val) / coef);
636 s.getTabValReel()[i] = dBVal;
673 s.getTabValReel()[i] = powVal;
682 double valeurGlob = 0.0;
685 valeurGlob = valeurGlob + pow(10, (
s.getTabValReel()[i] / 10));
687 valeurGlob = 10 * log10(valeurGlob);
698 ret =
s.valGlobDBLin();
704 ret =
s.valGlobDBLin();
730 short nbOctValue = 9;
732 for (
short i = 0; i < nbOctValue; i++, indice += 3)
735 s.getTabValReel()[indice] = valeur;
736 s.getTabValReel()[indice + 1] = valeur;
737 s.getTabValReel()[indice + 2] = valeur;
739 s.getTabValReel()[0] =
s.getTabValReel()[2];
740 s.getTabValReel()[1] =
s.getTabValReel()[2];
741 s.getTabValReel()[29] =
s.getTabValReel()[28];
742 s.getTabValReel()[30] =
s.getTabValReel()[28];
749 short nbOctValue = 9;
756 for (
short i = 0; i < nbOctValue; i++, indice += 3)
759 s.getTabValReel()[indice] = valeur;
760 s.getTabValReel()[indice + 1] = valeur;
761 s.getTabValReel()[indice + 2] = valeur;
765 s.getTabValReel()[0] = 1;
766 s.getTabValReel()[1] = 1;
767 s.getTabValReel()[29] = 1;
768 s.getTabValReel()[30] = 1;
772 s.getTabValReel()[0] = 1.0E-15;
773 s.getTabValReel()[1] = 1.0E-15;
774 s.getTabValReel()[29] = 1.0E-15;
775 s.getTabValReel()[30] = 1.0E-15;
801 unsigned int indiceDepart = 2;
802 unsigned int indice = 0;
804 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
809 s.getTabValReel()[indice] = valeur;
816 unsigned int indiceDepart = 2;
817 unsigned int indice = 0;
824 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
829 s.getTabValReel()[indice] = valeur;
839 std::cout <<
"Spectrum values: ";
844 std::cout << std::endl;
855 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
863 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
874 for (i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
878 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_DEFAULT_NB_ELMT);
879 for (i = decalage; i < maxInd; i++)
881 _module[i] = valeurs[i - decalage];
902 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
916 sp =
dynamic_cast<const OSpectre*
>(&other);
929 std::ostringstream oss;
930 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectre";
931 assert(
false && oss.str().c_str());
943 if ((OSpectreAbstract::operator!=(other)))
947 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
984 std::map<double, int> mapFI;
986 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
997 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
999 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), i - 18));
1001 return tabFreqExact;
1007 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1009 tabFreqExact.
_module[i] = 1000.0 * pow(pow(10.0, 0.1), i - 18);
1011 return tabFreqExact;
1018 long v1 = 12200 * 12200;
1019 double v2 = 20.6 * 20.6;
1020 double v3 = 107.7 * 107.7;
1021 double v4 = 737.9 * 737.9;
1022 double f2 = 1000.0 * 1000.0;
1024 (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::
sqrt((f2 + v3) * (f2 + v4)));
1025 double valeur = 0.0;
1026 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1028 f2 = tabFreqExact[i] * tabFreqExact[i];
1029 valeur = (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::
sqrt((f2 + v3) * (f2 + v4)));
1030 valeur = 20 * log10(valeur / v1000);
1031 s._module[i] = valeur;
1040 long v1 = 12200 * 12200;
1041 double v2 = 20.6 * 20.6;
1042 double v3 = 158.5 * 158.5;
1045 double v1000 = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1046 double valeur = 0.0;
1047 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1049 f = tabFreqExact[i];
1051 valeur = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1052 valeur = 20 * log10(valeur / v1000);
1053 s._module[i] = valeur;
1062 long v1 = 12200 * 12200;
1063 double v2 = 20.6 * 20.6;
1064 double f2 = 1000.0 * 1000.0;
1065 double v1000 = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1066 double valeur = 0.0;
1067 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1069 f2 = tabFreqExact[i] * tabFreqExact[i];
1070 valeur = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1071 valeur = 20 * log10(valeur / v1000);
1072 s._module[i] = valeur;
1084 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1086 s._module[i] =
c / tabFreqExact[i];
1097 const double seuil = 315;
1098 double a = NAN, b = NAN,
c = NAN, d = NAN, e = NAN, ab = NAN, de = NAN, diffG = NAN, diffD = NAN,
1099 freq = NAN, tolerence = NAN;
1106 for (
unsigned int i = 5; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1108 ab = 10 * ::log10(((::pow(10, a / 10.0) + ::pow(10, b / 10.0)) / 2.0));
1109 de = 10 * ::log10(((::pow(10, d / 10.0) + ::pow(10, e / 10.0)) / 2.0));
1117 if ((diffG > tolerence) && (diffD > tolerence))
1147 <<
"type=" <<
s.getType() <<
", state=" <<
s.getEtat() <<
"]" << std::endl;
1149 for (
unsigned i = 0; i <
s.getNbValues(); ++i)
1151 os <<
s.getTabValReel()[i] <<
", ";
1153 os <<
")" << std::endl;
1161 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1169 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1171 _phase[i] = defaultValue.imag();
1183 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++)
1206 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1230 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1243 if ((OSpectre::operator!=(other)))
1248 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1269 std::complex<double> z1;
1270 std::complex<double> z2;
1271 std::complex<double> z3;
1272 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1278 s._module[i] = std::abs(z3);
1279 s._phase[i] = std::arg(z3);
1292 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1308 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1322 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1324 s._module[i] =
_module[i] * coefficient;
1338 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1355 setValue(freq, cplx.real(), cplx.imag());
1366 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1374 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1383 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1385 s.getTabValReel()[i] =
_phase[i];
1393 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1403 double module = NAN, phase = NAN, reel = NAN, imag = NAN;
1407 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1411 module =
::sqrt(reel * reel + imag * imag);
1412 phase = atan2(imag, reel);
1413 s._module[i] = module;
1414 s._phase[i] = phase;
1422 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1439 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1448 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1456 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1467 for (i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1471 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_OCT_NB_ELMT);
1472 for (i = decalage; i < maxInd; i++)
1474 _module[i] = valeurs[i - decalage];
1494 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1507 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1537 std::ostringstream oss;
1538 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectreOctave";
1539 assert(
false && oss.str().c_str());
1547 assert(
false &&
"Invalid OSpectreOctave object during conversion");
1557 if ((OSpectreAbstract::operator!=(other)))
1561 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1594 for (
int i = 0; i < (int)TY_SPECTRE_OCT_NB_ELMT; i++, indice += 3)
1596 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), indice + 1 - 18));
1598 return tabFreqExact;
1612 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1621 std::map<double, int> mapFI;
1623 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.