EMAN2
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
EMAN::Util::KaiserBessel Class Reference

1-D Kaiser-Bessel window function class. More...

#include <util.h>

Inheritance diagram for EMAN::Util::KaiserBessel:
Inheritance graph
[legend]
Collaboration diagram for EMAN::Util::KaiserBessel:
Collaboration graph
[legend]

List of all members.

Classes

class  kbi0_win
 I0 window function object. More...
class  kbsinh_win
 Sinh window function object. More...

Public Member Functions

 KaiserBessel (float alpha_, int K, float r_, float v_, int N_, float vtable_=0.f, int ntable_=5999)
virtual ~KaiserBessel ()
float I0table_maxerror ()
 Compute the maximum error in the table.
vector< float > dump_table ()
virtual float sinhwin (float x) const
 Kaiser-Bessel Sinh window function.
virtual float i0win (float x) const
 Kaiser-Bessel I0 window function.
float i0win_tab (float x) const
 Kaiser-Bessel I0 window function (uses table lookup)
int get_window_size () const
 Return the size of the I0 window.
kbsinh_win get_kbsinh_win ()
 Sinh window function object factory.
kbi0_win get_kbi0_win ()
 I0 window function object factory.

Protected Member Functions

virtual void build_I0table ()
 2*pi*alpha*r*vadjust

Protected Attributes

float alpha
float v
float r
int N
 Kaiser-Bessel parameters.
int K
 size in Ix-space
float vtable
 I0 window size.
int ntable
 table I0 non-zero domain maximum
vector< float > i0table
float dtable
float alphar
 table spacing
float fac
 alpha*r
float vadjust
 2*pi*alpha*r*v
float facadj
float fltb
 Tabulate I0 window for speed.

Detailed Description

1-D Kaiser-Bessel window function class.

(It's a class so that the windowing parameters may be instantiated and held in the instance object.)

The I0 version can be tabulated and interpolated upon demand, but the max error needs to be checked. The "vtable" parameter corresponds to the maximum value of x for which the I0 window is non-zero. Setting "vtable" different from "v" corresponds to a change in units of x. In practice, it is often handy to replace x in some sort of absolute units with x described in terms of grid intervals.

The get_kbsinh_win and get_kbi0_win functions return single-argument function objects, which is what a generic routine is likely to want.

See also:
P. A. Penczek, R. Renka, and H. Schomberg, J. Opt. Soc. Am. _21_, 449 (2004)

Definition at line 229 of file util.h.


Constructor & Destructor Documentation

Util::KaiserBessel::KaiserBessel ( float  alpha_,
int  K,
float  r_,
float  v_,
int  N_,
float  vtable_ = 0.f,
int  ntable_ = 5999 
)

Definition at line 2156 of file util_sparx.cpp.

References alpha, alphar, build_I0table(), fac, facadj, K, r, twopi, v, vadjust, and vtable.

                : alpha(alpha_), v(v_), r(r_), N(N_), K(K_), vtable(vtable_),
                  ntable(ntable_) {
        // Default values are alpha=1.25, K=6, r=0.5, v = K/2
        if (0.f == v) v = float(K)/2;
        if (0.f == vtable) vtable = v;
        alphar = alpha*r;
        fac = static_cast<float>(twopi)*alphar*v;
        vadjust = 1.0f*v;
        facadj = static_cast<float>(twopi)*alphar*vadjust;
        build_I0table();
}
virtual EMAN::Util::KaiserBessel::~KaiserBessel ( ) [inline, virtual]

Definition at line 249 of file util.h.

{

Member Function Documentation

void Util::KaiserBessel::build_I0table ( ) [protected, virtual]

2*pi*alpha*r*vadjust

Reimplemented in EMAN::Util::FakeKaiserBessel.

Definition at line 2179 of file util_sparx.cpp.

References EMAN::Util::round(), and sqrt().

Referenced by KaiserBessel().

                                     {
        i0table.resize(ntable+1); // i0table[0:ntable]
        int ltab = int(round(float(ntable)/1.25f));
        fltb = float(ltab)/(K/2);
        float val0 = static_cast<float>(gsl_sf_bessel_I0(facadj));
        for (int i=ltab+1; i <= ntable; i++) i0table[i] = 0.f;
        for (int i=0; i <= ltab; i++) {
                float s = float(i)/fltb/N;
                if (s < vadjust) {
                        float rt = sqrt(1.f - pow(s/vadjust, 2));
                        i0table[i] = static_cast<float>(gsl_sf_bessel_I0(facadj*rt))/val0;
                } else {
                        i0table[i] = 0.f;
                }
//              cout << "  "<<s*N<<"  "<<i0table[i] <<endl;
        }
}
vector<float> EMAN::Util::KaiserBessel::dump_table ( ) [inline]

Definition at line 252 of file util.h.

                {
kbi0_win EMAN::Util::KaiserBessel::get_kbi0_win ( ) [inline]

I0 window function object factory.

Definition at line 299 of file util.h.

                {
kbsinh_win EMAN::Util::KaiserBessel::get_kbsinh_win ( ) [inline]

Sinh window function object factory.

Definition at line 285 of file util.h.

                {
int EMAN::Util::KaiserBessel::get_window_size ( ) const [inline]
float Util::KaiserBessel::I0table_maxerror ( )

Compute the maximum error in the table.

Definition at line 2197 of file util_sparx.cpp.

                                         {
        float maxdiff = 0.f;
        for (int i = 1; i <= ntable; i++) {
                float diff = fabs(i0table[i] - i0table[i-1]);
                if (diff > maxdiff) maxdiff = diff;
        }
        return maxdiff;
}
float Util::KaiserBessel::i0win ( float  x) const [virtual]

Kaiser-Bessel I0 window function.

Reimplemented in EMAN::Util::FakeKaiserBessel.

Definition at line 2170 of file util_sparx.cpp.

References sqrt().

Referenced by EMAN::Processor::EMFourierFilterFunc().

                                           {
        float val0 = float(gsl_sf_bessel_I0(facadj));
        float absx = fabs(x);
        if (absx > vadjust) return 0.f;
        float rt = sqrt(1.f - pow(absx/vadjust, 2));
        float res = static_cast<float>(gsl_sf_bessel_I0(facadj*rt))/val0;
        return res;
}
float EMAN::Util::KaiserBessel::i0win_tab ( float  x) const [inline]
float Util::KaiserBessel::sinhwin ( float  x) const [virtual]

Kaiser-Bessel Sinh window function.

Reimplemented in EMAN::Util::FakeKaiserBessel.

Definition at line 2206 of file util_sparx.cpp.

References sqrt().

Referenced by EMAN::EMData::divkbsinh(), EMAN::EMData::divkbsinh_rect(), and EMAN::Processor::EMFourierFilterFunc().

                                             {
        float val0 = sinh(fac)/fac;
        float absx = fabs(x);
        if (0.0 == x) {
                float res = 1.0f;
                return res;
        } else if (absx == alphar) {
                return 1.0f/val0;
        } else if (absx < alphar) {
                float rt = sqrt(1.0f - pow((x/alphar), 2));
                float facrt = fac*rt;
                float res = (sinh(facrt)/facrt)/val0;
                return res;
        } else {
                float rt = sqrt(pow((x/alphar),2) - 1.f);
                float facrt = fac*rt;
                float res = (sin(facrt)/facrt)/val0;
                return res;
        }
}

Member Data Documentation

Definition at line 232 of file util.h.

Referenced by KaiserBessel().

table spacing

Definition at line 239 of file util.h.

Referenced by KaiserBessel().

Definition at line 238 of file util.h.

float EMAN::Util::KaiserBessel::fac [protected]

alpha*r

Definition at line 240 of file util.h.

Referenced by KaiserBessel().

Definition at line 242 of file util.h.

Referenced by KaiserBessel().

float EMAN::Util::KaiserBessel::fltb [protected]

Tabulate I0 window for speed.

Definition at line 244 of file util.h.

vector<float> EMAN::Util::KaiserBessel::i0table [protected]

Definition at line 237 of file util.h.

int EMAN::Util::KaiserBessel::K [protected]

size in Ix-space

Definition at line 234 of file util.h.

Referenced by KaiserBessel().

int EMAN::Util::KaiserBessel::N [protected]

Kaiser-Bessel parameters.

Definition at line 233 of file util.h.

table I0 non-zero domain maximum

Definition at line 236 of file util.h.

float EMAN::Util::KaiserBessel::r [protected]

Definition at line 232 of file util.h.

Referenced by KaiserBessel().

float EMAN::Util::KaiserBessel::v [protected]

Definition at line 232 of file util.h.

Referenced by KaiserBessel().

2*pi*alpha*r*v

Definition at line 241 of file util.h.

Referenced by KaiserBessel().

I0 window size.

Definition at line 235 of file util.h.

Referenced by KaiserBessel().


The documentation for this class was generated from the following files: