29 #ifndef signalWindows_hpp
30 #define signalWindows_hpp
33 #include "../math/constants.hpp"
52 template<
typename realT>
58 constexpr realT
pi = math::pi<realT>();
60 realT lim1 = alpha*(N-1.0)/2.0;
61 realT lim2 = (N-1.0)*(1.0-0.5*alpha);
63 for(
int ii=0; ii<N; ++ii)
66 if(ii < lim1 && alpha > 0.)
68 filt[ii] = 0.5*(1.0 + cos(
pi * ( 2.*(ii)/(alpha*(N-1)) - 1.0) ));
70 else if(ii > lim2 && alpha > 0.)
72 filt[ii] = 0.5*(1.0 + cos(
pi * ( 2.*(ii)/(alpha*(N-1)) - 2./alpha + 1.0) ));
93 template<
typename realT>
94 void tukey( std::vector<realT> & filt,
98 tukey(filt.data(), filt.size(), alpha);
108 template<
typename realT>
115 constexpr realT
pi = math::pi<realT>();
117 for(
size_t n=0; n<N; ++n)
119 filt[n] = a0 - a1*cos(2*
pi*n/N);
130 template<
typename realT>
138 constexpr realT
pi = math::pi<realT>();
140 for(
size_t n=0; n<N; ++n)
142 filt[n] = a0 - a1*cos(2*
pi*n/N) + a2*cos(4*
pi*n/N);
153 template<
typename realT>
162 constexpr realT
pi = math::pi<realT>();
164 for(
size_t n=0; n<N; ++n)
166 filt[n] = a0 - a1*cos(2*
pi*n/N) + a2*cos(4*
pi*n/N) - a3*cos(6*
pi*n/N);
178 template<
typename realT>
183 genCosine<realT>(filt, N, 0.5, 0.5);
196 template<
typename realT>
197 void hann( std::vector<realT> & filt )
199 hann(filt.data(), filt.size());
210 template<
typename realT>
215 genCosine<realT>(filt, N, 25.0/46.0, 1.0-25.0/46.0);
228 template<
typename realT>
231 hamming(filt.data(), filt.size());
241 template<
typename realT>
246 genCosine<realT>(filt, N, 0.42, 0.5, 0.08);
258 template<
typename realT>
271 template<
typename realT>
276 genCosine<realT>(filt, N, 0.42659, 0.49656, 0.076849);
286 template<
typename realT>
299 template<
typename realT>
304 genCosine<realT>(filt, N, 0.355768, 0.487396, 0.144232, 0.012604);
316 template<
typename realT>
319 nuttal(filt.data(), filt.size());
329 template<
typename realT>
334 genCosine<realT>(filt, N, 0.3635819, 0.4891775, 0.1365995, 0.0106411 );
346 template<
typename realT>
362 template<
typename realT>
375 realT rad = 0.5*(D-1.0);
377 realT
pi = math::pi<realT>();
379 for(
int cc=0; cc<cols; ++cc)
381 realT y = ( (realT) cc) - yc;
382 for(
int rr=0; rr<rows; ++rr)
384 realT x = ( (realT) rr) - xc;
386 realT r = sqrt(x*x + y*y);
391 filt[cc*rows + rr] = 0.0;
393 else if(rad + r > (D-1)*(1-0.5*alpha) && alpha > 0.)
397 if(dr > D-1) dr = D-1;
399 filt[cc*rows + rr] = 0.5*(1.0 + cos(
pi * ( 2.*(dr)/(alpha*(D-1)) - 2./alpha + 1.0) ));
403 filt[cc*rows + rr] = 1.0;
423 template<
typename arrT>
425 typename arrT::Scalar D,
426 typename arrT::Scalar alpha,
427 typename arrT::Scalar xc,
428 typename arrT::Scalar yc
431 tukey2d(filt.data(), filt.rows(), filt.cols(), D, alpha, xc, yc);
446 template<
typename realT>
457 realT rad = 0.5*(D-1.0);
459 int Z = (1-eps)*rad+1.0;
461 realT
pi = math::pi<realT>();
463 for(
int cc=0; cc<cols; ++cc)
465 realT y = ( (realT) cc) - yc;
466 for(
int rr=0; rr<rows; ++rr)
468 realT x = ( (realT) rr) - xc;
470 realT r = sqrt(x*x + y*y);
472 realT z = (r - eps*(rad));
475 if(r > rad + 0.5 || r < eps*rad)
477 filt[cc*rows + rr] = 0.0;
479 else if(z <= 0.5*alpha*(Z-1) && alpha > 0)
481 filt[cc*rows + rr] = 0.5*(1.0 + cos(
pi*(2.*z/(alpha*(Z-1)) -1.0) ));
483 else if(z > (Z-1)*(1.-0.5*alpha) && alpha > 0)
487 filt[cc*rows + rr] = 0.5*(1.0 + cos(
pi* ( 2.*(z)/(alpha*(Z-1)) - 2./alpha + 1.0) ));
491 filt[cc*rows + rr] = 1.0;
511 template<
typename arrT>
513 typename arrT::Scalar D,
514 typename arrT::Scalar eps,
515 typename arrT::Scalar alpha,
516 typename arrT::Scalar xc,
517 typename arrT::Scalar yc
520 return tukey2dAnnulus(filt, filt.rows(), filt.cols(), D, eps, alpha, xc, yc);
constexpr T pi()
Get the value of pi.
void hann(std::vector< realT > &filt)
The Hann Window.
void genCosine(realT *filt, size_t N, realT a0, realT a1, realT a2, realT a3)
The generalized 4 parameter cosine Window.
void blackman(std::vector< realT > &filt)
The Blackman Window.
void tukey(std::vector< realT > &filt, realT alpha)
The Tukey Window.
void hamming(std::vector< realT > &filt)
The Hamming Window.
void exactBlackman(realT *filt, size_t N)
The Exact Blackman Window.
void blackmanNuttal(std::vector< realT > &filt)
The Blackman-Nuttal Windwo.
void nuttal(std::vector< realT > &filt)
The Nuttal Window.
void tukey2d(arrT &filt, typename arrT::Scalar D, typename arrT::Scalar alpha, typename arrT::Scalar xc, typename arrT::Scalar yc)
Create a 2-D Tukey window.
void tukey2dAnnulus(arrT &filt, typename arrT::Scalar D, typename arrT::Scalar eps, typename arrT::Scalar alpha, typename arrT::Scalar xc, typename arrT::Scalar yc)
Create a 2-D Tukey window on an annulus.