MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FIR.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Filter.hpp"
4
6
7/**
8 * @class FIR
9 * @brief Finite Impulse Response filter implementation
10 *
11 * The FIR filter implements a non-recursive digital filter where the output
12 * depends only on the current and past input values, with no feedback path.
13 * This creates a filter with guaranteed stability and linear phase response
14 * when coefficients are symmetric.
15 *
16 * FIR filters are characterized by the difference equation:
17 * y[n] = b₀x[n] + b₁x[n-1] + ... + bₘx[n-m]
18 *
19 * Key properties of FIR filters:
20 * - Always stable (no feedback means no potential for instability)
21 * - Can have perfectly linear phase (when coefficients are symmetric)
22 * - Typically require more coefficients than IIR for similar magnitude response
23 * - No feedback means no resonance or self-oscillation
24 *
25 * Common applications include:
26 * - Low/high/band-pass filtering with predictable phase response
27 * - Time-domain transformations and delay-based effects
28 * - Convolution-based processing (impulse responses, simulations)
29 * - Windowed-sinc filters for precise frequency response
30 * - Hilbert transformers and other specialized signal processors
31 * - Data smoothing and noise reduction in sensor data
32 * - Feature extraction in pattern recognition
33 */
34class MAYAFLUX_API FIR : public Filter {
35public:
36 /**
37 * @brief Creates an FIR filter with specified order
38 * @param input Source node providing input samples
39 * @param zindex_shifts String in format "N_0" specifying filter order
40 *
41 * Creates an FIR filter with the specified input node and order.
42 * For FIR filters, the second number in zindex_shifts should be 0
43 * since there is no feedback path (e.g., "64_0" for a 64-tap FIR).
44 * All coefficients are initialized to zero.
45 */
46 FIR(const std::shared_ptr<Node>& input, const std::string& zindex_shifts);
47
48 /**
49 * @brief Creates an FIR filter with specified coefficients
50 * @param input Source node providing input samples
51 * @param coeffs Vector of filter coefficients
52 *
53 * Creates an FIR filter with the specified input node and coefficients.
54 * The coefficients directly define the filter's impulse response and
55 * frequency response characteristics.
56 */
57 FIR(const std::shared_ptr<Node>& input, const std::vector<double>& coeffs);
58
59 /**
60 * @brief Creates an FIR filter with specified coefficients (no input node)
61 * @param coeffs Vector of filter coefficients
62 *
63 * Creates an FIR filter with the specified coefficients but no input node.
64 * This can be used in scenarios where the filter operates on external data
65 * or is part of a larger processing chain.
66 */
67 FIR(const std::vector<double>& coeffs);
68
69 /**
70 * @brief Processes a single sample through the FIR filter
71 * @param input The input sample
72 * @return The filtered output sample
73 *
74 * Implements the FIR filtering algorithm, computing the weighted sum
75 * of the current input and previous inputs according to the filter
76 * coefficients. This is the core processing method called for each sample.
77 */
78 double process_sample(double input = 0.) override;
79
80 void save_state() override;
81 void restore_state() override;
82};
83
84}
Finite Impulse Response filter implementation.
Definition FIR.hpp:34
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:138