filters Reference
Module defined in `lua/common/filters.lua`. Comprehensive signal processing library providing frequency filters, temporal smoothing, frequency detection, exponential smoothing, line fitting, and more.
Module defined in lua/common/filters.lua. Comprehensive signal processing library providing frequency filters, temporal smoothing, frequency detection, exponential smoothing, line fitting, and more. Core infrastructure for vehicle physics simulation.
Exports
All exports are global constructors (no module table).
Frequency Domain
newFreqFilter1()
Creates a 1st-order frequency filter with low-pass, high-pass, band-pass, and band-stop modes.
- Returns: freqFilter1 - Filter object
Methods:
filter:getLowPassFreq(sample, dt, cutOffFreq)→ numberfilter:getLowPassPeriod(sample, dt, cutOffPeriod)→ numberfilter:getHighPassFreq(sample, dt, cutOffFreq)→ numberfilter:getHighPassPeriod(sample, dt, cutOffPeriod)→ numberfilter:getBandPassFreq(sample, dt, lowFreq, highFreq)→ numberfilter:getBandPassPeriod(sample, dt, lowPeriod, highPeriod)→ numberfilter:getBandStopFreq(sample, dt, lowFreq, highFreq)→ numberfilter:getBandStopPeriod(sample, dt, lowPeriod, highPeriod)→ number
newFreqDetector()
Creates a frequency detector that estimates period, amplitude, and DC bias of an oscillating signal.
- Returns: freqDetector
Methods:
detector:get(sample, dt)→ period, amplitude, peakDt, biasdetector:reset()detector:value(dt)→ period, amplitude, peakDt, bias
newFreqExists()
Goertzel algorithm implementation - detects the presence/amplitude of a specific frequency in a signal.
- Returns: freqExists
Methods:
fe:get(sample, dt, freq, cycleCount)→ amplitudefe:getS(sample, dt, freq, winCoef)→ sliding amplitudefe:bufferStart(dt, freq)/fe:bufferAdd(sample)/fe:bufferEnd()→ amplitudefe:reset()
freqGenC(period, ampl, t)
Generates a cosine wave value: cos(t * 2π / period) * ampl.
- Returns: number
Temporal Smoothing
newTemporalSpring(spring, damp, startingValue)
Spring-damper temporal smoother.
- Methods:
get(sample, dt),getWithSpringDamp(sample, dt, spring, damp),set(sample),value()
newTemporalSigmoidSmoothing(inRate, startAccel, stopAccel, outRate, startingValue)
S-curve temporal smoother with acceleration control.
- Methods:
get(sample, dt),getWithRateAccel(sample, dt, ratelimit, startAccel, stopAccel),set(window, weight, bias),reset(),value()
newTemporalSmoothingNonLinear(inRate, outRate, startingValue)
Exponential/non-linear temporal smoother.
- Methods:
get(sample, dt),getWithRate(sample, dt, rate),set(window, weight, bias),value(),reset()
newTemporalSmoothing(inRate, outRate, autoCenterRate, startingValue)
Linear temporal smoother with separate in/out rates and optional auto-centering.
- Methods:
get(sample, dt),getUncapped(sample, dt),getCapped(sample, dt),getWithRate(sample, dt, rate),getWithRateCapped(sample, dt, rate),set(v),reset(),value()
Fixed-dt Smoothing
newLinearSmoothing(dt, inRate, outRate)
Linear smoother for fixed timestep use (pre-bakes dt into rates).
- Methods:
get(sample),set(v),reset()
newNopSmoothing()
Bypass/passthrough filter - returns input unchanged.
- Methods:
get(sample),set(),reset()
Exponential Smoothing
newExponentialSmoothing(window, startingValue, fixedDt)
EMA (Exponential Moving Average) filter.
- Methods:
get(sample),getWindow(sample, window, window2),value(),set(value),reset(value)
newExponentialSmoothingT(window, window2, startingValue)
EMA with trend tracking for improved responsiveness to direction changes.
- Methods:
get(sample),getWindow(sample, window, window2),value(),set(value),reset(value)
Line Fitting
newLineFitting(window, weight, bias, scale)
Exponentially weighted least-squares linear regression.
- Methods:
get(x, y)→ weight, bias;value()→ weight, bias;getY(x)→ number;set(window, weight, bias);reset()
Note: The following are instance methods on specific filter types, not standalone globals:
temporalSmoothing:getCapped(sample, dt)- Filtered value capped to max magnitudeexponentialSmoothing:getWindow(sample, window)- EMA with custom windowtemporalSmoothing:getWithRate(sample, dt, rate)- Rate-limited filteringtemporalSigmoidSmoothing:getWithRateAccel(sample, dt, ratelimit, startAccel, stopAccel)- Rate+accel limitedtemporalSmoothing:getWithRateCapped(sample, dt, rate)- Rate-limited and cappedtemporalSpring:getWithSpringDamp(sample, dt, spring, damp)- Spring-damper dynamicslineFitting:getY(x)→ number - Predicted Y from fitted linelineFitting:set(window, weight, bias)- Sets internal state
Metamethods
__index
Metatable index method for OOP-style method dispatch. Internal implementation detail.
Internal Notes
- All temporal smoothers support asymmetric rates: different speeds for "toward zero" vs "away from zero"
- The temporal smoothing convention:
self[false]= inRate,self[true]= outRate (using boolean keys for branchless selection) temporalSmoothingauto-switches togetUncappedAutoCenterwhen autoCenterRate differs from inRatefreqExistsimplements the Goertzel algorithm for O(1) per-sample frequency detection
extensions Reference
Module defined in `lua/common/extensions.lua`. The core extension/module management system for BeamNG. Handles loading, unloading, dependency resolution, hook dispatch, serialization, and virtual exte
graphpath Reference
Module defined in `lua/common/graphpath.lua`. Graph-based pathfinding library implementing Dijkstra's algorithm with extensions for road networks - supports edge properties (drivability, speed limits,