Hilbert transform with sine and cosine

38 views (last 30 days)
Hello there,
I have a question: from theory I know that the Hilbert transform of a simple sine is a cosine and viceversa. Now, the question is: why if I compute the Hilbert transform (with the function hilbert.m) of a sine, and I take the imaginary part of that transform, that imaginary part, once plotted, is not a cosine?
I think I miss what the matlab function really does. Someone can help me?
Thanks in advance.

Accepted Answer

Daniel M
Daniel M on 22 Oct 2019
The hilbert transform, as per the documentation, indicates that the imaginary part of the transform is the original (real) sequence with a 90 degree phase shift. Therefore, a cosine becomes a sine (because that is what happens when you shift a cosine wave by pi/2 to the right). A sine wave becomes a negative cosine, because that is what happens when you shift a sine wave by pi/2 to the right.
When it says "Sines are therefore transformed to cosines, and conversely, cosines are transformed to sines." it means that in the sense of odd and even functions (where sines are asymmetric about zero, and cosines are symmetric about zero).
  2 Comments
Lorenzo Bernardini
Lorenzo Bernardini on 22 Oct 2019
Thanks, for the help but I have further questions. First of all, when I write the following:
x=0:0.01:30;
y=@(x) sin(x);
y1=hilbert(sin(x));
plot(x,y(x),x,real(y1),x,-imag(y1))
legend('starting','real part','imaginary part')
grid on
It happens that the transform (-imag(y1)) is likely to diverge at the boundaries, where it behaves very differently from the cosine signal. Moreover in the middle of the time interval chosen the transform doesn't have always max and min respectively +1 and -1. Therefore it is not a proper cosine. Why does it happen?
Finally, if I have a random signal, named u, its Hilbert transform is always -imag(hilbert(u))? Thank you again for your time and attention.
Daniel M
Daniel M on 22 Oct 2019
In your example, you have 4.75 cycles of the wave. Internally hilbert takes an fft of the signal. Fourier transforms behave circularly, that is, it assumes that the end of the signal wraps back around to the beginning of the signal.
Now because your signal ends at 3pi/2 phase, and begins at 0 phase, it is a large discontinuous jump. That is the source of the distortion of the imag(y1) part.
With real-world signals, typically you can't do much about this, and if your signal is long enough, you can truncate the beginning and ends (if that is applicable to your situation).
Otherwise, I have had some success in the past using paddedhilbert on the file exchange:
"Finally, if I have a random signal, named u, its Hilbert transform is always -imag(hilbert(u))? Thank you again for your time and attention."
No, the hilbert transform is the imaginary part (without the negative).

Sign in to comment.

More Answers (1)

Lorenzo Bernardini
Lorenzo Bernardini on 25 Oct 2019
Thank you very much, now it's much more clearer. Sorry for having bothered you.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!