window.cpp
Go to the documentation of this file.
#include <itpp/base/itcompat.h>
#include <itpp/signal/window.h>
#include <itpp/signal/poly.h>
#include <itpp/base/specmat.h>
#include <itpp/base/converters.h>
#include <itpp/base/math/trig_hyp.h>
#include <itpp/signal/transforms.h>
#include <itpp/base/operators.h>
namespace itpp
{
vec hamming(int n)
{
vec t(n);
if (n == 1)
t(0) = 0.08;
else
for (int i = 0;i < n;i++)
t[i] = (0.54 - 0.46 * std::cos(2.0 * pi * i / (n - 1)));
return t;
}
vec hanning(int n)
{
vec t(n);
for (int i = 0;i < n;i++)
t(i) = 0.5 * (1.0 - std::cos(2.0 * pi * (i + 1) / (n + 1)));
return t;
}
// matlab version
vec hann(int n)
{
vec t(n);
for (int i = 0;i < n;i++)
t(i) = 0.5 * (1.0 - std::cos(2.0 * pi * i / (n - 1)));
return t;
}
vec blackman(int n)
{
vec t(n);
for (int i = 0;i < n;i++)
t(i) = 0.42 - 0.5 * std::cos(2.0 * pi * i / (n - 1)) + 0.08 * std::cos(4.0 * pi * i / (n - 1));
return t;
}
vec triang(int n)
{
vec t(n);
if (n % 2) { // Odd
for (int i = 0; i < n / 2; i++)
t(i) = t(n - i - 1) = 2.0 * (i + 1) / (n + 1);
t(n / 2) = 1.0;
}
else
for (int i = 0; i < n / 2; i++)
t(i) = t(n - i - 1) = (2.0 * i + 1) / n;
return t;
}
vec sqrt_win(int n)
{
vec t(n);
if (n % 2) { // Odd
for (int i = 0; i < n / 2; i++)
t(i) = t(n - i - 1) = std::sqrt(2.0 * (i + 1) / (n + 1));
t(n / 2) = 1.0;
}
else
for (int i = 0; i < n / 2; i++)
t(i) = t(n - i - 1) = std::sqrt((2.0 * i + 1) / n);
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);
vec w(n); // the window vector
// Appropriate IDFT and filling up depending on even/odd n
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.left(half_length) / w(1);
w = concat(reverse(w), w.right(n - half_length));
}
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(n - half_length));
}
return w;
}
} // namespace itpp
itpp::cosh
vec cosh(const vec &x)
Cosine hyperbolic function.
Definition: trig_hyp.h:93
itpp::hamming
vec hamming(int n)
Hamming window.
Definition: window.cpp:43
window.h
Definitions of window functions.
itpp::reverse
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
Definition: matfunc.h:777
itpp::is_even
bool is_even(int x)
Return true if x is an even integer.
Definition: misc.h:122
itpp::chebwin
vec chebwin(int n, double at)
Dolph-Chebyshev window.
Definition: window.cpp:119
itpp::elem_mult
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
Definition: mat.h:1582
itpp::triang
vec triang(int n)
Triangular window.
Definition: window.cpp:87
poly.h
Polynomial functions.
itpp::Vec::right
Vec< Num_T > right(int nr) const
Get the right nr elements from the vector.
Definition: vec.h:1228
itpp::ifft_real
ITPP_EXPORT void ifft_real(const cvec &in, vec &out)
Inverse Real Fast Fourier Transform.
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition: itassert.h:94
itpp::hann
vec hann(int n)
Hanning window compatible with matlab.
Definition: window.cpp:67
itpp::cheb
double cheb(int n, double x)
Chebyshev polynomial of the first kindChebyshev polynomials of the first kind can be defined as follo...
Definition: poly.cpp:195
itpp::sin
vec sin(const vec &x)
Sine function.
Definition: trig_hyp.h:54
converters.h
Definitions of converters between different vector and matrix types.
transforms.h
Fourier, Hadamard, Walsh-Hadamard, and 2D Hadamard transforms - header file.
itpp::pi
const double pi
Constant Pi.
Definition: misc.h:103
itpp::blackman
vec blackman(int n)
Blackman window.
Definition: window.cpp:77
trig_hyp.h
Trigonometric and hyperbolic functions - header file.
itpp::acosh
vec acosh(const vec &x)
Inverse cosine hyperbolic function.
Definition: trig_hyp.cpp:40
operators.h
Definitions of operators for vectors and matricies of different types.
itpp
itpp namespace
Definition: itmex.h:36
itpp::sqrt_win
vec sqrt_win(int n)
Square root window.
Definition: window.cpp:103
itpp::pow10
double pow10(double x)
Calculate ten to the power of x (10^x)
Definition: log_exp.h:68
itcompat.h
IT++ compatibility types and functions.
specmat.h
Definitions of special vectors and matrices.
itpp::linspace
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Definition: specmat.cpp:106
itpp::hanning
vec hanning(int n)
Hanning window.
Definition: window.cpp:56
itpp::sqrt
vec sqrt(const vec &x)
Square root of the elements.
Definition: elem_math.h:123
itpp::to_cvec
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
Definition: converters.h:107
itpp::cos
vec cos(const vec &x)
Cosine function.
Definition: trig_hyp.h:58
itpp::concat
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition: array.h:486

Generated on Sat Sep 30 2017 07:04:09 for IT++ by Doxygen 1.8.13