# Pulses per minute

## Recommended Posts

I am trying to find the average number of pulses per minute. I have a digital in channel called pulse, and another channel called counter set to Test, A to D. Here is what I have in the event:

if (pulse[0] && !pulse[1])

endif

I get an error saying Channel or function not found Line 2.

##### Share on other sites

You are missing an open parenthesis, so your parens don't match and its throwing off the whole line. It should be:

##### Share on other sites

I fixed that, but I'm still not getting the right answer. No matter how fast I simulate the stroke, I get the same answer. What I'm trying to get is the average number of strokes per minute, so if I click it once per second my channel would read 60 or twice per second it would read 120. What i'm getting now is 1249. Any ideas? Thanks.

##### Share on other sites

What does Pulse read? Maybe post a screenshot of the channel table for Pulse.

##### Share on other sites

I have the Pulse Channel set as a Digital In, Timing = 0.05. When I simulate the stroke, I read 1, otherwise it reads 0. Thanks for your help.

##### Share on other sites

Well, my expression isn't going to work then, since the deltaT value is basically going to be 0.1 every time! You need to create a second channel, call it pulseHigh or something. Then in the Event for pulse, put:

```if (pulse[0] &amp;&amp; !pulse[1])
endif```

Then in the event for pulseHigh put:

`counter.addvalue(insertTime(60/(pulseHigh.time[0] - pulseHigh.time[1])), systime(), 1))`

The first code makes the pulseHigh channel just have values when a pulse occurs. Thus, you can take the time interval between two pulseHigh values and calculate out a rate.

If you want an average rather than instantaneous, you could try:

`counter.addvalue(insertTime(sum(pulseHigh[systime(), systime() - 59.99]),systime(), 1))`

That will cause a new reading in counter that will contain the sum of pulses received over the last minute every time a new pulse arrives.

##### Share on other sites

BTW: two important points:

1) if the length of your pulse is shorter than 0.1 seconds, you will likely miss some pulses, so make sure its always > your sample rate of your digital input. Adjust your sample rate accordingly, or better yet, use a real counter (which requires different techniques)

2) the precision of the instantaneous calculation is determined by your sampling interval. The faster the sampling rate, the higher the precision. This error is significantly smaller in the averaged (sum()) version.