Sign in to follow this  
Followers 0
Conor

Smooth an Analogue signal

14 posts in this topic

Hi, This problem is on a PLC5. I have an Analogue signal coming in from an Ultrasonic. This Ultrasonic is process critical, so I can't adjust the settings in the panel for the Ultrasonic. The value coming back reads ok, but every between 2 and 5 mins the value drops to about 1/2 (half) or about 10 seconds. I was wonder what is the best way of "Smoothing" out this signal, i.e. take the bounce out of it. I was thinking of using an array. My signal is coming in on N11:14 and there is a compute expression (F8:31) to convert it to m3 to display on a Scada. If I take the value going into F8:31 and move it into N17:9 and step it back to N17:0, what would be the best way of getting the average value based on this? Or is there a better way of doing it? Thanks, Conor. EDIT: Is it better to smooth the signal coming in on N11:14, via an array at N17:0 ? Edited by Conor

Share this post


Link to post
Share on other sites
Without getting too into too much maths (http://en.wikipedia.org/wiki/Digital_filter), the simplest way to implement a filter is to average the last N samples... so you do something like this... On start-up or reset: initialise the array so that every element is either zero (will mean that the system ramps up from zero to the actual feedback value) or the current feedback value (no ramp time but if you have a bad value on initialisation it can upset the system a bit). On IO update or periodically: move every element in the array down one except the last element move the current feedback value into the first element of the array average the elements of the array (sum of the samples divided by the number of samples) and store the result as the filtered signal value somewhere. You may wish to consider what this dip in the signal actually is though, normally interferance is not a 10 second thing.. seems curious.

Share this post


Link to post
Share on other sites
Ok, I have done the following. MOV n17:101 to N17:100 length 9 Then COP N11:14 into N17:109 Then MOV N17:100 into N17:110 I am then using the same expression as stated above to calculate a new F8:410 (above F8:31) I am still seeing the dip. So, I put in a timer (3500 ms) that MOV N17:100 into N17:110. But then the dip stays on this for 3.5 secs. Conor Edited by Conor

Share this post


Link to post
Share on other sites
See filter text below Filtering.txt

Share this post


Link to post
Share on other sites
I've used the filter logic Mickey presents on a load cell input with a PLC5 for some time now. We update the value each scan and use a conditioning value of 0.05. Works like a charm. For your example let F8:42 be the filtered value and F8:40 - 0.05 the conditioning value. On First Scan or process Startup Move F8:31 to F8:42 Then every scan therafter F8:42 = F8:42 + (F8:40 *(F8:42 - F8:31)) F8:42 becomes your smoothed / filtered value.

Share this post


Link to post
Share on other sites
Thanks guys. I will check out in the morning

Share this post


Link to post
Share on other sites
So far these are all IID or FIR filters. You may also want to consider robust statistics instead. For instance, what's the problem with averages? A single outlier can totally screw up the average value. What's the solution? Use the median. In practice medians give you almost identical results as averages except that when you have outliers, the outliers tend to get ignored. For example, say you have 1, 2, 3, 4, 5. What's the average? The median? 3. Now imagine you have 1, 2, 3, 100, 5. What's the average? 22.2. What's the median? 3. You have to use a sort function to implement a median which makes it compute intensive, but it works extremely well for what it does. One problem with this simple example is that a simple median assumes that your data is constant, which may not be true. In the non-robust world, you can use either LPC (linear predictive coding) or even a simple linear interpolation filter (fit the data to a straight line) to try to estimate the correct value for a point while taking into account the fact that the data might be changing over time. In robust statistics to fit some data to a straight line, you calculate the median of the two-point differences to calculate a "slope", and calculate the Y-intercept using a similar conversion of the linear regression calculation into "robust statistics" form. If you google that phrase, you will find a lot more information than what I've described here, but this is the basic concept, and there's also a whole set of mathematics quantifying how well a particular robust statistical method deals with outliers. Unfortunately I don't know of a particular "robust statistics for dummies" document explaining it in "layman's" terms.

Share this post


Link to post
Share on other sites
Hi Paul, That was one thing I was thinking of, averages, but as you said this won't work. Basically I have an Analogue signal coming in. I then do a calculation to turn this into m3 for display on Scada. When I copy into the array I have something like this (an example); N17:100 -- 26804 N17:101 -- 26804 N17:102 -- 26804 N17:103 -- 14689 N17:104 -- 14689 N17:105 -- 26804 N17:106 -- 26804 N17:107 -- 26804 N17:108 -- 26804 N17:109 -- 26804 As you have said if I do an average of these then the figure is out. I will look into the maths for doing a different calculation as per what you have mentioned. Also, my signal coming in is like a sin wave Thanks again, Conor Edited by Conor

Share this post


Link to post
Share on other sites
I think you are chasing your tail trying to program around a real world problem. It's one thing to filter out spikes and dips that are milliseconds in duration, but ten seconds? Either the real process variable being measured is really dropping or the sensor/wiring has some fault. Forgive me if I have misunderstood. Anecdote: Many years ago we had ultrasonic height detectors that were extremely sensitive to air leaks. An air leak could create a frequency that would interfere with the sensor signal and cause it to go whacky. These were installed very close to some air flotation shafts (air leak by design). We had to be very careful how we aimed the air bars and the sensors to avoid problems similar to yours. And after learning the hard way, the first troubleshooting step became looking and listening for damaged hoses and leaking valves. When we went with newer sensors, they did not exhibit the same problem. Paul Edited by OkiePC

Share this post


Link to post
Share on other sites
Hi Paul, You are correct, I should really look into fixing the problem and not trying to code it out. My problem is with an Ultrasonic as well. It is measuring the level of gas in a Bio gas balloon. Thanks again, Conor

Share this post


Link to post
Share on other sites
Not to say that this is the answer in your particular case, but I've never gone wrong with sensors from Hyde Park. You can get a sensor from them with less than a half centimeter accuracy over a 2 meter range (1/4" or less over 6 feet). Worked extremely well and the beam is fairly narrow so it tended to be immune to noise. If you need tighter, then you will have to accept a narrower range. If you switch to laser, I've had reasonably good luck with units from Banner as well as the one from IFM Efector. These get you out to 10 meters or so with roughly the same accuracy, or you can get tighter in with better accuracy. My former boss also raved about PepperL-Fuchs for the same kind of sensors. Although the infrared ones are OK, I preferred the visible light ones because it's much easier to diagnose trouble and line them up.

Share this post


Link to post
Share on other sites
It is measuring the level of gas in a Bio gas balloon. how does that work? what is target surface? is it baloon wall or something else? what range? i never liked ultrasound sensors (reflections, noise, too wide cone, need to sync when delaing with more than etc.). we have used lasers on many jobs and they are much easier to deal with (plug and play), tiny beam, high accuracy etc. my favourite ones are from Baumer (can't beat price and performance). IFM has analog sensor with greater range and for much lower price but for such low price you can't get everything (slow update, accuracy not very good, thermaly not compensated and drifts a bit etc.) but this is excelent if you can live with some 5-8mm resolution or as a photoeye(s) replacement (specially long range).

Share this post


Link to post
Share on other sites
Hi guys, I have checked this out. Basically we have an outter membrain, and an inner membrain. The Bio gas is filled into the innner membrain, and the Ultrasonic measures the level of this. The unit measuring it is a Milltronics, Airanger SPL. Conor.

Share this post


Link to post
Share on other sites
Wow, haven't seen that name in a long time (10 years). As far as I know, the "Milltronics" name lives on but the company has long since been bought out. At the time they made very solid equipment but it's getting very long in the tooth now. I'd go shopping sensor-wise, and that's probably part of your problem. I definitely recall the Milltronics stuff would routinely drift and wander for a few seconds once in a while for no possible explanation. For the application, I'd definitely be looking at either laser or more ultrasonics since you're after distance. Hyde Park stops at 8 meters. Beyond that, I think Banner has some pretty long range stuff, too. Radar might work but it strongly depends on how much of a reflected signature you can get off the membrane. What's the total/change in distance you need to measure?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0