Solution to iterative equation with floor operation

41 Views Asked by At

This question is motivated by the following signal processing problem.

Suppose there is a source, which produces vectors of data of length $N_s$, and a filter (or other subsystem) that accepts vectors of data of length $N_f$, where $N_s \neq N_f$. We require a buffer between the two blocks to deal with the overflow or collect data until there is enough to pass whole blocks to the filter of its expected size.

What is the minimum value for the required size of the buffer, $N_b$, such that it never overflows?

System diagram

I can write down an iterative equation for the number of samples contained in the buffer at any given time. Let $B^+$ be the number of samples in the buffer after adding $N_s$ samples from the input, and let $B^-$ be the number of samples in the buffer after removing as many multiples of $N_f$ samples as possible and passing them to the filter. Then,

$B^+_{t+1}=B^-_t + N_s$, and

$B^-_{t+1} = B^+_{t+1} - \lfloor\frac{B^+_{t+1}}{N_f}\rfloor N_f $,

where $t$ is the time step index, $B^+_0 = 0$, and $B^-_0 = 0$.

Using the above formulas I was able to confirm empirically my suspicion that the maximum value attained by $B^+$ is $\max_t(B^+_t) \leq N_f + N_s - 1$ for values of $N_s$ and $N_f$ between 1 and 2000, and for 5000000 time steps. However, I would like to know if there is an analytical solution to the above equations, or some other way of framing the problem that makes an analytical solution simple?