Mercurial > hg > svcore
changeset 142:0ba66b160a02
* Add frequency plot to window shape preference -- just because...
* Fix some window shapes
author | Chris Cannam |
---|---|
date | Mon, 24 Jul 2006 14:36:35 +0000 |
parents | 4f26f623a8bc |
children | 0f0c9cf65d5e |
files | base/Preferences.cpp base/Window.h |
diffstat | 2 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/base/Preferences.cpp Fri Jul 21 16:03:42 2006 +0000 +++ b/base/Preferences.cpp Mon Jul 24 14:36:35 2006 +0000 @@ -93,7 +93,7 @@ if (name == "Window Type") { if (min) *min = int(RectangularWindow); - if (max) *max = int(ParzenWindow); + if (max) *max = int(BlackmanHarrisWindow); return int(m_windowType); } @@ -117,6 +117,8 @@ case BlackmanWindow: return tr("Blackman"); case GaussianWindow: return tr("Gaussian"); case ParzenWindow: return tr("Parzen"); + case NuttallWindow: return tr("Nuttall"); + case BlackmanHarrisWindow: return tr("Blackman-Harris"); } } return "";
--- a/base/Window.h Fri Jul 21 16:03:42 2006 +0000 +++ b/base/Window.h Mon Jul 24 14:36:35 2006 +0000 @@ -27,7 +27,9 @@ HanningWindow, BlackmanWindow, GaussianWindow, - ParzenWindow + ParzenWindow, + NuttallWindow, + BlackmanHarrisWindow }; template <typename T> @@ -46,7 +48,7 @@ encache(); return *this; } - virtual ~Window() { delete m_cache; } + virtual ~Window() { delete[] m_cache; } void cut(T *src) const { cut(src, src); } void cut(T *src, T *dst) const { @@ -64,6 +66,7 @@ T *m_cache; void encache(); + void cosinewin(T *, T, T, T, T); }; template <typename T> @@ -90,28 +93,20 @@ break; case HammingWindow: - for (i = 0; i < n; ++i) { - mult[i] *= (0.54 - 0.46 * cos(2 * M_PI * i / n)); - } + cosinewin(mult, 0.54, 0.46, 0.0, 0.0); break; case HanningWindow: - for (i = 0; i < n; ++i) { - mult[i] *= (0.50 - 0.50 * cos(2 * M_PI * i / n)); - } + cosinewin(mult, 0.50, 0.50, 0.0, 0.0); break; case BlackmanWindow: - for (i = 0; i < n; ++i) { - mult[i] *= (0.42 - 0.50 * cos(2 * M_PI * i / n) - + 0.08 * cos(4 * M_PI * i / n)); - } + cosinewin(mult, 0.42, 0.50, 0.08, 0.0); break; case GaussianWindow: for (i = 0; i < n; ++i) { - mult[i] *= exp(-(pow(i - (n-1)/2.0, 2) / - (2 * pow(0.25 * n, 2)))); // sd = 0.25 + mult[i] *= pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2)); } break; @@ -129,11 +124,31 @@ mult[i] *= m; mult[N-i] *= m; } - } + break; + } + + case NuttallWindow: + cosinewin(mult, 0.3635819, 0.4891775, 0.1365995, 0.0106411); break; + + case BlackmanHarrisWindow: + cosinewin(mult, 0.35875, 0.48829, 0.14128, 0.01168); + break; } m_cache = mult; } +template <typename T> +void Window<T>::cosinewin(T *mult, T a0, T a1, T a2, T a3) +{ + int n = int(m_size); + for (int i = 0; i < n; ++i) { + mult[i] *= (a0 + - a1 * cos(2 * M_PI * i / n) + + a2 * cos(4 * M_PI * i / n) + - a3 * cos(6 * M_PI * i / n)); + } +} + #endif