From 171043d6daec26ede0c4d6584d7a70eea214f0fe Mon Sep 17 00:00:00 2001 From: K Date: Tue, 15 Jan 2008 22:52:14 +0530 Subject: [PATCH] Add Dolph Chebyshev window. Add the chebwin function to evaluate the coefficients of the Dolph-Chebyshev Window, with tests. The tests check the values output by the Dolph-Chebyshev window function for lengths 32 and 33 for 50 dB suppression and for lengths 127 and 128 at 25 dB suppression. Signed-off-by: K --- itpp/signal/window.cpp | 39 ++++++++++++++++++++++++++++++++++++++- itpp/signal/window.h | 18 ++++++++++++++++++ tests/window_test.cpp | 5 +++++ tests/window_test.ref | 4 ++++ 4 files changed, 65 insertions(+), 1 deletions(-) diff --git a/itpp/signal/window.cpp b/itpp/signal/window.cpp index 0bf4be5..cfe27a8 100644 --- a/itpp/signal/window.cpp +++ b/itpp/signal/window.cpp @@ -27,7 +27,12 @@ */ #include - +#include +#include +#include +#include +#include +#include namespace itpp { @@ -106,6 +111,38 @@ namespace itpp { return t; } + vec chebwin(int n, double at) + { + it_assert((n > 0), "chebwin(): need a positive order n!"); + if (n == 1) { + return vec("1"); + } + + at = at < 0 ? -at : at; + // compute the parameter beta + double beta = std::cosh(::acosh(pow10(at/20.)) / (n-1)); + vec k = (pi / n) * linspace(0, n - 1, n); + vec cos_k = cos(k); + // find the window's DFT coefficients + vec p = cheb(n - 1, beta * cos_k); + + // Appropriate IDFT and filling up + // depending on even/odd n + vec w; // the window vector. + if (is_even(n)) { + w = ifft_real(to_cvec(elem_mult(p, cos_k), elem_mult(p,-sin(k)))); + int half_length = n / 2 + 1; + w = w / w(1); + w = concat(reverse(w.left(half_length)), w.mid(2, half_length - 2)); + } + else { + w = ifft_real(to_cvec(p)); + int half_length = (n + 1) / 2; + w = w.left(half_length) / w(0); + w = concat(reverse(w), w.right(half_length - 1)); + } + return w; + } } // namespace itpp diff --git a/itpp/signal/window.h b/itpp/signal/window.h index aad510f..12f5205 100644 --- a/itpp/signal/window.h +++ b/itpp/signal/window.h @@ -105,6 +105,24 @@ namespace itpp { sqrt_win(n) = sqrt(triang(n)) */ vec sqrt_win(int n); + + /*! \brief Dolph-Chebyshev Window + + + The length \c n Dolph-Chebyshev window is a vector \f$w\f$ whose \f$i\f$th + transform component is given by + \f[ + W[k] = \frac{T_M\left(\beta \cos\left(\frac{\pi k}{M}\right) + \right)}{T_M(\beta)},k = 0, 1, 2, \ldots, M - 1 + \f] + + where \c T_n(x) is the order \c n Chebyshev polynomial of the first kind. + \param n Length of the Doplh-Chebyshev window. + \param at Attenutation of side lobe (in dB). + \return Symmetric length \c n Doplh-Chebyshev window. + \author + */ + vec chebwin(int n, double at); //!@} diff --git a/tests/window_test.cpp b/tests/window_test.cpp index 31fcff5..6d3fb15 100644 --- a/tests/window_test.cpp +++ b/tests/window_test.cpp @@ -56,5 +56,10 @@ int main(void) cout << "triang(32) = " << round_to_zero(triang(32)) << endl; cout << "triang(128) = " << round_to_zero(triang(128)) << endl; + cout << "chebwin(32) = " << round_to_zero(chebwin(32, 50)) << endl; + cout << "chebwin(33) = " << round_to_zero(chebwin(33, 20)) << endl; + cout << "chebwin(127) = " << round_to_zero(chebwin(127, 25)) << endl; + cout << "chebwin(128) = " << round_to_zero(chebwin(128, 25)) << endl; + return 0; } diff --git a/tests/window_test.ref b/tests/window_test.ref index 7b1793c..e988967 100644 --- a/tests/window_test.ref +++ b/tests/window_test.ref @@ -11,3 +11,7 @@ blackman(32) = [0 0.0037516543 0.015638448 0.0374027 0.071464607 0.12028646 0.18 blackman(128) = [0 0.00022048463 0.00088426938 0.0019983131 0.0035741016 0.0056274806 0.008178424 0.011250741 0.014871722 0.019071735 0.023883764 0.029342905 0.035485826 0.042350182 0.049974012 0.058395105 0.067650362 0.077775135 0.08880258 0.100763 0.11368324 0.12758601 0.14248936 0.15840611 0.17534333 0.19330184 0.21227586 0.23225262 0.25321203 0.27512651 0.29796076 0.32167173 0.34620856 0.37151262 0.3975177 0.42415015 0.45132921 0.47896731 0.50697053 0.53523907 0.56366781 0.59214691 0.62056245 0.64879721 0.67673135 0.70424322 0.73121023 0.7575096 0.7830193 0.80761885 0.83119025 0.85361875 0.87479376 0.89460963 0.91296646 0.9297708 0.94493641 0.95838489 0.97004626 0.97985951 0.98777306 0.99374518 0.99774428 0.99974914 0.99974914 0.99774428 0.99374518 0.98777306 0.97985951 0.97004626 0.95838489 0.94493641 0.9297708 0.91296646 0.89460963 0.87479376 0.85361875 0.83119025 0.80761885 0.7830193 0.7575096 0.73121023 0.70424322 0.67673135 0.64879721 0.62056245 0.59214691 0.56366781 0.53523907 0.50697053 0.47896731 0.45132921 0.42415015 0.3975177 0.37151262 0.34620856 0.32167173 0.29796076 0.27512651 0.25321203 0.23225262 0.21227586 0.19330184 0.17534333 0.15840611 0.14248936 0.12758601 0.11368324 0.100763 0.08880258 0.077775135 0.067650362 0.058395105 0.049974012 0.042350182 0.035485826 0.029342905 0.023883764 0.019071735 0.014871722 0.011250741 0.008178424 0.0056274806 0.0035741016 0.0019983131 0.00088426938 0.00022048463 0] triang(32) = [0.03125 0.09375 0.15625 0.21875 0.28125 0.34375 0.40625 0.46875 0.53125 0.59375 0.65625 0.71875 0.78125 0.84375 0.90625 0.96875 0.96875 0.90625 0.84375 0.78125 0.71875 0.65625 0.59375 0.53125 0.46875 0.40625 0.34375 0.28125 0.21875 0.15625 0.09375 0.03125] triang(128) = [0.0078125 0.0234375 0.0390625 0.0546875 0.0703125 0.0859375 0.1015625 0.1171875 0.1328125 0.1484375 0.1640625 0.1796875 0.1953125 0.2109375 0.2265625 0.2421875 0.2578125 0.2734375 0.2890625 0.3046875 0.3203125 0.3359375 0.3515625 0.3671875 0.3828125 0.3984375 0.4140625 0.4296875 0.4453125 0.4609375 0.4765625 0.4921875 0.5078125 0.5234375 0.5390625 0.5546875 0.5703125 0.5859375 0.6015625 0.6171875 0.6328125 0.6484375 0.6640625 0.6796875 0.6953125 0.7109375 0.7265625 0.7421875 0.7578125 0.7734375 0.7890625 0.8046875 0.8203125 0.8359375 0.8515625 0.8671875 0.8828125 0.8984375 0.9140625 0.9296875 0.9453125 0.9609375 0.9765625 0.9921875 0.9921875 0.9765625 0.9609375 0.9453125 0.9296875 0.9140625 0.8984375 0.8828125 0.8671875 0.8515625 0.8359375 0.8203125 0.8046875 0.7890625 0.7734375 0.7578125 0.7421875 0.7265625 0.7109375 0.6953125 0.6796875 0.6640625 0.6484375 0.6328125 0.6171875 0.6015625 0.5859375 0.5703125 0.5546875 0.5390625 0.5234375 0.5078125 0.4921875 0.4765625 0.4609375 0.4453125 0.4296875 0.4140625 0.3984375 0.3828125 0.3671875 0.3515625 0.3359375 0.3203125 0.3046875 0.2890625 0.2734375 0.2578125 0.2421875 0.2265625 0.2109375 0.1953125 0.1796875 0.1640625 0.1484375 0.1328125 0.1171875 0.1015625 0.0859375 0.0703125 0.0546875 0.0390625 0.0234375 0.0078125] +chebwin(32) = [0.050664426 0.066069435 0.10497972 0.15478981 0.21565675 0.28701938 0.36753634 0.45508472 0.5468251 0.63933249 0.72878615 0.81120512 0.88271105 0.93979671 0.97957695 1 1 0.97957695 0.93979671 0.88271105 0.81120512 0.72878615 0.63933249 0.5468251 0.45508472 0.36753634 0.28701938 0.21565675 0.15478981 0.10497972 0.066069435 0.050664426] +chebwin(33) = [1.5667761 0.436121 0.4911289 0.5465011 0.60155649 0.65559419 0.70790584 0.75778846 0.80455735 0.84755887 0.8861828 0.91987396 0.94814295 0.97057557 0.98684093 0.99669794 1 0.99669794 0.98684093 0.97057557 0.94814295 0.91987396 0.8861828 0.84755887 0.80455735 0.75778846 0.70790584 0.65559419 0.60155649 0.5465011 0.4911289 0.436121 1.5667761] +chebwin(127) = [2.8062784 0.28379647 0.29780485 0.31203524 0.32647609 0.34111535 0.3559405 0.37093856 0.38609612 0.40139932 0.41683391 0.43238525 0.44803833 0.46377779 0.47958794 0.49545281 0.51135612 0.52728135 0.54321176 0.55913036 0.57502004 0.59086348 0.60664326 0.62234187 0.63794169 0.65342508 0.66877439 0.68397195 0.69900016 0.71384147 0.72847843 0.7428937 0.75707013 0.77099071 0.78463866 0.79799743 0.81105075 0.82378262 0.83617737 0.84821968 0.85989459 0.87118755 0.88208441 0.89257149 0.90263557 0.91226391 0.9214443 0.93016505 0.93841505 0.94618372 0.95346113 0.9602379 0.96650532 0.97225529 0.9774804 0.98217387 0.98632963 0.98994228 0.99300712 0.99552018 0.99747819 0.99887858 0.99971955 1 0.99971955 0.99887858 0.99747819 0.99552018 0.99300712 0.98994228 0.98632963 0.98217387 0.9774804 0.97225529 0.96650532 0.9602379 0.95346113 0.94618372 0.93841505 0.93016505 0.9214443 0.91226391 0.90263557 0.89257149 0.88208441 0.87118755 0.85989459 0.84821968 0.83617737 0.82378262 0.81105075 0.79799743 0.78463866 0.77099071 0.75707013 0.7428937 0.72847843 0.71384147 0.69900016 0.68397195 0.66877439 0.65342508 0.63794169 0.62234187 0.60664326 0.59086348 0.57502004 0.55913036 0.54321176 0.52728135 0.51135612 0.49545281 0.47958794 0.46377779 0.44803833 0.43238525 0.41683391 0.40139932 0.38609612 0.37093856 0.3559405 0.34111535 0.32647609 0.31203524 0.29780485 0.28379647 2.8062784] +chebwin(128) = [2.8276135 0.28370485 0.29760123 0.31171632 0.32603887 0.34055711 0.35525884 0.37013139 0.38516169 0.40033623 0.41564112 0.43106209 0.4465845 0.46219339 0.47787346 0.49360915 0.50938459 0.52518367 0.54099005 0.55678721 0.57255843 0.58828682 0.6039554 0.61954706 0.63504462 0.65043087 0.66568854 0.68080039 0.69574922 0.71051786 0.72508926 0.73944646 0.75357265 0.76745118 0.78106561 0.79439972 0.80743754 0.82016335 0.83256177 0.84461773 0.85631651 0.86764377 0.87858557 0.88912838 0.89925915 0.90896528 0.91823465 0.92705566 0.93541726 0.94330891 0.95072067 0.95764316 0.96406763 0.96998592 0.97539051 0.98027451 0.9846317 0.98845652 0.99174407 0.99449016 0.99669127 0.99834457 0.99944796 1 1 0.99944796 0.99834457 0.99669127 0.99449016 0.99174407 0.98845652 0.9846317 0.98027451 0.97539051 0.96998592 0.96406763 0.95764316 0.95072067 0.94330891 0.93541726 0.92705566 0.91823465 0.90896528 0.89925915 0.88912838 0.87858557 0.86764377 0.85631651 0.84461773 0.83256177 0.82016335 0.80743754 0.79439972 0.78106561 0.76745118 0.75357265 0.73944646 0.72508926 0.71051786 0.69574922 0.68080039 0.66568854 0.65043087 0.63504462 0.61954706 0.6039554 0.58828682 0.57255843 0.55678721 0.54099005 0.52518367 0.50938459 0.49360915 0.47787346 0.46219339 0.4465845 0.43106209 0.41564112 0.40033623 0.38516169 0.37013139 0.35525884 0.34055711 0.32603887 0.31171632 0.29760123 0.28370485 2.8276135] -- 1.5.4.rc3.4.g1633