FIR Filter (fir)
Filters a sampled signal with a fixed list of weights.
Group: Control · Kind: {"block":"fir","kind":"control"}
When to use it
Use it for a moving average or any linear-phase filter in firmware. Use IIR Filter for a sharper response with fewer coefficients.
Pins
| Pin | Domain | Meaning |
|---|---|---|
in |
signal | Signal to filter, sampled every ts |
out |
signal | Filtered output, held between samples |
Common parameters
ts: Time between samples (Default: required)coeffs: Filter weights, separated by commas (Default: required)offset: Time of the first sample (Default: 0)
Parameters
| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
ts |
s | required | Time between samples | |
offset |
s | 0 | Time of the first sample | |
coeffs |
— | required | Filter weights, separated by commas |
Parameter descriptions are in English in both languages.
Model
coeffs lists the taps h0, h1, ..., and y[k] = h0·u[k] + h1·u[k-1] + .... At most 4096 taps are allowed. There is no feedback, so the filter is always stable, and its DC gain is the sum of the taps. The history starts at zero. The block has direct feedthrough only when h0 is not 0.
Common mistakes
- The coefficients are not scaled for you. A moving average of N samples needs N coefficients of 1/N, and coefficients that add up to 1.2 give a DC gain of 1.2.
- The first outputs start from zero history, so there is a short start-up transient. A symmetric filter also delays the signal by half its length, which costs phase inside a control loop, so keep it short there.
Datasheet and sources
ts is the sample time of the data the filter runs on, the 1/fs of your interrupt. The coefficients come from a filter design tool for that sample rate, or are 1/N for a moving average.
Example
Open the example with the command file.openExample and the name demo:fir.
Generated by cargo xtask reference from the usage texts and parameter specs. Do not edit by hand.