Smoothing analog

cdnrookie

Member
Join Date
Apr 2013
Location
Canada
Posts
112
Good Morning,

So i have attached some really crude programming to try and work around my inability to smooth an anlog signal (actually several)

The problem I face is that I now have to add another 3 monometers which will mean some very confusing and lengthy programming.

Who wants to tear apart my rookie mistakes and give me some direction? lol
 
I cant open your file but its fairly easy to make a function of.

you would have the following
AnalogIn :input
FilterSize :intput
Memory : Inputoutput/memory
FilterdSignal :eek:utput

Every cycle you add the analog value to the memory until you reach the number of times specified by FilterSize. Then divide this by the FilterSize and this is the filtered value you can move to the FilterdSignal. Then reset the memory to 0 and start over. If the the area where you write the FilterdSignal to keeps its value than you dont need anything extra. Otherwise you have to keep the FilterSignal the correct value.
 
Last edited:
See text for a simple filter.

Your program posted does not show any attempt to smooth an analog input.(that I can see or maybe "smoothing" has a different meaning in Canada)

FV=FV+C(NV-FV)
Where:
FV= Filtered value
C= constant (range 0-.99) The smaller the number the more dampening.
NV= New Value

Filtered Value= Filtered Value+Constant*(New Value-Filtered Value)

New Value = Unfiltered Value

Constant= 0.00-.99 The smaller the number the more damping.
 
Last edited:
I use Mickeys method a lot. I have found that I need to condition the frequency of the filtering to slow it down a bit. I often precede the filter math with a bit from the free running clock and a oneshot.

On a side note, the free running clock is much faster in a Micrologix 1400 than it is in a SLC 5/03. I might use the bit S:4/4 or 5 in a SLC to update the filter every 320 or 640ms, but in the Micrologix I end up using bit 10 or 11. I could just set the filter number to a ridiculously small value and let it run as fast as it can, but I prefer the filter logic to be consistent regardless of scan time by triggering it with a timer or timebase I can control.
 
Last edited:
Thanks mickey

My original had a FIFO setup but then it just got really lenghty given that there are 6 analogs

Ill try your method........
 
We really should know what the analog signal is measuring.
Did you know you can cascade filters?
Code:
IV=IV+C(NV-IV)
FV=FV+C(IV-FV)
IV is an intermediate filtered value.
Now the noise is attenuated at twice the rate.
Also, one really should learn how to calculate C so the cut off frequency can be calculated.
 
I use a time constant to smooth incoming data on an analog signal.
The incoming signal is in y(t) = some data location. The time constant here is .005 and “Saved_Data” is just some other data location. This works really well.
.
Saved_Data = y(t) x 0.005 + (1 - .005) x Saved_Data
 
Last edited:
Also, one really should learn how to calculate C so the cut off frequency can be calculated.
Peter, you've piqued my interest. I'm sure someone went over this with me in a class 25 years ago, but I'm not presently aware of how C is calculated. Can you refresh my memory or point me in the right direction? Thanks in advance.
 
The simplest form of exponential smoothing is given by the formula:

s_t = \alpha \cdot x_{t} + (1-\alpha) \cdot s_{t-1}.
where α is the smoothing factor, and 0 < α < 1. In other words, the smoothed statistic st is a simple weighted average of the current observation xt and the previous smoothed statistic st−1. The term smoothing factor applied to α here is something of a misnomer, as larger values of α actually reduce the level of smoothing, and in the limiting case with α = 1 the output series is just the same as the original series. Simple exponential smoothing is easily applied, and it produces a smoothed statistic as soon as two observations are available.

Values of α close to one have less of a smoothing effect and give greater weight to recent changes in the data, while values of α closer to zero have a greater smoothing effect and are less responsive to recent changes. There is no formally correct procedure for choosing α. Sometimes the statistician’s judgment is used to choose an appropriate factor. Alternatively, a statistical technique may be used to optimize the value of α. For example, the method of least squares might be used to determine the value of α for which the sum of the quantities (sn-1 − xn-1)2 is minimized.

Unlike some other smoothing methods, such as the simple moving average, this technique does not require any minimum number of observations to be made before it begins to produce results. In practice, however, a “good average” will not be achieved until several samples have been averaged together; for example, a constant signal will take approximately 3/α stages to reach 95% of the actual value.[citation needed] To accurately reconstruct the original signal without information loss all stages of the exponential moving average must also be available, because older samples decay in weight exponentially. This is in contrast to a simple moving average, in which some samples can be skipped without as much loss of information due to the constant weighting of samples within the average. If a known number of samples will be missed, one can adjust a weighted average for this as well, by giving equal weight to the new sample and all those to be skipped.

This simple form of exponential smoothing is also known as an exponentially weighted moving average (EWMA). Technically it can also be classified as an Autoregressive integrated moving average (ARIMA) (0,1,1) model with no constant term.[6]
 
You can also build a FIFO stepper that takes a sample every second (or whatever) and add them up and divide by the total in the FIFO series.
This will give you a moving average of samples.
 

Similar Topics

Hello, I'm pretty new to RSLogix 500. I'm trying to smooth out the raw analog input. Current 4-20ma. I'm in an environment that I can not control...
Replies
5
Views
2,993
Hello, I am using a P1000 CPU (P1-540) with a P1-04DAL-2 and a P1-04ADL-2 I tried doing a data transfer now I am trying to scale them both...
Replies
0
Views
1,111
Mickey has posted a formula for doing this that a lot of people seem to make use of. Could somebody please give a simple "Ladder" diagram as to...
Replies
22
Views
12,277
I am trying to make an input less jumpy. The monitored input has large spikes, and changes too fast. I am trying to smooth it out. I am using...
Replies
2
Views
2,144
Good morning guys, So i know this is extremely basic, but im just starting our with analog signals and trying to wrap my head around it. I...
Replies
10
Views
4,347
Back
Top Bottom