# Why the Hilbert transform is not correct using the hilbert function in MATLAB?

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:

t=0:0.001:3;
realphase=30*cos(5*t); %signal phase
x=cos(realphase); %signal
H=hilbert(x);

img=imag(H); %Hilbert transform using hilbert function
real=real(H);
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

subplot(2,1,1)
plot(img)
hold on
plot(ht)
ylabel('Hilbert transform')
legend('imag(H)','sin(realphase)')

subplot(2,1,2)
plot(realphase)
hold on
plot(ph)
plot(pt)
ylabel('phase')
legend('realphase','ph','pt')


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?

• Note that your signal x is a cosine of a cosine. – MBaz Aug 11 '16 at 13:42
• @MBaz I believe this is intentional - the analysis is of a non-stationary sinusoid. – Speedy Aug 11 '16 at 14:47
• @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? – MBaz Aug 11 '16 at 18:20
• side note: don't call your variable real. You will confuse yourself when trying to call built-in real. – Memming Oct 10 '16 at 17:46

## 1 Answer

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).