What is the algorithm to do a Discrete Hilbert Transform?
The Discrete Hilbert Transform is an "ideal" (implying that this is not the practical implementation) linear time-invariant filter with input $x[n]$ having output

$$ \mathscr{H}\Big\{ x[n] \Big\} \triangleq \hat{x}[n] = \sum\limits_{i=-\infty}^{\infty} h[i] \, x[n-i] $$

Where the impulse response of a discrete-time Hilbert transformer is:

$$ h[n] = \begin{cases}
 \frac{\big(1 - (-1)^n\big)}{\pi n} \quad &amp; n \ne 0 \\
\\
0 &amp; n = 0
\end{cases}$$

Because $1 - (-1)^n = 0$ for even $n$, this can be restated as

$$ h[n] = \begin{cases}
 \frac{2}{\pi n} \quad &amp; n \text{ odd} \\
\\
0 &amp;  n \text{ even}
\end{cases}$$

This is not a causal impulse response, nor is it finite in length.  To make it finite in length, you would need to window it with a decent window:

$$ h[n] = \begin{cases}
 \frac{2}{\pi n} w[n] \quad &amp; n \text{ odd} \\
\\
0 &amp;  n \text{ even}
\end{cases}$$

where $w[n]$ is some window function of width $L+1$ samples (and $L$ is an even positive integer).  If it were a Hamming Window, it would be:

$$ w[n] = \begin{cases}
  0.54 \ + \ 0.46 \cdot \cos\left(\pi \frac{n}{L/2} \right) \qquad &amp; |n| \le L/2 \\
  0 &amp; |n| &gt; L/2 \\
\end{cases}$$

If it were a Kaiser window it would be

$$ w[n] = \begin{cases}
  \frac{1}{I_0(\beta)} \, I_0\left(\beta \sqrt{1 -  \left(\frac{n}{L/2}\right)^2 } \right) \qquad &amp; |n| \le L/2 \\
  0 &amp; |n| &gt; L/2 \\
\end{cases}$$

where

$$ I_0(u) \triangleq \sum\limits_{k=0}^{\infty} \frac{(-1)^k \big( \tfrac{u}{2} \big)^{2k}}{(k!)^2} $$

$I_0(x)$ is the 0th-order modified Bessel function of the 1st kind. $L+1$ is the number of non-zero samples or FIR taps (the FIR filter order is $L$) and, in my centered and symmetrical case, must be even. $\beta$ is a "shape parameter", maybe around 5 or 6, i dunno.

Now, to make this causal, your impulse response has to be delayed by $\frac{L}2$ samples to be $h[n-\frac{L}2]$, but then should also all other signals that this Hilbert output is compared to, they should also be delayed by $\frac{L}2$ samples to keep the phase relationship correct.

With a windowed finite-length impulse response (which is what we call an "FIR"), the Hilbert transform output is 

$$ \hat{x}[n] = \sum\limits_{i=-L/2}^{L/2} h[i] \, x[n-i] $$

and delaying the output so that the filter is causal you get

$$ \hat{x}[n-\tfrac{L}2] = \sum\limits_{i=0}^{L} h[i-\tfrac{L}2] \, x[n-i] $$

but with this delayed output $\hat{x}[n-\tfrac{L}2]$, you must compare that only to the like delayed input $x[n-\tfrac{L}2]$ in order for the two signals to have their 90° phase relationship (which is fundamentally what the Hilbert Transform is about).  Note that every even-indexed sample of $h[n]$ is zero, so the number of taps is not really $L+1$ but is $\frac{L}2 - 1$ taps with non-zero coefficients.