summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-19 20:46:56 +0300
committerVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-19 20:46:56 +0300
commit5a3eb9f10863abeea248adb2acf5df44a2b0a048 (patch)
tree26b6675ca93085801ef1f318ebd8efb5fcba261c
parent78225142a8b3c0f95090b089eef32c244ed03551 (diff)
Move normalization from ValueMap to FFT class.
-rw-r--r--src/fft.cpp7
-rw-r--r--src/value-map.cpp5
2 files changed, 8 insertions, 4 deletions
diff --git a/src/fft.cpp b/src/fft.cpp
index 8f94986..2802346 100644
--- a/src/fft.cpp
+++ b/src/fft.cpp
@@ -104,6 +104,11 @@ FFT::Compute(const ComplexWindow& input)
(void *) this->out_,
lhl * sizeof(fftw_complex));
+ /* fftw does not normalize; divide by the window size */
+ for (auto& v : output) {
+ v /= (double)output.size();
+ }
+
return output;
}
@@ -231,4 +236,4 @@ FFT::Crop(const RealWindow& input, double rate, double fmin, double fmax)
/* return corresponding subvector */
return RealWindow(input.begin() + i_fmin, input.begin() + i_fmax);
-} \ No newline at end of file
+}
diff --git a/src/value-map.cpp b/src/value-map.cpp
index 2627ed3..51e3944 100644
--- a/src/value-map.cpp
+++ b/src/value-map.cpp
@@ -49,7 +49,7 @@ RealWindow LinearValueMap::Map(const RealWindow &input)
RealWindow output(n);
for (unsigned int i = 0; i < n; i ++) {
- output[i] = std::clamp<double>(input[i] / n, this->lower_, this->upper_);
+ output[i] = std::clamp<double>(input[i], this->lower_, this->upper_);
output[i] = (output[i] - this->lower_) / (this->upper_ - this->lower_);
}
@@ -67,7 +67,7 @@ RealWindow DecibelValueMap::Map(const RealWindow &input)
RealWindow output(n);
for (unsigned int i = 0; i < n; i ++) {
- output[i] = 20.0 * std::log10(input[i] / n);
+ output[i] = 20.0 * std::log10(input[i]);
output[i] = std::clamp<double>(output[i], this->lower_, this->upper_);
output[i] = (output[i] - this->lower_) / (this->upper_ - this->lower_);
}
@@ -79,4 +79,3 @@ std::string DecibelValueMap::GetUnit() const
{
return "dB" + unit_;
}
-