MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
IIR.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Filter.hpp"
4
6
7/**
8 * @class IIR
9 * @brief Infinite Impulse Response filter implementation
10 *
11 * The IIR filter implements a recursive digital filter where the output
12 * depends on both current/past input values and past output values through
13 * a feedback path. This creates a filter that can achieve complex frequency
14 * responses with fewer coefficients than FIR filters.
15 *
16 * IIR filters are characterized by the difference equation:
17 * y[n] = (b₀x[n] + b₁x[n-1] + ... + bₘx[n-m]) - (a₁y[n-1] + ... + aₙy[n-n])
18 *
19 * Key properties of IIR filters:
20 * - Can become unstable if coefficients are improperly designed
21 * - Non-linear phase response (phase distortion)
22 * - Require fewer coefficients than FIR for similar magnitude response
23 * - Feedback path enables resonance and self-reinforcing behaviors
24 * - Can model analog system responses (Butterworth, Chebyshev, etc.)
25 *
26 * Common applications include:
27 * - Efficient low/high/band-pass filtering
28 * - Resonant systems for dynamic modeling
29 * - Spectral shaping and frequency-domain transformations
30 * - Physical modeling components (resonators, feedback systems)
31 * - Adaptive filters and dynamic response systems
32 * - Control systems and feedback loops
33 * - Predictive modeling in time-series data
34 * - Simulation of natural and mechanical systems
35 */
36class MAYAFLUX_API IIR : public Filter {
37public:
38 /**
39 * @brief Creates an IIR filter with specified order
40 * @param input Source node providing input samples
41 * @param zindex_shifts String in format "N_M" specifying filter order
42 *
43 * Creates an IIR filter with the specified input node and order configuration.
44 * The zindex_shifts parameter defines both feedforward and feedback paths
45 * (e.g., "2_2" for a biquad filter). All coefficients are initialized to zero
46 * except a[0] which is set to 1.0.
47 */
48 IIR(const std::shared_ptr<Node>& input, const std::string& zindex_shifts);
49
50 /**
51 * @brief Creates an IIR filter with specified coefficients
52 * @param input Source node providing input samples
53 * @param a_coef Feedback (denominator) coefficients
54 * @param b_coef Feedforward (numerator) coefficients
55 *
56 * Creates an IIR filter with the specified input node and coefficient vectors.
57 * The a_coef vector contains feedback coefficients (denominator of transfer function),
58 * while b_coef contains feedforward coefficients (numerator of transfer function).
59 *
60 * Note: a[0] is typically normalized to 1.0, and the remaining a coefficients
61 * are negated compared to the standard transfer function representation.
62 */
63 IIR(const std::shared_ptr<Node>& input, const std::vector<double>& a_coef, const std::vector<double>& b_coef);
64
65 /**
66 * @brief Creates an IIR filter with specified coefficients (no input node)
67 * @param a_coef Feedback (denominator) coefficients
68 * @param b_coef Feedforward (numerator) coefficients
69 *
70 * Creates an IIR filter with the specified coefficient vectors but no input node.
71 * This can be used in scenarios where the input will be set later or through
72 * other means.
73 */
74 IIR(const std::vector<double>& a_coef, const std::vector<double>& b_coef);
75
76 /**
77 * @brief Processes a single sample through the IIR filter
78 * @param input The input sample
79 * @return The filtered output sample
80 *
81 * Implements the IIR filtering algorithm, computing the weighted sum
82 * of the current input, previous inputs, and previous outputs according
83 * to the filter coefficients. This is the core processing method called
84 * for each sample.
85 */
86 double process_sample(double input = 0.) override;
87
88 void save_state() override;
89 void restore_state() override;
90};
91
92}
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:138
Infinite Impulse Response filter implementation.
Definition IIR.hpp:36