LowpassFilter
- Namespace
- ZCore
- Extends
- Inherited Methods
FUNCTION_BLOCK LowpassFilter EXTENDS ZCore.FirFilter
In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. FirFilter implements main concepts of FIR Filters. Specializations implement the InitalizeCoefficents, which in turn controls the bahavior of the filter.
To use the FIR Filter
Frequencies below the cut-off frequency freq can pass through the filter. This filter is commonly used
for smoothing a signal.
The following code shows an example where a signal (sinus signal with amplitude 1 and frequency 1Hz) is noisy (50Hz and 100Hz noise).
A lowpass filter with 8000 samples is applied to the signal filtering out the noise.
lowpassFilter : ZCore.LowpassFilter(cycletime:=0.001, samples:=8000, freq:=20);
signal, t, filtered : LREAL;
//--------------------------------------------------------
signal := SIN(1 * 2 * PI * t) + 0.1*SIN(50 * 2 * PI * t) + 0.03*SIN(100 * 2 * PI * t);
t := t + 0.001;
lowpassFilter.Update(signal);
filtered := lowpassFilter.Output();
Constructor
FB_init
METHOD FB_init (
[input] bInitRetains : BOOL,
[input] bInCopyCode : BOOL,
[input] cycletime : LREAL,
[input] samples : DINT,
[input] freq : LREAL) : BOOL
Inputs
bInitRetainsBOOLif TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCodeBOOLif TRUE, the instance afterwards gets moved into the copy code (online change)
cycletimeLREALcycletime in seconds, this should be set to the cycle time of the PLC and the cycle that Update is called with, respectively.
samplesDINTnumber of samples, the actual sample count is capped by ParameterList.MovingAverageMaxBufferSize.
freqLREAL
Returns
- BOOL
Methods
InitalizeCoefficents
METHOD PROTECTED FINAL InitalizeCoefficents ()
Initializes the coefficent of the FIR filter for a lowpass