Need some help with smoothing an output

Hello All, I could use a direction here.

I’m using an ADXL337 G sensor, when I bench test the sensor i get a nice clean trace which is usable.

when i have the sensor in car i get a messy trace as seen in the second picture, its totally unusable as an input.

is there a Filter node or smoothing node that I can use?

Datalogger april 1.xodball (21.7 KB)

You can try something like gweimer/utils/running-avg, but anything you do to smooth out the noise is going to reduce response time if that is important (like a balance sensor would be). There might be other libraries that can provide better response while still filtering some of the noise.

Is the noise problem only when you are running the motors? Could be electrical noise from the motors or controller, or power fluctuations. If possible, it would be better to fix the problem instead of trying to hide it.

I’ll try that!

It not to run any kind of balancing type function, its to add pwm duty cycle to stiffen magnetic shocks.

No motors are on the circuit and both time it was running off a 9v battery

Question tho, why have the extra inputs and outputs on your node if the are not for use?


If the same battery is powering other items (like your magnetic shocks), you may well be drawing too much current for a 9V battery, causing your fluctuations. If you have not added those yet, or they have a separate battery pack, it might still be electrical noise from the controller or shocks, but besides suggesting the addition of a small capacitor, I can’t help much with that. I’m not even sure what size or where you would need to add it. (In RC cars, a small capacity is sometimes added between the terminals of the motor to reduce electrical noise.)

If you had a clean signal on the bench, you might try disconnecting parts one at a time on the car to determine which one(s) are causing the fluctuations.

Haven’t connected anything to the system, it was just a Prototyping making sure the sensor works as intended run.

I’m pretty sure its from the vibrations of the car when its in motion.

this is for an actual car by the way, so it will eventually be powered by the 12v system with Mosfets driving the shocks, ride height sensors determining velocity etc,

this is just the first step of actual on car testing since everything is only bench tested at the moment.

Ah…if you are testing the G sensor in a real car, that would likely produce a lot of noise in the output of the G sensor since there will be a lot of vibration. You might be able to mount your sensor as a way to provide a sort of mechanical averaging rather than trying to do it in code (or maybe mechanical mount to reduce the bulk of the noise and filter the rest in software).

The trouble with doing it in software is that you will only be taking samples from the graphs you show. If you get “unlucky”, you might sample adjacent vibration peaks or both sides of a peak. If you take too many samples or space them too far apart, the “real” peaks could be done before you start to see them; too few samples and you still get a lot of noise. It is likely to be a balancing act between how often you sample and how many samples you average. If you are trying to stiffen shocks before the car bottoms out, you probably need pretty quick response time.

If the running average doesn’t work for you, maybe using gweimer/utils/queue-buffer (or just setting up your own buffer nodes) to save the last few values and compare the min and max of those values will allow you to see quick changes but still filter out some noise. I’m sure there are other options for comparing/filtering also.

I was thinking of using a thick foam/rubber to help dampen some vibrations as well.

the G-sensor isn’t critical in terms of it needing to be perfect, it’s more to help control nose dive, squat and leaning, just to slow it down

Ever owned a car where if the antenna wasn’t properly connected, or the radio station was slightly off, you’d get the electrical buzz/whine?

Try insulating your wires leading into the G sensor, so they can’t pick up electrical noise from any wires they may be running next to/across, and also put a balun in line to limit noises from elsewhere in the vehicle

my 3c worth may not be worthy, but it’s worth a shot

How do i use the running average node? I set it to 10, 100 samples and I didn’t see a difference?

I ended up making 20 Clip Boolean Nodes so when the sensor is outputing between say 1.65v and 1.75 I get a .1G and then using fade to smooth it out. kinda works but i think the running average combined with Fade will work really well once i figure it out

You adjust the size of the running-avg node so the number of dummy pins matches how many numbers you want to average together.

VAL is where you input the numbers to be averaged. Pulse the UPD pin to tell the node when to read VAL & add it as a new number. The AVG output pin will have the average. Note that if you expand the node to include dumy3, The initial AVG will be 0 because everything initializes to zero. Sending one pulse to UPD will cause the 1st number to update to VAL, but the other 2 will still be zero until two more pulses are sent to update all 3 internal values to average together. If you keep sending pulse with the same VAL, the AVG will just be VAL. The unlabelled pins should not be used; they are used internally to pass the variadic data.

utils-example-avg is a demonstration of how to use the running-avg node.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.