# Inverse DFT of $-i\pi \text{ sgn}(f)$

the following MATLAB code should plot the iFFT of $-i \pi sgn(f)$ which has to be $\frac{1}{t}$ in continuous time. As you can see, the output kinda looks like a 1/x function, but is modulated. How can this phenomena be explained and is there a way to get the desired $\frac{1}{t}$ function?

clc;
clear;
close all;

L=1000;
fStart=-100;
fEnd=100;
df=(fEnd-fStart)/L;
f=linspace(fStart,fEnd-df,L);

X=-1i*pi*sign(f);
x=ifft(fftshift(X));

figure()
ax1=subplot(3,1,1);
ax2=subplot(3,1,2);
ax3=subplot(3,1,3);

stem(ax1,imag(X));
plot(ax2,fftshift(real(x)));
plot(ax3,fftshift(imag(x)));

title(ax1,'spectrum');
title(ax2,'Re(iFFT)');
title(ax3,'Im(iFFT)');


Edit: for clarification: I especially wonder, why every other sample in the result is zero: • to your edit: you will see exactly why so is the case, by explicitly computing the inverse discrete Fourier transform (implemented via inverse FFT) of the DFT spectrum samples $X[k]$ you defined in discrete-time in order to simulate the continuous-time pair. You are eventually performing a discrete-Fourier transform operation. The result is consistent in its own. What's not consistent is the relation to the continuous-time domain, the relation that you constructed to exist must be interpreted carefully. Jul 16 '18 at 13:40

There are two issues here. First of all, you go from continuous time to discrete time, and second, you go from a continuous spectrum to a sampled spectrum. Note that the impulse response of an ideal discrete-time Hilbert transformer with frequency response

$$H(e^{j\omega})=-j\text{ sgn}(\omega),\qquad \omega\in[-\pi,\pi]\tag{1}$$

is given by

$$h[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}H(e^{j\omega})e^{jn\omega}d\omega=\begin{cases}\frac{2}{n\pi},& n\textrm{ odd}\\0,&n\textrm{ even}\end{cases}\tag{2}$$

So the zero samples at even indices don't come as a surprise.

However, with your method you don't get $(2)$ because you sample the spectrum, which results in aliasing in the time domain. You also get a non-zero imaginary part because your discrete spectrum does not satisfy the condition

$$X[k]=X^*[N-k]\tag{3}$$

where $^*$ denotes complex conjugation. Using the following definition for $X[k]$ will give you a purely real-valued time-domain sequence (up to numerical errors):

$$X[k]=\begin{cases}0,&n\in \{0,N/2\}\\ -j,& n=1,\ldots,N/2-1\\ j,&n=N/2+1,\ldots,N-1\end{cases}\tag{4}$$

where I've assumed that $N$ is even.

The inverse discrete Fourier transform (IDFT) of $(4)$ is given by

$$x[n]=\frac{1}{N}\sum_{k=0}^{N-1}X[k]e^{j2\pi kn/N}=\begin{cases}\frac{2}{N}\cot\left(\frac{\pi n}{N}\right),&n\text{ odd}\\0,& n\text{ even}\end{cases}\tag{5}$$

Consequently, it is expression $(5)$ which you should expect instead of a sampled version of $1/\pi t$. Of course, $(5)$ approximates $(2)$, but the approximation gets worse for increasing magnitude of the index $n$ ($n\in [-N/2,N/2-1])$: Using a discrete Fourier transform (that's provided by the MATLAB fft/ifft functions) to simulate a continuous-time Fourier transform pair should be interpreted carefully. This will have inherent implications on the computed result compared to the theoretical expectation. Simply stated you cannot represent a continuous-time Hilbert pair by simulation through a discrete Fourier transform.

The problem stems from the fact that CTFT $-j \text{sign}(f)$ extends from minus infinity to infinity in frequency; it's not bandlimited. Therefore the time function $\frac{1}{\pi t}$ cannot be sampled adequately without aliasing in its spectrum. This results in an erroneous approximation to it. In order to get a better approximaton to your (never exact) simulation, you could increase the observation length $L$ in your code.

By the way, a discrete-time Hilbert transform pair is defined and implemented in a different manner which is not a numerical approximation to the continuous-time case, at all.