Frequency computation

62 Views Asked by At

I generate pulses using microcontroller with following method:

  1. Set $A=0$
  2. With frequency $F$ execute the following code:

    2.1. Add $S$ to $A$

    2.2. If $A\ge N$ then produce a pulse and substract $N$ from $A$

Here $A, S, N\in \mathbb N$, and $S\le N$.

It's easy to see that period between the pulses may be not constant, but let's call the frequency $f$ of the pulses the limit of number of pulses per time $T$ divided to $T$ when $T\to \infty$.

How to compute $f$? I can compute it for concrete numeric examples, but I need general symbolic solution.

1

There are 1 best solutions below

4
On BEST ANSWER

As mentioned in the comments, at $T\to\infty, f=\frac{FS}{N}$ for $N>S$ and for $N\leq S$ your code will start double pulsing periodically.

However, that's the the limit. If you aren't looking at long term behavior, this is what you'll follow:

Define $r\equiv N\pmod{S}$. (i.e. $r$ is the remainder after dividing $N$ by $S$.) The number generation will be cyclic over $S$ pulses. So every $S$ pulses, you have the same pattern again. However, in this cycle, some of the pulses will be $F$ longer than the rest. Denote $P=\lfloor \frac{N}{S}\rfloor$. You will have $S-r$ pulses of length $\frac{P}{F}$ and $r$ pulses of length $\frac{P+1}{F}$. However, the longer pulses will be evenly spaced out in the cycle.

For example: take $N=30$ and $S=7$. We know $r=2$ and $P=4$.

Here is the cycle:

$$7,14,21,28,35$$ $$12,19,26,33$$ $$10,17,24,31$$ $$8,15,22,29,36$$ $$13,20,27,34$$ $$11,18,25,32$$ $$9,16,23,30$$ $$\vdots$$

You have a cycle of length $7$ where $7-2=5$ of them are of length $P$ and $r=2$ of them of length $P+1$.

However, for fast enough $F$, it will be hard to notice the difference between this "varying" frequency pulse pattern and a pulse sequence of frequency $\frac{FS}{N}$.