comparison data/model/FFTModel.cpp @ 1092:70f18770b72d simple-fft-model

Normalization function
author Chris Cannam
date Fri, 12 Jun 2015 18:20:09 +0100
parents bdebff3265ae
children 44b079427b36
comparison
equal deleted inserted replaced
1091:bdebff3265ae 1092:70f18770b72d
107 107
108 float 108 float
109 FFTModel::getMaximumMagnitudeAt(int x) const 109 FFTModel::getMaximumMagnitudeAt(int x) const
110 { 110 {
111 Column col(getColumn(x)); 111 Column col(getColumn(x));
112 auto itr = max_element(col.begin(), col.end()); 112 float max = 0.f;
113 if (itr == col.end()) return 0.f; 113 for (int i = 0; i < col.size(); ++i) {
114 else return *itr; 114 if (col[i] > max) max = col[i];
115 }
116 return max;
115 } 117 }
116 118
117 float 119 float
118 FFTModel::getPhaseAt(int x, int y) const 120 FFTModel::getPhaseAt(int x, int y) const
119 { 121 {
148 } 150 }
149 151
150 bool 152 bool
151 FFTModel::getNormalizedMagnitudesAt(int x, float *values, int minbin, int count) const 153 FFTModel::getNormalizedMagnitudesAt(int x, float *values, int minbin, int count) const
152 { 154 {
153 //!!! WRONG 155 if (!getMagnitudesAt(x, values, minbin, count)) return false;
154 return getMagnitudesAt(x, values, minbin, count); 156 if (count == 0) count = getHeight();
157 float max = 0.f;
158 for (int i = 0; i < count; ++i) {
159 if (values[i] > max) max = values[i];
160 }
161 if (max > 0.f) {
162 for (int i = 0; i < count; ++i) {
163 values[i] /= max;
164 }
165 }
166 return true;
155 } 167 }
156 168
157 bool 169 bool
158 FFTModel::getPhasesAt(int x, float *values, int minbin, int count) const 170 FFTModel::getPhasesAt(int x, float *values, int minbin, int count) const
159 { 171 {