I am struggling for some time to solve the following integral:
$$ \int_{-n}^{N-n} \left( \frac{e^{-j\pi(\alpha-1)\tau}}{\tau} - \frac{e^{-j\pi(\alpha+1)\tau}}{\tau} \right) d\tau $$
$N$ is a positive integer, $n$ is an integer, $\alpha$ can be a negative or positive rational number.
I want to express it analytically using exponential integrals $E_1(z)$:
$$ \mathrm{E}_1(z) = \int_z^\infty \frac{e^{-t}}{t}\, dt,\qquad|{\rm Arg}(z)|<\pi $$
I am afraid to split the integral because it is not well defined around $\tau=0$.
I tried lots of stuff, in particular using a limit before the integral and approaching zero with it, and substitute for $E_1(z)$.
I compare my analytical results (using values from $E_1(z)$ in MATLAB) against a numerical evaluation in MATLAB.
It works out for approximately half of my values but the rest is different by absolute values of exactly 1 or 0.5. Sometimes I even get NaN (undefined) values because $\alpha$ will be -1 and 1 at some point and $n$ will be zero at some point. Still, practically this makes no sense and should not happen (it does not happen with the numerical integration too).
In my opinion, the result should be $$ E_1(i\pi(\alpha-1)n) - E_1(-i\pi(\alpha-1)(N-n)) - E_1(-i\pi(\alpha+1)n) + E_1(-i\pi(\alpha+1)(N-n)) $$
In order to match the results with my numerical integration, I split the integration and leave out the problematic zero ($\epsilon\rightarrow 0$):
$$ E_1(i\pi(\alpha-1)n) - E_1(-i\pi(\alpha-1)\epsilon) + E_1(i\pi(\alpha-1)\epsilon) - E_1(-i\pi(\alpha-1)(N-n)) -E_1(-i\pi(\alpha+1)n)+E_1(-i\pi(\alpha+1)\epsilon)-E_1(i\pi(\alpha+1)\epsilon)+E_1(-i\pi(\alpha+1)(N-n)) $$
I would expect $- E_1(-i\pi(\alpha-1)\epsilon) + E_1(i\pi(\alpha-1)\epsilon)$ and $E_1(-i\pi(\alpha+1)\epsilon)-E_1(i\pi(\alpha+1)\epsilon)$ to be zero but depending on $n$, they are $\pm i\pi$ which ultimately result in the wrong result.
So it seems I need to take special care around the singularity ... but what do I need to change?
Here is an approach. Expand the exponential functions in terms of their Taylor series and note that constant terms cancel each other so we have
$$I= \int_{-n}^{N-n} \left( \frac{e^{j\pi\alpha\tau}}{\tau} - \frac{e^{j\pi\beta\tau}}{\tau} \right) d\tau = \sum_{k=1}^{\infty}\frac{(j\pi\alpha)^k-(j\pi\beta)^k}{k!} \int_{-n}^{N-n}\tau^{k-1}=\dots $$
where $\it E_1 $ is the exponential integral. Also you can have a solution in terms of the upper incomplete gamma function