The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHATableLookup::linear_table_t Class Reference

Class for interpolation with equidistant x values. More...

Inheritance diagram for MHATableLookup::linear_table_t:
Inheritance graph

Public Member Functions

 linear_table_t (void)
 contructor creates an empty linear_table_t object. More...
 
mha_real_t lookup (mha_real_t x) const
 look up the y value that is stored for the mesh point where x is lower than or equal to the x value given here. More...
 
mha_real_t interp (mha_real_t x) const
 interpolate y value for the given x value. More...
 
 ~linear_table_t (void)
 destructor More...
 
void set_xmin (mha_real_t xmin)
 set the x value for the first mesh point. More...
 
void add_entry (mha_real_t y)
 set the y value for the next mesh point. More...
 
void set_xmax (mha_real_t xmax)
 this sets the x value for a past-the-end, not added mesh point. More...
 
void prepare (void)
 prepare computes the x distance of the mesh points based on the values given to set_xmin, set_xmax, and the number of times that add_entry was called. More...
 
void clear (void)
 clear resets the state of this object to the state directly after construction. More...
 
- Public Member Functions inherited from MHATableLookup::table_t
 table_t (void)
 
virtual ~table_t (void)
 

Protected Attributes

mha_real_tvy
 
unsigned int len
 

Private Attributes

vector< mha_real_tvec_y
 
mha_real_t xmin
 
mha_real_t xmax
 
mha_real_t scalefac
 

Additional Inherited Members

Detailed Description

Class for interpolation with equidistant x values.

This class can be used for linear interpolation tasks where the mesh points are known for equidistant x values.

Before the class can be used for interpolation, it has to be filled with the y values for the mesh points, the x range has to be specified, and when all values are given, the prepare method has to be called so that the object can determine the distance between x values from the range and the number of mesh points given.

Only after prepare has returned, the object may be used for interpolation.

Constructor & Destructor Documentation

◆ linear_table_t()

linear_table_t::linear_table_t ( void  )

contructor creates an empty linear_table_t object.

add_entry, set_xmin, set_xmax and prepare methods have to be called before the object can be used to lookup and interpolate values.

◆ ~linear_table_t()

linear_table_t::~linear_table_t ( void  )

destructor

Member Function Documentation

◆ lookup()

mha_real_t linear_table_t::lookup ( mha_real_t  x) const
virtual

look up the y value that is stored for the mesh point where x is lower than or equal to the x value given here.

This method does not extrapolate, so for x < xmin, the y value for xmin is returned. For all x greater than the x of the last mesh point, the y value of the last mesh point is returned.

Precondition
prepare must have been called before lookup may be called.

Implements MHATableLookup::table_t.

◆ interp()

mha_real_t linear_table_t::interp ( mha_real_t  x) const
virtual

interpolate y value for the given x value.

The y values for the neighbouring mesh points are looked up and linearly interpolated. For x values outside the range of mesh points, the y value is extrapolated from the nearest two mesh points.

Precondition
prepare must have been called before interp may be called.

Implements MHATableLookup::table_t.

◆ set_xmin()

void linear_table_t::set_xmin ( mha_real_t  xmin)

set the x value for the first mesh point.

Must be called before prepare can be called.

◆ add_entry()

void linear_table_t::add_entry ( mha_real_t  y)

set the y value for the next mesh point.

Must be called at least twice before prepare can be called.

◆ set_xmax()

void linear_table_t::set_xmax ( mha_real_t  xmax)

this sets the x value for a past-the-end, not added mesh point.

Example:

t.set_xmin(100);
t.add_entry(0); // mesh point {100,0}
t.add_entry(1); // mesh point {110,1}
// the next mesh point would be at x=120, but we do not add this
t.set_xmax(120); // the x where the next mesh point would be
t.prepare();

now, t.interp(100) == 0; t.interp(110) == 1; t.interp(105) == 0.5;

◆ prepare()

void linear_table_t::prepare ( void  )

prepare computes the x distance of the mesh points based on the values given to set_xmin, set_xmax, and the number of times that add_entry was called.

Precondition
set_xmin, set_xmax, add_entry functions must have been called before calling prepare, add_entry must have been called at least twice.

Only after this method has been called, interp or lookup may be called.

◆ clear()

void linear_table_t::clear ( void  )
virtual

clear resets the state of this object to the state directly after construction.

mesh entries and x range are deleted.

interp and lookup may not be called after this function has been called unless prepare and before that its precondition methods are called again.

Implements MHATableLookup::table_t.

Member Data Documentation

◆ vy

mha_real_t* MHATableLookup::linear_table_t::vy
protected

◆ len

unsigned int MHATableLookup::linear_table_t::len
protected

◆ vec_y

vector<mha_real_t> MHATableLookup::linear_table_t::vec_y
private

◆ xmin

mha_real_t MHATableLookup::linear_table_t::xmin
private

◆ xmax

mha_real_t MHATableLookup::linear_table_t::xmax
private

◆ scalefac

mha_real_t MHATableLookup::linear_table_t::scalefac
private

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