a way of taking out very different value before calculating an average

i'm programming in j# which receives GPS data.

I noticed that sometimes the GPS give very 'bad' or 'wrong' data from time to time.

I designed a program that calculates something according to the data it receives

but since sometime i get some bad datas i decided to take the average data of every 3 datas

for example, if i'm using the bearing, i would get three bearings and get the average of the three and use them as the value.

but sometimes one of the three values would read very incorrect data.

i was wandering if there was an algorithm of some sort to take out that bad data or give less weight to it when doing the average.


bearing1 = 39
bearing2 = 43
bearing3 = 05

when i get this, i don't want to average the three but actually get soemthing in between 39 and 43

please help

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
if you know the valid range you could check each values falls inside it and ignore any value outside.
shpark82Author Commented:
actually even the wrong values are always going to be in range between 0 to 360 but it is just that sometimes the reading is incorrect by quite a bit
Mick BarryJava DeveloperCommented:
you need to know what is correct or incorrect, do u have a way of determing that. eg. how would u do ity manually
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

shpark82Author Commented:
compare the three and see which of the three are completely different from others

for example if i had a sample of 10 readings


i would know that 33 is a bad read and therefore put much less weight on it when calculating the average of these

standard deviation or something? not sure
Mick BarryJava DeveloperCommented:
perhaps do two passes, first to take the average of all numbers
and the 2nd to strip out any numbers that are drastically outside that average

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Take the median perhaps instead of the mean. (39 in your example)
first to take the average of all numbers
and the 2nd to strip out any numbers that are drastically outside that average

If you're going to do it that way, you need to do it the other way around
Mayank SAssociate Director - Product EngineeringCommented:
Are you using any standard J# GPS API?
shpark82Author Commented:
i'm using J# express

free version from microsoft

how do you calculate median?

what is the difference between mean (average) and median?
>>how do you calculate median?

Sort them and take the middle value

>>what is the difference ...

(See above)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.