Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Minimum value problem?

Author
Message
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 10th Jun 2010 15:00
How would I stop my minimum value from going to low.

I have this weather station that sends a signal to say what the outside temperature is, however some times it misses a beat and returns zero, which is not to good when the last temperature was 16.5c.

so I how would I go about it ignoring the zero expect when it is around about zero.

this what I use at the moment.



cheers.

Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Jun 2010 15:21
Keep track of the last temperature, and if the new temp is too different from the last, ignore it or use the last temp.

This could be something as simple as:


sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 10th Jun 2010 15:37 Edited at: 10th Jun 2010 15:40
How often does it return the temperature? The problem would be that if it's only once every few hours then the temp could change by over 5 degrees and be ignored. And if it returns a temp every few minutes, the current temp is 4deg and you get an erronous 0, it >will< be recorded as valid.

You could just completely ignore any 0's. Even if that is the correct temperature you will only ever be 1 degree out either way, and then only for a short while if the temp is rising/falling. Actually, if the recorder returns fractions of a degree (looking at your 16.5 example) then it will only ever be a tenth out. (Or the resolution of your sensor) Edit: And if you're averaging over time it would become insignificant.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 10th Jun 2010 15:44
cheers IanM seem to be doing it right now, tried this before but I think I had the value sums the wrong way round.

Dark Physics makes any hot drink go cold.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 10th Jun 2010 15:47
@sladeiw

its checking it every 5 seconds so you can see why it would annoying when it comes up with zero.

Dark Physics makes any hot drink go cold.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 10th Jun 2010 17:26
Quote: "its checking it every 5 seconds so you can see why it would annoying when it comes up with zero."


Absolutely! If it's returning every 5 seconds I would personally still just ignore exact 0`s. Your maximum error will only be the resolution of the temp sensor (eg. 0.01c or 0.01c) Otherwise the max error could be whatever whatever difference value you choose to compare.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 10th Jun 2010 17:34 Edited at: 10th Jun 2010 17:38
I see I forgoten to say that it displays max and min temperature figure and a min max line on the screen, so every time I got a zero then the min showed zero.

Anyhow the above idea has fixed the sudden error.

picture of the output, not easy to read but still working on getting the values right. persention will come later.



Dark Physics makes any hot drink go cold.
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 10th Jun 2010 18:00
What a cool App. Top marks for novel application of DBPro!

GrumpyOne - the natural state of the programmer
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 10th Jun 2010 18:15
put in one wire in the search box and you can look at the development thread.

or link

Dark Physics makes any hot drink go cold.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 13th Jun 2010 17:46
Now I am use IanM's code above like so



Now I thought If I add an or it would allow me to check if it was higher than five like so



however this does do it just ingors all any movement it the tempauture.

Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Jun 2010 19:33
If the difference is greater than 5 or less than 5, use the last temperature? Or in other words, if the temp difference isn't exactly 5, use the last temp. That's definitely got to be wrong.

I don't know what you are trying to do here, so I can't suggest any code.

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 13th Jun 2010 20:06 Edited at: 13th Jun 2010 20:06
Simplest solution as I suggested is ignore ANY 0. That's it, job done. Your screenshot shows temperature to 100th of a degree, so it means the max error in your readings will be 1/100th degree, and only when the actual temp is 0.

If you really want to have 100% accuracy, since the sensor returns results every 5 seconds, you could take 3 readings. Discard the highest and lowest and use the middle reading.

If you look at the code you're using now, you will definitely get errors when the temp is below 5 degrees:

HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 13th Jun 2010 23:02
ok. I get what you are saying about it returning zero, so if i lower the test variable to 1.0, it should catch any thing that jumps higher than the value its on.

eg

value is 14.38c so >1.0 or <1.0 should stop it jumping when it returns a zero or is higher than the last value.


so is there away to keep in check when the value could be -20 to +30c, I could check it in both C and F.

Dark Physics makes any hot drink go cold.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 13th Jun 2010 23:09 Edited at: 13th Jun 2010 23:11
Quote: "so if i lower the test variable to 1.0,"


Unfortunately this will still give an error, just in a more restricted range.



Either method I posted would work whatever the temp range. If you want I could write a quick example of the 3 value discard method?
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 13th Jun 2010 23:42
this what I've put in now I think works OK.



Dark Physics makes any hot drink go cold.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 14th Jun 2010 02:25
I'm lost what you're trying to achive there!
I don't know if you meant to, but don't forget precedence when dividing prevtemp# by 2.0. Do you mean
to average the values?
At the end of the day if it's working for you then

Maybe create a test routine that simulates a temperature movement from -20 to +30 and back again (with a random chance of a 0 being thrown in) and see if you get the expected results.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 14th Jun 2010 18:56
oops, those pesky brackets, I think I should be doing as you have shown, I'll get there one day.

Cheers sladeiw.

Dark Physics makes any hot drink go cold.
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 15th Jun 2010 15:53
found this bit of code from qbasic that finds the min and max of inputed numbers.

Now I can see what it does and how it works, however what are these two bits doing at the start.



all code



Dark Physics makes any hot drink go cold.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 15th Jun 2010 18:54 Edited at: 15th Jun 2010 18:59
Scientific Notation, AFAIK DBpro dosen't support it but I've never tried it so not sure.
http://en.wikipedia.org/wiki/Scientific_notation

If this is still for your temperatures then just set iMAX to -100 and iMIN to +100, this ensures they will always get at least one valid result from your temp data. (Assuming you're not going to deploy this on any other planets!)

If you are still trying to eliminate the erronous 0's from your sensor then averaging will still affect the results. You want the median number rather than the average. To get the median from 3 numbers simply discard the highest and lowest values out of the 3.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Jun 2010 20:25
Since the last convention DBPro does support scientific notation

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 15th Jun 2010 20:27 Edited at: 15th Jun 2010 20:28
Quote: "Since the last convention DBPro does support scientific notation "


So it does!

The ace of the spade
17
Years of Service
User Offline
Joined: 8th May 2009
Location: Everywhere
Posted: 19th Jun 2010 16:42
So... just skimming through here, a couple of things...


Unless I'm misreading something, this is just going to set here.tnow to prevTemp#, sense you set lastTemp to prevTemp before taking the average.

Quote: "Your screenshot shows temperature to 100th of a degree, so it means the max error in your readings will be 1/100th degree, and only when the actual temp is 0."
That doesn't mean that his input is actually that accurate - its just being stored that accurately. It could be coming from a device thats only accurate within a 10th of a degree, or even just accurate to the nearest degree.Plus, 0C is definitely a reasonable value to expect when it comes to temperatures.

Also, I don't know how your data source works exactly, so this may not be applicable, but you mite want to also keep track of how much time has elapsed sense the last time you received input. That way, if you're cut off from your source for an hour, and the temperature changes drastically, you can take into account how much time has passed before deciding that the temperature measurement is erroneous.

“It is not clear that intelligence has any long-term survival value” -Stephen Hawking

Login to post a reply

Server time is: 2026-07-25 16:21:08
Your offset time is: 2026-07-25 16:21:08