RobotCasserole1736 / CasseroleLib

Common Libraries used year-to-year for FRC robot code
MIT License
6 stars 1 forks source link

Create FIR filter class #12

Closed gerth2 closed 8 years ago

gerth2 commented 8 years ago

Create a new FIR filter class for the signalmath library.

See the wikipedia article on FIR filters. An FIR filter is basically a weighted average of some number of previous samples. The number of samples considered is the number of "filter taps" and the weight on each sample is carefully chosen to select the frequencies of interest.

Graphically, it looks like this: FIR

The z^-1's are "delay blocks" and each b_i is a weight for the tap. Note in order for the filter to have unity gain (not amplify or degrade the signal overall), the sum of all b_i must equal 1. Finally, note that the b_i sequence is symmetric about its midpoint. These things are true because math.

For choosing the b_i values, use an online filter designer, like this one.

For simplicity, the user should only have to select the filter type from a fixed list. This list should include:

2Hz Lowpass
5Hz Lowpass
15Hz Lowpass
1Hz highpass (DC Reject)
10Hz highpass
Unity (all taps with equal gain - this is a "sliding window average" filter)

More may be added in the future if needed.

The user interface for this library is 3-part:

1) instantiate the filter with an enum value to indicate cutoff frequency & type. Filter should start periodic background calculations in its own thread.
2) User may call a "input update" function at will to change the current input to the filter. This will be asynchronous from filter calculations.
3) User may 

The buffer of previous samples is best implemented as a Java queue. Every sample period, the new present value is added to the queue. Then the whole queue is iterated over, summing up each member multiplied by the approprate gain.

gerth2 commented 8 years ago

Done, mostly. Still needs some testing, but I"m pretty confident in this code.