29#ifndef signalWindows_hpp
30#define signalWindows_hpp
33#include "../math/constants.hpp"
52template <
typename 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 ) ) );
93template <
typename realT>
94void tukey( std::vector<realT> &filt,
98 tukey( filt.data(), filt.size(), alpha );
94void tukey( std::vector<realT> &filt, {
…}
108template <
typename realT>
117 for(
size_t n = 0; n < N; ++n )
119 filt[n] = a0 - a1 * cos( 2 * pi * n / N );
130template <
typename 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 );
153template <
typename 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 );
178template <
typename realT>
183 genCosine<realT>( filt, N, 0.5, 0.5 );
196template <
typename realT>
197void hann( std::vector<realT> &filt )
199 hann( filt.data(), filt.size() );
197void hann( std::vector<realT> &filt ) {
…}
210template <
typename realT>
215 genCosine<realT>( filt, N, 25.0 / 46.0, 1.0 - 25.0 / 46.0 );
228template <
typename realT>
231 hamming( filt.data(), filt.size() );
241template <
typename realT>
246 genCosine<realT>( filt, N, 0.42, 0.5, 0.08 );
258template <
typename realT>
261 blackman( filt.data(), filt.size() );
271template <
typename realT>
276 genCosine<realT>( filt, N, 0.42659, 0.49656, 0.076849 );
286template <
typename realT>
299template <
typename realT>
304 genCosine<realT>( filt, N, 0.355768, 0.487396, 0.144232, 0.012604 );
316template <
typename realT>
319 nuttal( filt.data(), filt.size() );
329template <
typename realT>
334 genCosine<realT>( filt, N, 0.3635819, 0.4891775, 0.1365995, 0.0106411 );
346template <
typename realT>
362template <
typename realT>
376 realT rad = 0.5 * ( D - 1.0 );
380 for(
int cc = 0; cc < cols; ++cc )
382 realT y = ( (realT)cc ) - yc;
383 for(
int rr = 0; rr < rows; ++rr )
385 realT x = ( (realT)rr ) - xc;
387 realT r = sqrt( x * x + y * y );
392 filt[cc * rows + rr] = 0.0;
394 else if( rad + r > ( D - 1 ) * ( 1 - 0.5 * alpha ) && alpha > 0. )
401 filt[cc * rows + rr] =
402 0.5 * ( 1.0 + cos( pi * ( 2. * ( dr ) / ( alpha * ( D - 1 ) ) - 2. / alpha + 1.0 ) ) );
406 filt[cc * rows + rr] = 1.0;
426template <
typename arrT>
428 typename arrT::Scalar D,
429 typename arrT::Scalar alpha,
431 typename arrT::Scalar xc,
432 typename arrT::Scalar yc
435 tukey2d( filt.data(), filt.rows(), filt.cols(), D, alpha, xc, yc );
450template <
typename realT>
462 realT rad = 0.5 * ( D - 1.0 );
464 int Z = ( 1 - eps ) * rad + 1.0;
468 for(
int cc = 0; cc < cols; ++cc )
470 realT y = ( (realT)cc ) - yc;
471 for(
int rr = 0; rr < rows; ++rr )
473 realT x = ( (realT)rr ) - xc;
475 realT r = sqrt( x * x + y * y );
477 realT z = ( r - eps * ( rad ) );
480 if( r > rad + 0.5 || r < eps * rad )
482 filt[cc * rows + rr] = 0.0;
484 else if( z <= 0.5 * alpha * ( Z - 1 ) && alpha > 0 )
486 filt[cc * rows + rr] = 0.5 * ( 1.0 + cos( pi * ( 2. * z / ( alpha * ( Z - 1 ) ) - 1.0 ) ) );
488 else if( z > ( Z - 1 ) * ( 1. - 0.5 * alpha ) && alpha > 0 )
490 z = z * ( ( Z - 0.5 ) / Z );
493 filt[cc * rows + rr] =
494 0.5 * ( 1.0 + cos( pi * ( 2. * ( z ) / ( alpha * ( Z - 1 ) ) - 2. / alpha + 1.0 ) ) );
498 filt[cc * rows + rr] = 1.0;
518template <
typename arrT>
520 typename arrT::Scalar D,
521 typename arrT::Scalar eps,
522 typename arrT::Scalar alpha,
524 typename arrT::Scalar xc,
525 typename arrT::Scalar yc
528 return tukey2dAnnulus( filt, filt.rows(), filt.cols(), D, eps, alpha, xc, yc );
541template <
typename realT>
556 realT W2 = 0.5 * ( W - 1.0 );
557 realT H2 = 0.5 * ( H - 1.0 );
561 for(
int cc = 0; cc < cols; ++cc )
563 realT y = fabs( ( (realT)cc ) - yc );
567 for(
int rr = 0; rr < rows; ++rr )
569 filt[cc * rows + rr] = 0;
574 for(
int rr = 0; rr < rows; ++rr )
576 realT x = fabs( ( (realT)rr ) - xc );
580 filt[cc * rows + rr] = 0;
583 else if( ( W2 + x > ( W - 1 ) * ( 1 - 0.5 * alpha ) ) && ( H2 + x > ( H - 1 ) * ( 1 - 0.5 * alpha ) ) &&
595 filt[cc * rows + rr] =
596 0.5 * ( 1.0 + cos( pi * ( 2. * ( dx ) / ( alpha * ( W - 1 ) ) - 2. / alpha + 1.0 ) ) );
597 filt[cc * rows + rr] *=
598 0.5 * ( 1.0 + cos( pi * ( 2. * ( dy ) / ( alpha * ( H - 1 ) ) - 2. / alpha + 1.0 ) ) );
602 filt[cc * rows + rr] = 1.0;
constexpr floatT six_fifths()
Return 6/5 in the specified precision.
void nuttal(realT *filt, size_t N)
The Nuttal Window.
void genCosine(realT *filt, size_t N, realT a0, realT a1)
The generalized 2 parameter cosine Window.
void tukey(realT *filt, int N, realT alpha)
The Tukey Window.
void blackmanNuttal(realT *filt, size_t N)
The Blackman-Nuttal Windwo.
void blackman(realT *filt, size_t N)
The Blackman Window.
void exactBlackman(realT *filt, size_t N)
The Exact Blackman Window.
void hamming(realT *filt, int N)
The Hamming Window.
void hann(realT *filt, int N)
The Hann Window.
void tukey2d(realT *filt, int rows, int cols, realT D, realT alpha, realT xc, realT yc)
Create a 2-D Tukey window.
void tukey2dAnnulus(realT *filt, int rows, int cols, realT D, realT eps, realT alpha, realT xc, realT yc)
Create a 2-D Tukey window on an annulus.
void tukey2dSquare(realT *filt, int rows, int cols, realT W, realT H, realT alpha, realT xc, realT yc)
Create a 2-D Tukey window on a rectangle.