NMPB08 shared libraries
RoadSurfaceDescription.cpp
Go to the documentation of this file.
00001 
00008 #include "RoadSurfaceDescription.h"
00009 #include <math.h>
00010 
00011 namespace RoadSurfaceDescriptionNMPB
00012 {
00016         RoadSurfaceDescription::RoadSurfaceDescription(void)
00017         {
00018                 // default value from R2 surface type
00019                 _AVL = 20.1;
00020                 _BVL = 55.4;
00021                 _Vref_VL = 90;
00022                 _APL = 20;
00023                 _BPL = 63.4;
00024                 _Vref_PL = 80;
00025         }
00026 
00046         RoadSurfaceDescription::RoadSurfaceDescription(double AVL, double BVL, double Vref_VL, double APL, double BPL, double Vref_PL, const double* spectrum, bool doNormalization)
00047         {
00048                 _AVL = AVL;
00049                 _BVL = BVL;
00050                 _Vref_VL = Vref_VL;
00051                 _APL = APL;
00052                 _BPL = BPL;
00053                 _Vref_PL = Vref_PL;
00054 
00055                 //spectrum
00056                 _spectralDistributionMap.clear();
00057                 if(spectrum == NULL) return ;
00058                 int frequencyNumber = 18;
00059                 int NominalMedianFrequency[] = {100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000};
00060                 for(int i = 0; i < frequencyNumber ; i++)
00061                 {
00062                         _spectralDistributionMap[NominalMedianFrequency[i]] = spectrum[i];
00063                 }
00064 
00065                 if(doNormalization)
00066                 {
00067                         SpectrumNormalization();
00068                 }
00069         }
00070 
00074         void RoadSurfaceDescription::SpectrumNormalization()
00075         {
00076                 if(_spectralDistributionMap.empty()) return;
00077 
00078                 // Sum calculation
00079                 double spectrumSum = 0;
00080                 for (map<int,double>::iterator it = _spectralDistributionMap.begin() ; it != _spectralDistributionMap.end(); it++ )
00081                 {
00082                                 spectrumSum += pow(10.0, it->second / 10.0);
00083                 }
00084 
00085                 // Values modification
00086                 if(spectrumSum <= 0 || spectrumSum == 1) return;
00087                 spectrumSum = 10. * log10(spectrumSum);
00088 
00089                 for (map<int,double>::iterator it = _spectralDistributionMap.begin() ; it != _spectralDistributionMap.end(); it++ )
00090                 {
00091                                 it->second = it->second - spectrumSum;
00092                 }
00093         }
00094 }
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines