Filters 1.0
LPF, HPF, BPF, BSF, SRL
Loading...
Searching...
No Matches
Filters Library

Introduction

The Filters library is a C++ library providing discrete-time digital signal filtering algorithms for applications such as sensor signal processing, signal conditioning, robotics, control systems, and embedded systems.

The library provides templated filter implementations that support different numeric data types such as float and double.

All filters are organized under the filter namespace and further grouped according to their filter type.

Features

The library currently provides the following digital filters:

  • First-order low-pass filter
  • Second-order low-pass filter
  • First-order high-pass filter
  • Second-order high-pass filter
  • Second-order band-pass filter
  • Second-order band-stop filter

The filters provide interfaces for configuration, parameter modification, signal processing, state reset, and retrieval of filter parameters.

Available Filters

Low-pass Filters

Low-pass filters attenuate high-frequency components while allowing low-frequency components of the input signal to pass.

Available implementations:

High-pass Filters

High-pass filters attenuate low-frequency components and DC components while allowing higher-frequency components to pass.

Available implementations:

Band-pass Filters

Band-pass filters allow frequency components around a specified center frequency to pass while attenuating frequency components below and above the passband.

Available implementation:

  • filter::band_pass::BPF_2
    • Second-order band-pass filter.
    • Configured using center frequency, bandwidth, and sampling time.

Band-stop Filters

Band-stop filters attenuate frequency components within a specified frequency band while allowing frequencies below and above the stopband to pass.

Available implementation:

  • filter::band_stop::BSF_2
    • Second-order band-stop filter.
    • Configured using center frequency, bandwidth, and sampling time.

Filter Configuration

The filters are configured using their frequency parameters and sampling time.

First-order low-pass and high-pass filters can be configured using:

filter.config(fc, dt);
Contains digital signal filtering algorithms.
Definition bpf_2.h:38

where:

  • fc is the cutoff frequency in Hz.
  • dt is the sampling time in seconds.

Second-order low-pass and high-pass filters use the same configuration interface:

filter.config(fc, dt);

The second-order filters use a prewarped cutoff frequency during their digital filter design.

Band-pass and band-stop filters are configured using center frequency, bandwidth, and sampling time:

filter.config(f0, B, dt);

where:

  • f0 is the center frequency in Hz.
  • B is the bandwidth in Hz.
  • dt is the sampling time in seconds.

For the second-order band-pass and band-stop filters, the quality factor is defined as:

\‍[Q = \frac{f_0}{B}
\‍]

Basic Usage

The filter classes provide an update() function for processing individual input samples.

A typical usage sequence is:

#include "lpf_1.h"
filter.config(10.0, 0.001);
double input = 1.0;
double output = filter.update(input);
First-order low-pass filter.
Definition lpf_1.h:72
First-order low-pass filter.

The update() function processes one input sample and returns the corresponding filtered output sample.

Resetting Filter State

Each filter maintains internal state required for discrete-time signal processing.

The state can be reset using the reset() function:

filter.reset();

Resetting a filter clears its previous signal samples and startup state.

Parameter Access

The filters provide setter and getter functions for their configurable parameters.

Common parameters include:

  • Cutoff frequency
  • Sampling time
  • Sampling frequency
  • Center frequency
  • Bandwidth
  • Quality factor

The sampling frequency is calculated from the sampling time as:

\‍[f_s = \frac{1}{dt}
\‍]

Namespace Organization

The library uses the following namespace hierarchy:

+-- LPF_1
+-- LPF_2
+-- HPF_1
+-- HPF_2
+-- BPF_2
+-- BSF_2
Contains band-pass filter implementations.
Contains band-stop filter implementations.
Contains high-pass filter implementations.
Contains low-pass filter implementations.

Library Organization

The filter implementations are organized according to their filter category.

+-- low_pass/
+-- lpf_1.h
+-- lpf_2.h
+-- high_pass/
+-- hpf_1.h
+-- hpf_2.h
+-- band_pass/
+-- bpf_2.h
+-- band_stop/
+-- bsf_2.h
+-- filters.h

Common Filter Interface

The filter classes provide a consistent interface for configuring and processing signals.

Typical operations include:

filter.config(...); // Configure the filter
filter.set_param(...); // Modify filter parameters
output = filter.update(input); // Process an input sample
filter.reset(); // Reset internal state

Individual filter classes may additionally provide parameter-specific setters and getters.

Template Support

The filter classes are implemented as C++ templates:

This allows the same filter implementation to be used with different numeric data types.

Examples

A first-order low-pass filter can be used as follows:

lpf.config(10.0, 0.001);
double output = lpf.update(input);
T update(T x_k)
Processes a new input sample.
Definition lpf_1.h:26
void config(T fc_, T dt_)
Configures the low-pass filter.
Definition lpf_1.h:11

A second-order band-pass filter can be configured as:

bpf.config(10.0, 2.0, 0.001);
double output = bpf.update(input);
Second-order band-pass filter.
Definition bpf_2.h:80
void config(T f0_, T B_, T dt_)
Configures the band-pass filter.
Definition bpf_2.h:11
T update(T x_k)
Processes a new input sample.
Definition bpf_2.h:56

A second-order band-stop filter can be configured as:

bsf.config(50.0, 5.0, 0.001);
double output = bsf.update(input);
Second-order band-stop filter.
Definition bsf_2.h:81
T update(T x_k)
Processes a new input sample.
Definition bsf_2.h:56
void config(T f0_, T B_, T dt_)
Configures the band-stop filter.
Definition bsf_2.h:11

Author

Author
Abhinay Kumar
Version
1.0.0