filter_init
Builtin index · Signal processing
result = filter_init(filt)
Input: filt · Output: result
What it is
filt: a Model (kind "filter").
Overloads
2 forms. Each carries its own inputs, outputs and worked example — pick the tab for the one you are calling.
| Code | Input | Output | Description |
result = filter_init(filt) | filt Modelnot documented yet | result Model, matrix, or number | Returns a filter_state Model whose z is an (n_sections, 2) all-zero biquad-state matrix — 2 numbers of memory per section. |
Examples
Written for this form and run by the build -- the output below is what the engine actually produced.
fs = 1000
iir = butter(2, "low", 100, fs)
si = filter_init(iir)
print("IIR state shape: {shape(si.z)}") # IIR state shape: [1, 2]
IIR state shape: [1, 2]
| Code | Input | Output | Description |
result = filter_init(filt) | filt Modelnot documented yet | result Model or vector | Returns a filter_state Model whose z is a plain length-(len(b)-1) all-zero delay vector — just the last few inputs, no feedback to track. |
Examples
Written for this form and run by the build -- the output below is what the engine actually produced.
fs = 1000
fir = fir1(6, 100, kind="low", fs=fs)
sf = filter_init(fir)
print("FIR state length: {length(sf.z)}") # FIR state length: 6
FIR state length: 6
How it works
The streaming (sample-at-a-time) filtering pair, for real-time/serial-fed data where a whole array isn't available up front: state = filter_init(filt) then repeatedly state = filter_next(state, next_sample), reading state.y for each filtered output — the same "thread a new state through each call" idiom kalman_predict/kalman_update already use, not a mutable iterator object (Qu has no mutation-of-shared-state primitive for this, by design). filter_init(filt) — a fresh all-zero state: an (n_sections, 2) biquad-state matrix for an IIR (sos) filter, or a len(b)-1-long all-zero delay line for an FIR (b) filter — simpler, since there's no feedback state to track at all, just the last few inputs.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.