Running Total with Sample and Hold?

ginsu777's picture

I have been trying to take a single sample every 15 seconds from a number I am calculating and then display as it increments every minute - only incrementing when it gets to the next whole number. The reason for this confusion is that the number is calories/minute based on a heart rate that is sampled every 2 seconds. So I only want to calculate and store and augment the number every minute.

In any event, I tried the INTEGRATOR patch, but it seems to go haywire adding things up fast. I also tried different multiplexers and triggers but with no luck.

Any ideas how to calculate and display a running total sampled from a stream of calculated numbers? Side issue: rounding. The numbers calculated are usually like 0.0254689 every 2 seconds I dont even want to count it towards the total unless it reaches something like .20 or .30

The included example wont work unless you can input some numbers on the serial port or replace the serial thing with some numbers of your own.

SampleHold.qtz13.95 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.'s picture
Re: Running Total with Sample and Hold?

This what you're after?

I've never found a good use for the integrator patch btw ;)

This version of an 'integrator' is adding value twice (?!) which is a bug of mine (sorry). When I place this 'integrator' in its own comp (sampleHold2.qtz) it works as it should. In SampleHold1 I have all the stages you need but it needs a debug on the double add problem — otherwise the methodology is good.

If I was doing it I would have used a Javascript patch with a timer input but I tried to do it with stock patches. I'm guessing you don't like/know JS or you would have done it that way in first place.

sampleHold2.qtz13.59 KB
SampleHold1.qtz37.9 KB

ginsu777's picture
Re: Running Total with Sample and Hold?

thank you, i will have to look into it as the problem mushrooms into other problems. i dont know js so i am just trying to get things to work, then i pretty them up later. :)