I am trying to get the phase of a signal with Hilbert transform. However, I found that the unwrapped phase was not correct because the Hilbert transforming using the hilbert function in MATLAB is not correct. The simulation code shown as below:

realphase=30*cos(5*t); %signal phase
x=cos(realphase); %signal

img=imag(H); %Hilbert transform using hilbert function
ph=unwrap(atan2(img,real)); %unwrapped phase using hilbert function in MATLAB
ht=sin(realphase); %Hilbert transform of cos is sin
pt=unwrap(atan2(ht,real)); %unwrapped phase

hold on
ylabel('Hilbert transform')

hold on

The Hilbert transform of $\cos$ should be $\sin$, but with the hilbert function in MATLAB, it is not a $\sin$, why? Could anyone please help me?

  • 1
    $\begingroup$ Note that your signal x is a cosine of a cosine. $\endgroup$
    – MBaz
    Commented Aug 11, 2016 at 13:42
  • $\begingroup$ @MBaz I believe this is intentional - the analysis is of a non-stationary sinusoid. $\endgroup$
    – Speedy
    Commented Aug 11, 2016 at 14:47
  • $\begingroup$ @Speedy I thought so, but the OP is expecting the Hilbert transform to be a sine, which only makes sense if the signal x is a (regular) cosine, right? $\endgroup$
    – MBaz
    Commented Aug 11, 2016 at 18:20
  • 1
    $\begingroup$ side note: don't call your variable real. You will confuse yourself when trying to call built-in real. $\endgroup$
    – Memming
    Commented Oct 10, 2016 at 17:46

2 Answers 2


I don't think the Hilbert function in Matlab is incorrect - you can establish this by carrying out the same process for a stationary sinusoid (observe the discontinuities at the start/end). Further, the unwrapped phase of the Hilbert transform you've performed does have a sinusoidal characteristic, although with a significant offset.

I think it's more likely you're looking at an interaction of your rapidly changing phase with the windowing implicit to a filter implementation of the Hilbert Transform. Perhaps you could try slowing down the rate in change of phase to see whether you can isolate changes in phase from the window length? You could do this by expanding your time vector (using an increment smaller than 0.001).


As carefully buried deep in the help of hilbert function ...

"hilbert returns a complex helical sequence, sometimes called the analytic signal, from a real data sequence. The analytic signal x = xr + jxi has a real part, xr, which is the original data, and an imaginary part, xi, which contains the Hilbert transform."

So the "Hilbert transform", xi, is the imaginary part of the returned value from hibert function, or Hilbert transform = imag(hilbert(xr));


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.