What I am trying to do is compare the output of a waveform from the wave generator to a certain value to trigger some event. However, despite using comparison values that are known to be in the waveform for sure, the boolean comparison never yields true. I am guessing it has something to do with the signal generation speed and the boolean not seeing every value output in the signal.
Do you all know of the correct or better way to accomplish this task?
Solved! Go to Solution.
Without seeing your code it is hard to say for sure, but I suspect that the problem is the issue of equality comparison of floating point numbers. If just one of the 64 bits in the binary representation of a DBL differs from the value being compared, the result is False.
Two options: (1) Use a range of values and the In Range & Coerce function or (2) use Greater Than or Equal along with some logic to locate the first transition in the data set.
I see what you're saying. The dynamic signal from the generator had already been converted to a double, but it may need further manipulation. As for the using the In Range and Greater than or Equal to function, I've tried that and is where I stand right now to get the program working. The only problem with that is when you adjust frequnecy or amplitude you also have to adjust the thresholds for the those two functions accordingly. This is because at different wave parameters the outputs also change somewhat.
Could the comparison possibly not work because of sampling rate? (1000 samples/sec, for 100 samples in the wave generator).
No. The sampling rate has nothing to do with the comparison. Please post your VI with typicla values for the data saved as default. That way we can see what you are doing and provide suggestions to resolve the issue.
Sorry about that,
The original VI is not with me at the moment. However, I am attaching a simple VI that represents the corresponding part in the main VI. This should contain the scope of the problem.
The evil Dynamic Data Type (DDT) strikes again! The output of the Express VI which generates the simulated signal is Dynamic Data Type. This obscures the structure of the underlying data. The conversion you chose was to a single scalar. The simulated signal contains 100 samples. Which one does the conversion select? The first, I think, or maybe, the last. It does not tell you. But what are the chances that the one of one hundred which you compare was actually the one you wanted? You really want to compare all of them.
Rather than use the Express VI with all its problems, I prefer to use something like Basic Function Generator.vi from the Signal Processing >> Waveform Generation palette. Its output is the Waveform data type, which is a cluster of an array of doubles Y, dt = the sampling interval, and t0 = the start time.
I extract the array of samples and compare all of them to zero. Then search the boolean array for a True value.
Note also that for non-integer values of frequency the minimum value in the Y array may not be zero even though the amplitude and offset are the same.