------edit-------
So I coded the Hilbert transformation in $C$ but unfortunately I do not get a phase shift of $90^\circ$ but somewhat different from that and with a wrong amplitude. My code looks like this:
void hilbertfun(float *vin, float *vout, int n, int d)
{
static complex *A; //working array
int i;
float pi = 4. * atan(1.);
int signfun;
static float *rkx;
void rk(float *ak, int n, float d, int ind);
A = (complex*) alloc1(n,sizeof(complex));
rkx = (float*) alloc1(n,sizeof(float));
//copy input array to complex array
for(i=0; i<n; i++){
A[i].r = vin[i];
A[i].i = 0.;
}
// perform inverse fft
fouriertransform(1,n,A);
// calculate wavenumbers
wavenumbers(rkx,n,d,1);
// check wether wavenumbers are positive or negative >> apply phase shift by using the impulse response of the Hilbert transformer
// + apply phase shift
for(i=0;i<n;i++){
if (rkx[i] > 0) signfun = 1;
else if (rkx[i] == 0) signfun = 0;
else if (rkx[i] < 0) signfun = -1;
A[i].r = - A[i].i * signfun;
A[i].i = A[i].r * signfun;
}
// perform forward fft
fouriertransform(-1,n,A);
for(i=0;i<n;i++) vout[i]=A[i].r/n; //write into output and normalise
}
The Fourier transform and the normalisation work perfectly fine without the phase shift (Original (lower), Output (upper)):
Yet, with the phase shift I get this result (Original (lower), Hilbert transformed Output (upper)):
What am I missing?