Ok
You need to time how many pulses come from the port.
Each start of pulse can be measured (timestamp) and stored in an array
This array can be limited to say 100 elements, and if its full you start replacing elements.
from this array you could calculate how many pulses have been sent in n miutes or seconds.
You should have a parallel while loop for the inspection of the array and in the existing program
ony use the first two elements of the sequence in a total while.
PS
If you know how fast pulses come you may add a while of say 1ms inside your while to preserve computing power..
play a little and ask further questions.
greetings from the Netherlands