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;
634 dBVal = 10.0 * log10((val) / coef);
635 s.getTabValReel()[i] = dBVal;
672 s.getTabValReel()[i] = powVal;
681 double valeurGlob = 0.0;
684 valeurGlob = valeurGlob + pow(10, (
s.getTabValReel()[i] / 10));
686 valeurGlob = 10 * log10(valeurGlob);
697 ret =
s.valGlobDBLin();
703 ret =
s.valGlobDBLin();
729 short nbOctValue = 9;
731 for (
short i = 0; i < nbOctValue; i++, indice += 3)
734 s.getTabValReel()[indice] = valeur;
735 s.getTabValReel()[indice + 1] = valeur;
736 s.getTabValReel()[indice + 2] = valeur;
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];
748 short nbOctValue = 9;
755 for (
short i = 0; i < nbOctValue; i++, indice += 3)
758 s.getTabValReel()[indice] = valeur;
759 s.getTabValReel()[indice + 1] = valeur;
760 s.getTabValReel()[indice + 2] = valeur;
764 s.getTabValReel()[0] = 1;
765 s.getTabValReel()[1] = 1;
766 s.getTabValReel()[29] = 1;
767 s.getTabValReel()[30] = 1;
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;
800 unsigned int indiceDepart = 2;
801 unsigned int indice = 0;
803 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
808 s.getTabValReel()[indice] = valeur;
815 unsigned int indiceDepart = 2;
816 unsigned int indice = 0;
823 for (
unsigned int i = indiceDepart; i < TY_SPECTRE_DEFAULT_NB_ELMT - 2; i += 3, indice++)
828 s.getTabValReel()[indice] = valeur;
838 std::cout <<
"Spectrum values: ";
843 std::cout << std::endl;
854 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
862 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
873 for (i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
877 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_DEFAULT_NB_ELMT);
878 for (i = decalage; i < maxInd; i++)
880 _module[i] = valeurs[i - decalage];
901 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
915 sp =
dynamic_cast<const OSpectre*
>(&other);
928 std::ostringstream oss;
929 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectre";
930 assert(
false && oss.str().c_str());
942 if ((OSpectreAbstract::operator!=(other)))
946 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
983 std::map<double, int> mapFI;
985 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
996 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
998 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), i - 18));
1000 return tabFreqExact;
1006 for (
int i = 0; i < (int)TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1008 tabFreqExact.
_module[i] = 1000.0 * pow(pow(10.0, 0.1), i - 18);
1010 return tabFreqExact;
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;
1023 (v1 * f2 * f2) / ((f2 + v1) * (f2 + v2) * ::
sqrt((f2 + v3) * (f2 + v4)));
1024 double valeur = 0.0;
1025 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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;
1039 long v1 = 12200 * 12200;
1040 double v2 = 20.6 * 20.6;
1041 double v3 = 158.5 * 158.5;
1044 double v1000 = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1045 double valeur = 0.0;
1046 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1048 f = tabFreqExact[i];
1050 valeur = (v1 * f2 * f) / ((f2 + v1) * (f2 + v2) * ::
sqrt(f2 + v3));
1051 valeur = 20 * log10(valeur / v1000);
1052 s._module[i] = valeur;
1061 long v1 = 12200 * 12200;
1062 double v2 = 20.6 * 20.6;
1063 double f2 = 1000.0 * 1000.0;
1064 double v1000 = (v1 * f2) / ((f2 + v1) * (f2 + v2));
1065 double valeur = 0.0;
1066 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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;
1083 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1085 s._module[i] =
c / tabFreqExact[i];
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;
1105 for (
unsigned int i = 5; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
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));
1116 if ((diffG > tolerence) && (diffD > tolerence))
1146 <<
"type=" <<
s.getType() <<
", state=" <<
s.getEtat() <<
"]" << std::endl;
1148 for (
unsigned i = 0; i <
s.getNbValues(); ++i)
1150 os <<
s.getTabValReel()[i] <<
", ";
1152 os <<
")" << std::endl;
1160 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1168 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1170 _phase[i] = defaultValue.imag();
1182 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1190 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1205 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1229 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1242 if ((OSpectre::operator!=(other)))
1247 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1268 std::complex<double> z1;
1269 std::complex<double> z2;
1270 std::complex<double> z3;
1271 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1277 s._module[i] = std::abs(z3);
1278 s._phase[i] = std::arg(z3);
1291 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++)
1321 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1323 s._module[i] =
_module[i] * coefficient;
1337 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1354 setValue(freq, cplx.real(), cplx.imag());
1365 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1373 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1382 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1384 s.getTabValReel()[i] =
_phase[i];
1392 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1402 double module = NAN, phase = NAN, reel = NAN, imag = NAN;
1406 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1410 module =
::sqrt(reel * reel + imag * imag);
1411 phase = atan2(imag, reel);
1412 s._module[i] = module;
1413 s._phase[i] = phase;
1421 for (
unsigned int i = 0; i < TY_SPECTRE_DEFAULT_NB_ELMT; i++)
1438 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1447 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1455 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1466 for (i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1470 unsigned int maxInd =
std::min(nbVal + decalage, TY_SPECTRE_OCT_NB_ELMT);
1471 for (i = decalage; i < maxInd; i++)
1473 _module[i] = valeurs[i - decalage];
1493 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1506 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1536 std::ostringstream oss;
1537 oss <<
"Impossible to convert from " << other.
getForm() <<
" to OSpectreOctave";
1538 assert(
false && oss.str().c_str());
1546 assert(
false &&
"Invalid OSpectreOctave object during conversion");
1556 if ((OSpectreAbstract::operator!=(other)))
1560 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1593 for (
int i = 0; i < (int)TY_SPECTRE_OCT_NB_ELMT; i++, indice += 3)
1595 tabFreqExact.push_back(1000.0 * pow(pow(10.0, 0.1), indice + 1 - 18));
1597 return tabFreqExact;
1611 for (
unsigned int i = 0; i < TY_SPECTRE_OCT_NB_ELMT; i++)
1620 std::map<double, int> mapFI;
1622 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.