Rectangular window $\psi$ wave-function and the calculus of $\langle p^2\rangle$ for it I'm currently considering a rectangular window $\psi$ function:
$$
\psi(x) = \begin{cases}\left(2a\right)^{-1/2}&\text{for } |x|<a \\ 0&\text{otherwise.} \end{cases}
$$
I am interested in the momentum uncertainty of this function. I expect it to be a function of a, the 'width' of $\psi$ in the x-space. 
I claim that $\langle{p}\rangle = 0$ because this is a stationary state and so $m\frac{d\langle x\rangle}{dt} = 0 $. This spares me a trial to take the derivative of a step function, which I'm about to have to do though for $\langle{p^2}\rangle$. 
For $\langle{p^2}\rangle$ I should calculate: 
$$
{-\hbar^2\int_{-a}^a\psi^*\frac{d^2}{dx^2}\psi}  \,dx .
$$
This requires taking the second derivative of a square window function, which I imagine will lead to infinite values. So instead, I will work in the momentum space after calculating the Fourier transform of $\psi$ for which I got the sinc function: 
$$
\phi(p) = \sqrt{\frac{\hbar}{a\pi}}\frac{\sin(\frac{a\pi p}{\hbar})}{p}. 
$$
And then I tried to calculate $\langle p^2 \rangle$
$$
\langle p^2\rangle = \frac{\hbar}{a\pi}\int_{-\infty}^{\infty}\frac{\sin^2(\frac{a\pi p}{\hbar})}{p^2}p^2dp = \frac{\hbar}{a\pi}\int_{-\infty}^{\infty}{\sin^2(\frac{a\pi p}{\hbar})} dp \rightarrow \infty
$$
Am I mistaken? This would say that the uncertainty in momentum,
 $\sqrt{\langle p^2\rangle-\langle p\rangle^2}$ , is infinite independently of the width $a$ of the $x$-localization. 
 A: You can also look at this problem from a practical point of view. If you even take a smoothed (allowed) version of a rectangular window $\psi$ function, you will end up with very steep "edges" of your function. And now from mathematical point of view you will have very big values of derivative around $-a$ and $a$ (which means big values of momentum in QM), and consequently a huge $\langle p^2 \rangle$, while $\langle p \rangle$ will remain zero due to the opposite signs of derivative values.
In your Fourie transform, this smoothed wave function means integration over large but finite region, which will lead you again to a huge uncertainty. 
A: Just for your self verification, you could though do the calculus in the $x$ representation,
$$
{(1) \ \langle p^2 \rangle = -\hbar^2\int_{-a}^a\psi^*\frac{d^2}{dx^2}\psi}  \,dx .
$$
where I understand that you assume units in which $2m = 1$.
Now, the derivative of the step ascending function is which goes up at $x=-a$ is $\delta(x + a)$ and since the descending step function that goes down at $x=a$ can be written as 1 - the step function, its derivative is $-\delta(x - a)$. Therefore
$$ (2) \frac {d W(x;a)}{dx} = \frac {\delta(x+a) - \delta(x-a)}{\sqrt {2a}} .$$
Now, let's use (2) in (1).
$$ \ \langle p^2 \rangle = - \frac {\hbar^2}{2a} \int_{-a}^a \frac {d}{dx} \left[ \delta(x+a) - \delta(x-a) \right] dx .$$
$$ \ \ \ \ \ \ = - \frac {\hbar^2}{2a} \left[ \delta(x+a) - \delta(x-a) \right] \Bigg|_{-a}^{a} = \frac {\hbar^2}{a} \cdot \infty \ \ \ . $$
It is exactly the same as what you get with your calculus in the $p$ space, if you correct the mistake in $\phi (p)$, where should appear $\hbar $, not $\sqrt {\hbar}$ .
