Main Page · Modules · All Classes · Class Hierarchy
MASoundAdvancedAnalyzer.cpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #include "MASoundAdvancedAnalyzer.hpp"
23 
24 #include "core/MAContainerStatistics.hpp"
25 #include "MASoundAnalyzerPrivate.hpp"
26 
27 #include <MCSampleStatistics.hpp>
28 
29 MASoundAdvancedAnalyzer::MASoundAdvancedAnalyzer(unsigned int frequency, unsigned int sliding_window_limit) :
30  MASoundBasicAnalyzer(frequency)
31 {
32  SlidingWindowLimit = sliding_window_limit;
33 }
34 
35 
36 MASoundAdvancedAnalyzer::~MASoundAdvancedAnalyzer()
37 {
38 }
39 
40 
42 {
43  MC::FloatList NewVector;
44 
45  // The horizontal features have not been committed yet.
46  if (unlikely(FeatureNamesReady && FeatureNames.size() < FeatureVectors[0].size()))
47  FeatureNamesReady = false;
48 
49  for (unsigned int i = 0; i < SlidingWindow[0].size(); ++i)
50  {
51  MC::FloatList Vector = MCGetTableColumn<MC::FloatList>(SlidingWindow, i);
52 
53 // MCMergeContainers(NewVector, MAChebyshevPolyCoeffFromContainer(Vector, 5, -1, 1));
54 // for (int i1 = 0; i1 < 5; ++i1)
55 // MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Chebyshev"+MCToStr(i1))
56 // if (Vector.size() == 8)
57 // MCMergeContainers(NewVector, MAFFTComponentsFromContainer(Vector)[0]);
58 // else
59 // MCMergeContainers(NewVector, MC::FloatList(5, 0));
60 // for (int i1 = 0; i1 < 5; ++i1)
61 // MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Fft"+MCToStr(i1))
62  float Minimum = MCCalculateColumnStatInTable(SlidingWindow, i, *new MCMinimum<float>);
63  float Maximum = MCCalculateColumnStatInTable(SlidingWindow, i, *new MCMaximum<float>);
64  float Mean = MCCalculateColumnStatInTable(SlidingWindow, i, *new MCArithmeticMean<float>);
65 
66  NewVector.push_back(Minimum);
67  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Min")
68  NewVector.push_back(Maximum);
69  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Max")
70  NewVector.push_back(Maximum-Minimum); // Min-max range
71  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Range")
72  NewVector.push_back(MCCalculateColumnStatInTable(SlidingWindow, i, *new MCIqr<float>));
73  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Iqr")
74  NewVector.push_back(Mean);
75  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-AritMean")
76  NewVector.push_back(SlidingWindow.back()[i]-Mean);
77  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-AritMeanDiff")
78  NewVector.push_back(MCCalculateColumnStatInTable(SlidingWindow, i, *new MCAbsoluteSum<float>));
79  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-AbsSum")
80  NewVector.push_back(MCCalculateColumnStatInTable(SlidingWindow, i, *new MCLogarithmicSquareSum<float>));
81  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-LogSquareSum")
82  NewVector.push_back(MCCalculateColumnStatInTable(SlidingWindow, i, *new MCPower<float>));
83  MA_ANALYZER_ADD_FEATURE_NAME_STR(FeatureNames[i]+"-Power")
84  }
85  if (unlikely(!FeatureNamesReady))
86  {
87  FeatureNamesReady = true;
88  if (FeatureNames.size() != FeatureVectors[0].size())
89  {
90  MC_ERROR("Feature vector size and feature name count are different (%d != %d)",
91  (int)FeatureVectors[0].size(), (int)FeatureNames.size());
92  }
93  }
94  return NewVector;
95 }
float MCCalculateColumnStatInTable(const std::vector< std::vector< T > > &table, int column, MCSampleStatistic< T > &statistic)
Calculate a statistic over a column in a table.
Absolute sum statistic.
Power statistic for signals.
int SlidingWindowLimit
Sliding window count.
Minimum statistic.
#define MC_ERROR(...)
Error macro.
Definition: MCLog.hpp:45
bool FeatureNamesReady
Whether the feature names are defined.
Definition: MAAnalyzer.hpp:137
MASoundAdvancedAnalyzer(unsigned int frequency, unsigned int sliding_window_limit)
Class constructor.
MC::FloatTable FeatureVectors
Feature vectors.
Interquartile range statistic.
MC::StringList FeatureNames
Feature names.
Definition: MAAnalyzer.hpp:135
MC::FloatTable SlidingWindow
Sliding window of feature vectors.
Maximum statistic.
Logarithmic square sum statistic.
Sound analyzer class.
virtual MC::FloatList CalculateHorizontalFeatures() override
Calculate horizontal features for the feature vectors.
Arithmetic mean statistic.