Skip to content

A digital implementation of an analogue filter

Notifications You must be signed in to change notification settings

TeamSunride/RCFilter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic low pass RC filter implementation

This is a digital implementation of an analogue RC filter.

Theory

We can infer that the differential equation for this system is:

$$ V_{in} = RC\frac{dV_{out}}{dt} + V_{out} $$

Discretising using euler's method:

$$ \frac{dV_{out}}{dt} = \frac{V_{out}[n] - V_{out}[n-1]}{T} $$

We obtain:

$$ V_{out} = V_{in}[n]\frac{T}{T+RC} + V_{out}[n-1]\frac{RC}{T+RC} $$

This is calculated every time the .update() method is called, and is very computationally inexpensive.

Operation

The RC filter is constructed with:

RCFilter acc_x(8); // Cutoff frequency of 8Hz 

The filtered value is obtained by calling the .update() method: (need an accurate timestamp in microseconds (us) )

double x = sensor.read();
unsigned long t = micros();
float out = acc_x.update(x, t);

The filter successfully filters out noise (accelerometer data shown below, Raw (Red) and Filtered (Green) ):

Be careful when choosing a cutoff frequency, if it's too low, the response lag's behind:

About

A digital implementation of an analogue filter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%