04-19-2011 05:17 PM - edited 04-19-2011 05:26 PM
Say I have a simulated sine wave, I'd like to have an indicator show the time at which the wave's derivative equals zero. How would I go about this?'
EDIT: For simplicity, say I only care about the first time the signal equals zero.
04-19-2011 05:55 PM
Maybe I am over simplifying it but if you input your derivative in place of the x control the indicator will change to the time x=0
04-20-2011 08:01 AM - edited 04-20-2011 08:04 AM
Double = zero is a poor practice. Why? Because of the way numbers are represented in binary in the computer the result of a calculation which is nominally zero may actually appear as a very tiny value. It is better to compare to a range of values near zero. You can use "Machine epsilon" (a predefined constant equal to the smallest non-zero value available on your computer), or some larger tolerance chosen on the basis of knowledge of your process. For example if you have an 8-bit A/D converter with a 10 V full scale range, the smallest signal you can measure is 10/256 = 0.03906... In such a system anything less than about 0.02 is probably zero.
Use In Range and Coerce? rather than Equals Zero?
Edit: The other issue is that a numerical derivative may never be zero. If a data sample does not lie exactly at the peak the derivative values will change sign on either side of the peak but may never be close to zero.
Lynn
04-20-2011 09:50 AM
I understand your point and in cases like you mentioned I would probably end up doing something like that.
But I have ran into more cases where doubles will equal exactly zero and need to act accordingly.
First thing off the top of my head, I work for a power supply manufacturer and often need to test transient response of our PSU's by step loading 0 to full load and full load to 0. When I step from full load to 0 I not only send the (double) value 0 to the electronic load but also use a (x)=0 to turn the load's input relay off fully disconnecting it from the UUT. My vi's also have the opposite where (x)<>0 engages the loads input relay.
Notice I said (x)<>0 because the load has an internal crowbar circuit for short circuit testing, I set the load value to -1 and the load applies a short circuit.
04-20-2011 10:32 AM
If you are sending a zero from a control or something like that you are probably OK. You do need to watch controls which have the increment set to a fractional value. Increments which are not exact binary fractions can cause round-off errors at zero. Calculations which should result in zero are more likely to cause problems.
Lynn