Ultrasonic Smoothing Data

I am trying to smooth data from my ultrasonic sensor and have no idea how to!

Anyone have a smoothing function?

Thank you x

I've deleted your other cross-post @steve-unicorn.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

steve-unicorn:
I am trying to smooth data from my ultrasonic sensor and have no idea how to!

Anyone have a smoothing function?

Thank you

here’s a simple LPF algorithm.

// low-pass filter algorithm, given input samples, size of array and weighting factor
float lowpass(const float samples[], int size, float weighting){
    float data[size], lpf=0;
    
    data[0] = weighting*samples[0];
 
    for (int i = 1; i<size; ++i){
        data[i] = weighting*(samples[i]-data[i-1])+ data[i-1];
        lpf+=data[i-1];
    }
    
    lpf+=data[size-1];
 
 return lpf/size;
}
}

or a moving average algorithm

hope that helps…

An += (Sn - An-1) * K

where An is the current average, Sn the current sample and K, a value < 1 which is the time constant for averaging.

I dont understand the LPF algorithm or how to connect this to my ultrasonic sensor data, please can you explain

steve-unicorn:
I dont understand the LPF algorithm or how to connect this to my ultrasonic sensor data, please can you explain

please post the current code you have to read your ultrasonic sensor