# Counting samples on a pulse wave signal

Given an non-zero integer $n$, I've got a rectangular pulse wave $f_n(t)$ defined by:

• period $T = \frac{1}{\sqrt{2}}$
• pulse time $\tau = n - \frac{\lfloor n*\sqrt{2} \rfloor}{\sqrt{2}}$
• Amplitude=1 (so $f(t)=1$ for $t \in [0, \tau]$ an $f(t)=0$ for $t \in ]\tau, T[$)

That implies $f_n$ is symmetric with respect to $x=\frac{n}{2}$ axis and $f_n(0) = f_n(n)=1$. To better visualize, I plotted the shape of the signals for different vales of n (going from 2 to 11)

I'm trying to find a formula to count the number of times $m_1$ for which $f_n(i)=1$ and $m_2$ for which $f_n(i)=0$ for $i \in \mathbb{N} \cap [0, \frac{n}{2}]$.

This could be formulated as:

$m1 = \sum\limits_{i=1}^{ \lfloor n/2 \rfloor } f_n(i)$

Once we get $m_1$, it is easy to get $m_2$ using $m_1+m_2=\lceil \frac{n+1}{2} \rceil$

I manually computed the result $(m_1, m_2)$ for some values of $n$:

\begin{array}{|c|c|} \hline n & (m_1, m_2) \\ \hline 2 & (2, 0) \\ \hline 3 & (1, 1) \\ \hline 4 & (2, 1) \\ \hline 5 & (1, 2) \\ \hline 6 & (3, 1) \\ \hline 7 & (4, 0) \\ \hline 8 & (2, 3) \\ \hline 9 & (4, 1) \\ \hline 10 & (2, 4) \\ \hline 11 & (4, 2) \\ \hline 12 & (7, 0) \\ \hline 13 & (3, 4) \\ \hline 14 & (6, 2) \\ \hline 15 & (2, 6) \\ \hline 16 & (6, 3) \\ \hline 17 & (1, 8)\\ \hline \end{array}

I'm confident there is a well defined pattern. When I plot different couples $(m_1, m_2)$ on an image, I obtain some beautiful pattern (green for $n$ even, red for $n$ odd).

Using the definition on the wikipedia Pulse_wave page:

$f(t) = \frac{\tau}{T} + \sum_{k=1}^{\infty} \frac{2}{k\pi} \sin\left(\frac{\pi k\tau}{T}\right) \cos\left(\frac{2\pi k}{T} t\right)$

An approximation of $m_1$ can be given by $\lceil \lceil \frac{n+1}{2} \rceil * \frac{\tau}{T} \rceil$ but tested on small $n$ values (from 2 to 2000), it only gives a correct result for 70% of the $n$ values. I tried to simplify the second term using Euler's formula but I don't seems to go anywhere.