# Compensate for phase shift of Hilbert transform

I'm using Octave and trying to use the "instfreq" function from the time frequency toolbox which requires an analytic signal input. To get this analytic signal I'm using the Octave function "hilbert" on my real valued signal thus:

analytic_sig = hilbert( my_real_valued_signal ) ;
[ instf, t ] = instfreq( analytic_signal ) ;


where instf is the instantaneous frequency I'm trying to obtain. However, the results are not quite what I expected. I suspect that the 90 degree phase shift induced by the hilbert transform is where the problem lies, so my question is how can I alter the output of the Octave "hilbert" function to compensate/adjust for this phase shift?

Edit in response to comments

With a simple test case I'm creating a signal x with instantaneous frequency ifl

octave:1> [x ifl] = fmlin(10,0.05,0.35)
x =

-0.97815 - 0.20791i
-0.80902 - 0.58779i
-0.30902 - 0.95106i
0.50000 - 0.86603i
1.00000 + 0.00000i
0.30902 + 0.95106i
-0.91355 + 0.40674i
-0.30902 - 0.95106i
1.00000 - 0.00000i
-0.50000 + 0.86603i

ifl =

0.050000
0.083333
0.116667
0.150000
0.183333
0.216667
0.250000
0.283333
0.316667
0.350000


but in my envisioned real life application I will only have data for the real component

octave:2> real_sig = real(x)
real_sig =

-0.97815
-0.80902
-0.30902
0.50000
1.00000
0.30902
-0.91355
-0.30902
1.00000
-0.50000


using the hilbert function I create an analytic signal from my available real data

octave:3> anal_sig = hilbert( real_sig )
anal_sig =

-0.97815 + 0.07265i
-0.80902 - 0.41187i
-0.30902 - 0.92331i
0.50000 - 0.81514i
1.00000 + 0.04490i
0.30902 + 0.98765i
-0.91355 + 0.52573i
-0.30902 - 0.89042i
1.00000 + 0.28002i
-0.50000 + 1.12978i


and when this is put in to the instfreq function I get the measured instantaneous frequency instf

octave:4> instf = instfreq( anal_sig )
instf =

0.10520
0.13131
0.15427
0.18209
0.20487
0.24755
0.31328
0.30974


The instfreq function returns values in the range [2:end-1] of its input, so padding to make an easy comparison

octave:5> [ ifl [ 0 ; instf ; 0 ] ]
ans =

0.05000   0.00000
0.08333   0.10520
0.11667   0.13131
0.15000   0.15427
0.18333   0.18209
0.21667   0.20487
0.25000   0.24755
0.28333   0.31328
0.31667   0.30974
0.35000   0.00000


it can be seen that the measured frequency is different from the true, known frequency. Thinking of a phasor diagram, I was thinking that perhaps some trigonometric manipulation of the real and imaginary components of the hilbert function output might correct this.

• The 90 degree phase shift shows up in the imaginary component only, and it's inherent in the Hilbert transform. It wouldn't seem there could be anything to adjust. What results are you getting that you didn't expect? May 26 '14 at 1:44
• If you added some more information about your signal, maybe some plots, it would be easier to judge where the problem lies. As already mentioned by MackTuesday, it can't be the 90 degree phase shift of the Hilbert transform, because that's what you need to get an analytic signal. May 26 '14 at 7:18

## 2 Answers

1) A Hilbert transform has a very very long impulse response (above some given noise floor), so you need a ton more data to manufacture an analytic signal, otherwise you won't have enough to span the width of the Hilbert impulse response filter without serious edge truncation effects.

2) Instantaneous frequency estimates from this type of artificially approximated analytic signal can be very noisy, so often has to be low pass filtered to significantly below half your sample rate.

Your result is not wrong or strange at all. Note that the function 'hilbert' can only approximate a Hilbert transform. Furthermore, the function 'instfreq.m' can only estimate the instantaneous frequency. After all, the relative error between your and the original estimates is really not big at all (obviously apart from the first and last value).