# 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