Let $f \in L^2(\mathbb R)$ then it is well-known that 
$$ \widetilde{f}(x):=\sum\_{n \in \mathbb Z} \frac{1}{\varepsilon}\int\_{[n\varepsilon,(n+1)\varepsilon]} f(s) \ ds 1\_{[n\varepsilon,(n+1)\varepsilon)}(x)$$


converges in the $L^2$ sense to $f.$


But even more is true, as we can write 


$$(\widetilde{f}-f)(x):=\sum\_{n \in \mathbb Z} \frac{1}{\varepsilon}\int\_{[n\varepsilon,(n+1)\varepsilon]} f(s)-f(x) \ ds 1\_{[n\varepsilon,(n+1)\varepsilon)}(x).$$


Then, it follows that if $f$ is absolutely continuous that
$$(\widetilde{f}-f)(x):=\sum\_{n \in \mathbb Z} \frac{1}{\varepsilon}\int\_{[n\varepsilon,(n+1)\varepsilon]} \int\_x^s f'(\tau) d \tau \ ds 1\_{[n\varepsilon,(n+1)\varepsilon)}(x).$$


Hence, it is tempting to ask whether there are conditions on $f$ being in some Sobolev space such that


$$\left\lVert \widetilde{f}-f \right\rVert\_{L^2}=\mathcal O(\varepsilon).$$


Moreover, perhaps this generalizes to higher dimensions, i.e. $\mathbb R^d$ rather than $\mathbb R.$


It seems that what would be sufficient is that $$\sum\_{n \in \mathbb Z} \frac{1}{\varepsilon} \sup\_{s \in [n \varepsilon, (n+1)\varepsilon)}\left\lvert f'(s)\right\rvert 1\_{[n\varepsilon,(n+1)\varepsilon)}(x)$$ is square-integrable. However, I fail to see whether there is some natural Sobolev space in which functions have this property.



Convergence rate for $L^2$ convergence
$\newcommand{\al}{\alpha}
\newcommand{\de}{\delta}
\newcommand{\De}{\Delta}
\newcommand{\ep}{\varepsilon}
\newcommand{\ga}{\gamma}
\newcommand{\Ga}{\Gamma}
\newcommand{\la}{\lambda}
\newcommand{\Si}{\Sigma}
\newcommand{\thh}{\theta}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\F}{\mathcal{F}}
\newcommand{\E}{\operatorname{\mathsf E}} 
\newcommand{\PP}{\operatorname{\mathsf P}}
\newcommand{\ii}[1]{\operatorname{\mathsf I}\{#1\}} 
\newcommand{\tf}{\widetilde{f}}$ 


As you noted,
\begin{equation\*}
 \tf-f=\frac{1}{\ep}\sum\_n a\_n 1\_{[n\ep,(n+1)\ep)},
\end{equation\*}
where 
\begin{equation\*}
 a\_n(x):=\int\_{n\ep}^{(n+1)\ep} \int\_x^s f'(\tau) d \tau \ ds. 
\end{equation\*}
For $x\in[n\ep,(n+1)\ep)$, 
\begin{equation\*}
 |a\_n(x)|\le\int\_{n\ep}^{(n+1)\ep}\int\_{n\ep}^{(n+1)\ep} |f'(\tau)| d \tau\ ds
 =\int\_{n\ep}^{(n+1)\ep} |f'(\tau)| d \tau\ \ep\le b\_n\ep\sqrt\ep,
\end{equation\*}
where 
\begin{equation\*}
 b\_n:=\sqrt{\int\_{n\ep}^{(n+1)\ep} |f'(\tau)|^2 d \tau}. 
\end{equation\*}
So, 
\begin{equation\*}
|\tf-f|\le\sum\_n b\_n \sqrt\ep \, 1\_{[n\ep,(n+1)\ep)}
\end{equation\*}
and 
\begin{equation\*}
 \|\tf-f\|\_2\le\sqrt{\sum\_n b\_n^2 \ep^2}=\ep\|f'\|\_2\le\ep\|f\|\_{W^{1,2}}, 
\end{equation\*}
as desired. 




---


Consider now the general case when $f$ is a function on $\R^d$ with $d\ge2$ and 
\begin{equation\*}
 \tf=\frac{1}{\ep^d}\sum\_{n\in\Z^d} 1\_{\de\_n}\int\_{\de\_n} ds\,f(s),
\end{equation\*}
where $\de\_n:=\prod\_1^d\,(n\_i\ep,(n\_i+1)\ep)$ for $n=(n\_1,\dots,n\_d)$. 
Take any real 
\begin{equation\*}
 p>d
\end{equation\*}
and let $q:=\frac p{p-1}$, so that $\frac1p+\frac1q=1$. 
We have  

\begin{equation\*}
 \tf-f=\frac{1}{\ep^d}\sum\_n a\_n 1\_{\de\_n}, \tag{!}
\end{equation\*}
where 
\begin{equation\*}
 a\_n(x):=\int\_{\de\_n} ds \int\_0^1 dt\, f'(x+t(s-x))\cdot(s-x) 
\end{equation\*}
$f':=\nabla f$ and $\cdot$ is the dot product. 
By the change of variables from $s$ to $\tau=x+t(s-x)$, for $x\in\de\_n$ we have 
\begin{equation\*}
 a\_n(x)=\int\_0^1 dt\int\_{\de\_n} \frac{d\tau}{t^d} \, f'(\tau)\cdot\frac{\tau-x}t\,1\_{(t\_\*,\infty)}(t),
\end{equation\*}
where 
\begin{align\*}
t\_\*:=t\_\*(n,x,\tau)&:=\max\_1^d\Big(\frac{\tau\_i-x\_i}{x\_i-n\_i\ep}\vee\frac{x\_i-\tau\_i}{(n\_i+1)\ep-x\_i}\Big) \\ 
&\ge\max\_1^d\frac{|\tau\_i-x\_i|}{\ep}\gg\frac{|\tau-x|}{\ep},
\end{align\*}
with the constants in $\gg$ and $\ll$ depending only on $d$ and $p$, and  

$|\ \, |$ also denoting the Euclidean norm on $\R^d$. Note that 
\begin{equation\*}
 \int\_{t\_\*}^\infty\frac{dt}{t^{d+1}}\ll\frac1{t\_\*^d}\ll\frac{\ep^d}{|\tau-x|^d}. 
\end{equation\*}
It follows that for $x\in\de\_n$ 
\begin{equation\*}
 |a\_n(x)|\ll\ep^d\,\int\_{\de\_n} \frac{d\tau}{|\tau-x|^{d-1}} \, |f'(\tau)|
 \le\ep^d\,b\_n c^{1/q}, \tag{!!}
\end{equation\*}
by H\"older's inequality, where 
\begin{equation\*}
 b\_n:=\Big(\int\_{\de\_n}d\tau\,|f'(\tau)|^p\Big)^{1/p}, 
\end{equation\*}
\begin{equation\*}
 c:=\int\_{|\tau-x|\le\ep\sqrt d}\frac{d\tau}{|\tau-x|^{(d-1)q}}
 \ll\int\_0^{\ep\sqrt d}\frac{dr}{r^{(d-1)q}}\,r^{d-1}
 \ll\ep^{(p-d)/(p-1)}. 
\end{equation\*}
Thus, by (!) and (!!), 
\begin{equation\*}
 \|\tf-f\|\_p\ll\Big(\sum\_n b\_n^p \ep^{p-d}\ep^d\Big)^{1/p}=\ep\|f'\|\_p\le\ep\|f\|\_{W^{1,p}}, 
\end{equation\*}
as desired. 


