Cheetah Software  1.0
butterworth_filter< T > Class Template Reference

#include <filters.h>

+ Inheritance diagram for butterworth_filter< T >:
+ Collaboration diagram for butterworth_filter< T >:

Public Member Functions

 butterworth_filter (int num_sample, T dt, T cutoff_frequency)
 
virtual ~butterworth_filter (void)
 
virtual void input (T input_value)
 
virtual T output (void)
 
virtual void clear (void)
 
- Public Member Functions inherited from filter< T >
 filter (void)
 
virtual ~filter (void)
 

Private Attributes

T * mpBuffer
 
int mCurIdx
 
int mNumSample
 
mDt
 
mCutoffFreq
 
mValue
 

Detailed Description

template<typename T>
class butterworth_filter< T >

Definition at line 15 of file filters.h.

Constructor & Destructor Documentation

template<typename T >
butterworth_filter< T >::butterworth_filter ( int  num_sample,
dt,
cutoff_frequency 
)

Definition at line 47 of file filters.cpp.

48  {
49  mNumSample = num_sample;
50  mDt = dt;
51  mCutoffFreq = cutoff_frequency;
52 
53  mpBuffer = new T[num_sample];
54  memset((void *)mpBuffer, 0, sizeof(T) * num_sample);
55 
56  mCurIdx = 0;
57 }
template<typename T >
butterworth_filter< T >::~butterworth_filter ( void  )
virtual

Definition at line 60 of file filters.cpp.

60  {
61  delete[] mpBuffer;
62 }

Member Function Documentation

template<typename T >
void butterworth_filter< T >::clear ( void  )
virtual

Implements filter< T >.

Definition at line 89 of file filters.cpp.

89  {
90  for (int i(0); i < mNumSample; ++i) {
91  mpBuffer[i] = 0.0;
92  }
93 }
template<typename T >
void butterworth_filter< T >::input ( input_value)
virtual

Implements filter< T >.

Definition at line 65 of file filters.cpp.

65  {
66  int j;
67  T sqrt_2 = sqrt(2);
68  T value = 0;
69  for (j = mNumSample - 2; j >= 0; j--) {
70  mpBuffer[j + 1] = mpBuffer[j];
71  }
72 
73  mpBuffer[0] = input_value;
74  for (j = 0; j < mNumSample; j++) {
75  T t = (T)j * mDt;
76  value += sqrt_2 / mCutoffFreq * mpBuffer[j] * exp(-1. / sqrt_2 * t) *
77  sin(mCutoffFreq / sqrt_2 * t) * mDt;
78  // value += sqrt_2 * exp(-1./sqrt_2*t) * sin(1./sqrt_2*t ) * mDt;
79  }
80  mValue = value;
81 }
template<typename T >
T butterworth_filter< T >::output ( void  )
virtual

Implements filter< T >.

Definition at line 84 of file filters.cpp.

84  {
85  return mValue;
86 }

Member Data Documentation

template<typename T >
int butterworth_filter< T >::mCurIdx
private

Definition at line 25 of file filters.h.

template<typename T >
T butterworth_filter< T >::mCutoffFreq
private

Definition at line 28 of file filters.h.

template<typename T >
T butterworth_filter< T >::mDt
private

Definition at line 27 of file filters.h.

template<typename T >
int butterworth_filter< T >::mNumSample
private

Definition at line 26 of file filters.h.

template<typename T >
T* butterworth_filter< T >::mpBuffer
private

Definition at line 24 of file filters.h.

template<typename T >
T butterworth_filter< T >::mValue
private

Definition at line 29 of file filters.h.


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