Given this difference equation $y(k)$ ... $$y(k) = \frac{1}{K^2} \sum_{m = k-K+1}^k \; \sum_{n = m-K+1}^m x(n) - \frac{1}{L^2} \sum_{m = k-L+1}^k \; \sum_{n = m-L+1}^m x(n)$$
... how does one derive this frequency response $H(f)$? $$H(f) = \frac{1}{K^2} \left( \frac{\sin{\pi f K}}{\sin{\pi f}} \right)^2 e^{-2j\pi f(K-1)} - \frac{1}{L^2} \left( \frac{\sin{\pi f L}}{\sin{\pi f}} \right)^2 e^{-2j\pi f(L-1)}$$
My (attempt at) derivation, using only the first lowpass filter of $y(k)$: $$\sum_{m = k-K+1}^k \; \sum_{n = m-K+1}^m x(n) = \\ \left[x(k-2K+2) + x(k-2K+3) + \dots + x(k-K+1) \right] +\\ \left[x(k-2K+3) + x(k-2K+4) + \dots + x(k-K+2) \right] +\\ \cdots +\\ \left[x(k-K+1) + x(k-K+2) + \dots + x(k) \right] =\\ \left[ x(k-2K+2) + 2x(k-2K+3) + \cdots + (K-1)x(k-K+1) + \cdots + 2x(k-1) + x(k) \right]$$
Applying $Z$-transform, we get $$X(z) \left[ z^{-2K+2} + 2z^{-2K+3} + \cdots + (K-1)z^{-K+1} + \cdots + 2z^{-1} + 1 \right]$$
Now, if the above is correct, then the question boils down to how can this $$\left[ z^{-2K+2} + 2z^{-2K+3} + \cdots + (K-1)z^{-K+1} + \cdots + 1 \right]$$ when evaluated on the unit circle $z=e^{j2\pi f}$, be equal to this? $$\left( \frac{\sin{\pi f K}}{\sin{\pi f}} \right)^2 e^{-2j\pi f(K-1)}$$
Note that $$\left[ z^{-2K+2} + 2z^{-2K+3} + \cdots + (K-1)z^{-K+1} + \cdots + 1 \right]$$ is
$$\left[ z^{-K+1} + z^{-K+2} + \cdots + z^{-1} + 1 \right]^2$$
which is
$$\left[ \frac{(z^{-K}-1)}{(z^{-1}-1)}\right]^2$$
$$=\left[ \frac{(z^{-K/2}-z^{K/2})/z^{K/2}}{(z^{-1/2}-z^{1/2})/z^{1/2}}\right]^2$$
$$=\left[ \frac{(z^{-K/2}-z^{K/2})}{(z^{-1/2}-z^{1/2})}\right]^2 z^{-(K-1)}$$
which for $z=e^{j2\pi f}$ is
$$\left( \frac{\sin{\pi f K}}{\sin{\pi f}} \right)^2 e^{-2j\pi f(K-1)}$$