03-18-2019 09:53 AM
Hello!
I am attempting to count how many times a signal turns beyond a specific threshold. For example, an initial peak or valley occurs in the signal with a value of 10. I want to compare this value of 10 to the next peak/valley data points until I find one that is greater or less than 5/-5 from that value of 10 (i.e. at least 15/-15). So 14 would not count and the program would continue to look for the next peak/valley. If a peak/valley value was 22, it would then save this as a "turn" on a counter and report the total difference between the initial and new value (ie if the initial value was 10 and the new value was 22, it would be a difference of 12 and add "1" to an overall counter). This process would then continue from the value 22 and keep comparing peak/valleys to that new number of 22 until a new peak/valley is greater or less than 5/-5 of the value of 20 (ie at least 17/27). The values may be negative or positive in the overall comparisons.
I have been able to identify the peak/valleys, but when I attempt to compare them using shift registers I cant figure out how to perform it this way. I can compare each data point to the next etc, but to perform a function as described I have been unsuccessful. I am unsure if a shift register is the best way to accomplish this and I am open to new ideas/suggestions. I hope someone has experience performing something similar to this and would be willing to guide me in the right direction.
Thank you for your time!
Solved! Go to Solution.
03-18-2019 10:11 AM - edited 03-18-2019 10:14 AM
Use a feedback node and a Select instead of shift registers. Wire the boolean to the Select of whether or not you hit a peak/valley that was valid for your logic. On the true case of the Select, wire in the new peak/valley value and on the false case wire in the output of the Feedback node. The result of the Select should go into the Feedback node.
03-18-2019 10:11 AM
@CSmith8 wrote:
I have been able to identify the peak/valleys, but when I attempt to compare them using shift registers I cant figure out how to perform it this way.
This is usually the time it would help to show us some code so we can get the context, see what's wrong, and suggest a solution.
03-18-2019 04:54 PM
@heath89 wrote:
Use a feedback node and a Select instead of shift registers. Wire the boolean to the Select of whether or not you hit a peak/valley that was valid for your logic. On the true case of the Select, wire in the new peak/valley value and on the false case wire in the output of the Feedback node. The result of the Select should go into the Feedback node.
I would say, "Use whatever method is comfortable to you. If you are comfortable with shift registers, use that. If you're comfortable using feedback nodes, then use that, instead."
The only real advantage I can see with a feedback node (in this case) is that you don't have wires running across your FOR loop.
03-18-2019 05:03 PM - edited 03-18-2019 05:04 PM
@billko wrote:
@heath89 wrote:
Use a feedback node and a Select instead of shift registers. Wire the boolean to the Select of whether or not you hit a peak/valley that was valid for your logic. On the true case of the Select, wire in the new peak/valley value and on the false case wire in the output of the Feedback node. The result of the Select should go into the Feedback node.
I would say, "Use whatever method is comfortable to you. If you are comfortable with shift registers, use that. If you're comfortable using feedback nodes, then use that, instead."
The only real advantage I can see with a feedback node (in this case) is that you don't have wires running across your FOR loop.
Good point, I guess the Select was the part that I should have emphasized. Make sure you don't update your shift register every iteration. Only change it when the new value is a peak/valley. Like was said earlier, It would help if we could see the code
03-19-2019 07:53 AM
Thank you all for your input. I took your example and it was quite helpful. Spent some time yesterday and today playing with feedback loops, as these were new for me. I was able to implement this into my program and it has worked great so far. Thank you for everyone who helped!