Suggested Filter: Rate Limiter Filter with Spike Rejection
Explanation:
To achieve a filtered level signal that is as flat as possible without substantial signal delay, especially in the presence of occasional long sustained spikes and frequent random bursts of noise, a rate limiter filter with spike rejection is an effective solution. This filter limits the maximum rate at which the filtered value can change over time, effectively smoothing out sudden spikes and bursts while allowing gradual changes to pass through with minimal delay.
Why This Filter:
-
Spike Rejection: By limiting the rate of change, sudden spikes (both short and long sustained) are gradually adjusted in the filtered output, preventing abrupt shifts due to noise.
-
Minimal Signal Delay: Small and gradual changes in the measured signal are allowed to pass through the filter without significant delay, maintaining responsiveness where needed.
-
Simplicity and Efficiency: The filter is straightforward to implement in structured text for an Allen Bradley PLC, requiring minimal computational resources.
Implementation Details:
-
Variables:
MeasuredValue: The raw input from the level instrument.
FilteredValue: The output of the filter, representing the smoothed level signal.
Diff: The difference between the MeasuredValue and the FilteredValue.
Limit: The maximum allowable rate of change of the FilteredValue per second.
DeltaTime: The time interval between filter updates (sample time), in seconds.
MaxChange: The maximum change allowed for the FilteredValue in one update cycle.
-
Logic:
- Calculate the Maximum Allowed Change per Update:
MaxChange is determined by multiplying the Limit (rate per second) by DeltaTime.
- Determine the Difference Between Measured and Filtered Values:
Diff is calculated as MeasuredValue - FilteredValue.
- Apply Rate Limiting:
- If
Diff is within MaxChange, the FilteredValue is set directly to the MeasuredValue (no delay).
- If
Diff exceeds MaxChange, the FilteredValue is adjusted towards the MeasuredValue by MaxChange, limiting the rate of change.
Structured Text Implementation for Allen Bradley PLC:
// Define and initialize variables
VAR
MeasuredValue : REAL; // Raw instrument measurement input
FilteredValue : REAL; // Output of the filter
Diff : REAL; // Difference between MeasuredValue and FilteredValue
Limit : REAL := 0.5; // Maximum rate of change per second (adjustable parameter)
DeltaTime : REAL := 0.1; // Time between samples in seconds (e.g., 100ms)
MaxChange : REAL; // Maximum allowed change per update
END_VAR
// Calculate the maximum change allowed per sample
MaxChange := Limit * DeltaTime;
// Calculate the difference between measured and filtered values
Diff := MeasuredValue - FilteredValue;
// Apply rate limiting logic
IF ABS(Diff) <= MaxChange THEN
// If within limit, set FilteredValue to MeasuredValue (no delay)
FilteredValue := MeasuredValue;
ELSE
// If outside limit, adjust FilteredValue towards MeasuredValue by MaxChange
IF Diff > 0 THEN
FilteredValue := FilteredValue + MaxChange;
ELSE
FilteredValue := FilteredValue - MaxChange;
END_IF;
END_IF;
Notes:
-
Adjustable Parameters:
Limit can be adjusted based on the acceptable rate of change for the process. A smaller value provides more smoothing but may introduce more delay for legitimate rapid changes.
DeltaTime should match the actual sample time of the PLC task or loop executing this code.
-
Execution Frequency:
- The filter code should be executed at regular intervals defined by
DeltaTime to maintain consistent filtering behavior.
-
Benefits of This Filter:
- Effectively smooths out both short-term noise and long-term sustained spikes by controlling the rate at which the output can change.
- Maintains a balance between signal smoothing and responsiveness, essential for control applications in process engineering.
- Simple and efficient to implement, ensuring that PLC resources are not overly taxed.
-
Tuning and Optimization:
- Monitor the filtered output and adjust the
Limit parameter as needed to achieve the desired level of smoothing without compromising the responsiveness of the control system.
- Consider implementing additional logic if specific patterns of noise or spikes are observed, such as adding counters to detect sustained deviations.
Conclusion:
The rate limiter filter with spike rejection provides an effective solution for filtering a noisy level signal in a process control application. Its ability to smooth out noise and reject spikes while maintaining minimal signal delay makes it suitable for implementation in an Allen Bradley PLC using structured text.