# Proving a question about the average of a periodic function formula

Let's say I've a function $y\colon [0,\infty]\to\mathbb{R}$ and it is periodic with $T$. If we take a look at the average value of this function over the hole region we can write:

$$\lim_{n\to\infty}\frac{1}{n}\int_0^nf(x)\,dx=\frac{1}{T}\int_0^Tf(x)\,dx$$

But how can prove that that is indeed true?

My work:

When $f(x)$ is periodic with T, the integral on the left hand side is infinite. So we can use lhopitals rule:

$$\lim_{n\to\infty}\frac{1}{n}\int_0^nf(x)\,dx=\lim_{n\to\infty}\frac{\frac{d}{dn}\left(\int_0^nf(x)\,dx\right)}{\frac{d}{dn}\left(n\right)}=\lim_{n\to\infty}\frac{f(n)}{1}=\lim_{n\to\infty}f(n)$$

So, we get:

$$\lim_{n\to\infty}f(n)=\frac{1}{T}\int_0^Tf(x)\,dx$$

But because $f(x)$ is periodic $f(\infty)$ does not have a 'value'. So this leads to noting.

Suppose that $n=kT+n'$, where $0\le n'<T$. Then:
$$\frac{1}{n}\int_0^n f(x)dx = \frac{k\int_0^T f(x)dx + \int_{kT}^{kT+n'}f(x)dx}{n}=\frac{k}{kT+n'}\int_0^T f(x)dx+\frac{1}{n}\int_{kT}^{kT+n'}f(x)dx$$
As $n\to\infty$, we have $k\to \infty$, while $n'$ and $\int_{kT}^{kT+n'}f(x)dx$ remain bounded. Hence, in the limit, the first summand approaches $\frac{1}{T}\int_0^T f(x)dx$, while the second summand approaches $0$.
Let $m_n = \lfloor n/T \rfloor$.
The second term is bounded by $\frac{n-m_n T}{n} \sup_{x \in [0,T]} |f(x)| \le \frac{T}{n} \sup_{x \in [0,T]} |f(x)| \to 0$ as $n \to \infty$. The first term converges to $1$ the desired limit, since $1 - \frac{T}{n} \le \frac{m_n T}{n} \le 1$.