Build an analog filter in logic

NetNathan

Lifetime Supporting Member
Join Date
Nov 2011
Location
Corona, CA
Posts
2,199
I have an analog signal that has a small amount of noise.
It is on an RX3I PLC and the analog in module (IC693ALG442) does not have filter capabilities.
How could I build a filter in logic?

Is this right?
I believe I want to total readings taken every .250 ms for 2 sec and then average the total with the number of readings...correct?

So...if I am taking readings every .250 ms, I average the total by 8 (4 readings per second x 2).


Better idea?
 
Correct :)

This should be a running average, so every 250 ms you replace your oldest value with the newest value.

Also depending on your needs, 8 values may be a bit little...
 
Replace??
Wouldn't I add the readings done every 250ms to the running total until 2 secs then calculate?

ie....averaging every 1 sec on .250 ms readings
1st reading 1.5
add
2nd reading 1.9
add
3rd reading 1.4
add
4th reading 1.9
add
Total = 6.7
6.7/4=1.675
 
Last edited:
You could do that, but then you would get a little step response if your signal is changing. Might be fine if you are not using the signal to control anything.

For our application (Siemens) we write the values to an array and take the average of that array. When the array is full we loop around start from the beginning.
 
You could do that, but then you would get a little step response if your signal is changing. Might be fine if you are not using the signal to control anything.

For our application (Siemens) we write the values to an array and take the average of that array. When the array is full we loop around start from the beginning.

Do you automatically get an avg of the array, or do you divide by number of values in the array?
 
I total the entries and divide by the number of entries. The same as you described in your first post :).

I do have to mention that in something like an Arduino, I do follow your version, but with a much faster cycle:

store0 = 0;
for (int pass = 0; pass < 100; pass++) {
store0 = store0 + analogRead(A0);
}
MoistureAi = store0/100;
 
Last edited:
Here is a function block I use. K1 and Unfiltered are 32-bit REALs and are inputs to the block. Filtered is the 32-bit REAL output. K1 is a value between 0 and 1. A value of 1 produces no filtering. The smaller the value of K1, the longer the lag between the filtered and unfiltered values and the longer it takes to respond to a step change in the unfiltered signal.
 
Since you aren't operating on a system model I'm not sure what this implementation will get you over a standard first order filter form (Filtered replaced Projected in the multiply by K2) other than slightly slower step response.

Keith
 
Why not use Kalman filter? Just kidding.
Knowing what and why makes a big difference.
Why do I always have to ask questions?
Also, an analog filter doesn't average. An analog filter implements an IIR filter or infinite impulse response. On this forum people usually implement simple first order low pass filters.

Boneless is right about the step jump. If you want to average the readings the start with a circular que or FIFO 8 items long. Initialize a SUM to 0. Every 250 ms remove the item at the head of the FIFO and subtract it from the SUM. Add the new value to the SUM and then put it into the FIFO. Now divide the SUM by the number of items in the FIFO. This way you get a new average every 250 ms.
 
Here is a function block I use. K1 and Unfiltered are 32-bit REALs and are inputs to the block. Filtered is the 32-bit REAL output. K1 is a value between 0 and 1. A value of 1 produces no filtering. The smaller the value of K1, the longer the lag between the filtered and unfiltered values and the longer it takes to respond to a step change in the unfiltered signal.

Thanks Steve. I will check it out.

Looks like GE logic even...
 
Last edited:
Here is a function block I use. K1 and Unfiltered are 32-bit REALs and are inputs to the block. Filtered is the 32-bit REAL output. K1 is a value between 0 and 1. A value of 1 produces no filtering. The smaller the value of K1, the longer the lag between the filtered and unfiltered values and the longer it takes to respond to a step change in the unfiltered signal.

I guess if K1 is a value between 0 and 1.... with 1 being NO filtering....I would be using a setting of 1.00 to 0.00 OR 1.000 to 0.000? How sensitive is K1?
 

Similar Topics

We are considering dropping our UL membership because most of our customers do not care if we are a 508A shop. However, there may be times when a...
Replies
8
Views
363
I'm looking for some clarification if anyone here is familiar with UL698a panels. Panel is out of zone/class'd area. with thermocouples extending...
Replies
0
Views
113
Hey guys, last week I posted part 1 of a series of OPC UA articles in Node-RED. That article covered some important concepts of OPC UA and how...
Replies
8
Views
3,906
Hey everyone I have an 1756-CNBR/E CONTROLNET goes faulty sometimes and now it's still faulty until I restart the main racks It shows this message...
Replies
0
Views
870
Good afternoon all I'm having some troubles trying to go online with a twincat3 project that has been developed with another laptop (I will call...
Replies
1
Views
1,562
Back
Top Bottom