# Hilbert Transform Phase

Started by April 16, 2010
```Hi all,

I am a newbie to Hilbert transform. I found the follow definition from
textbook

H(f) = -j or -90degree, f>0
H(f) =  j or +90degree, f<0
H(f) =  0, f=0

But when I plot the phase out in Matlab, I saw that the phase is not
constant at -90 or +90degree across frequency. The code I have is as
follow

b = firpm(10,[.1 .9],[1 1],'Hilbert')
w = linspace(-pi, pi, 2^12);
h = freqz(b, 1, w);
plot(w, angle(h)*180/pi);

What do I miss?

Cfy30
```
```On 4/16/2010 12:43 AM, cfy30 wrote:
> Hi all,
>
> I am a newbie to Hilbert transform. I found the follow definition from
> textbook
>
> H(f) = -j or -90degree, f>0
> H(f) =  j or +90degree, f<0
> H(f) =  0, f=0
>
> But when I plot the phase out in Matlab, I saw that the phase is not
> constant at -90 or +90degree across frequency. The code I have is as
> follow
>
> b = firpm(10,[.1 .9],[1 1],'Hilbert')
> w = linspace(-pi, pi, 2^12);
> h = freqz(b, 1, w);
> plot(w, angle(h)*180/pi);
>
> What do I miss?

The phase is 90 degrees only over a limited band. All bets are off at
Fs/2, and you can't include enough taps to get 90 degrees of delay at
DC. What's more, there will be some amplitude ripple in the passband.

Jerry
--
"It does me no injury for my neighbor to say there are 20 gods, or no
God. It neither picks my pocket nor breaks my leg."
Thomas Jefferson to the Virginia House of Delegates in 1776.
&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
```
```On Apr 16, 4:43&#4294967295;pm, "cfy30" <cfy30@n_o_s_p_a_m.yahoo.com> wrote:
> Hi all,
>
> I am a newbie to Hilbert transform. I found the follow definition from
> textbook
>
> H(f) = -j or -90degree, f>0
> H(f) = &#4294967295;j or +90degree, f<0
> H(f) = &#4294967295;0, f=0
>
> But when I plot the phase out in Matlab, I saw that the phase is not
> constant at -90 or +90degree across frequency. The code I have is as
> follow
>
> b = firpm(10,[.1 .9],[1 1],'Hilbert')
> w = linspace(-pi, pi, 2^12);
> h = freqz(b, 1, w);
> plot(w, angle(h)*180/pi);
>
> What do I miss?
>
> Cfy30

What wire are you using for your Hilbert Transformer? Beware of Eddie
Current.

Hardy
```
```>Hi all,
>
>I am a newbie to Hilbert transform. I found the follow definition from
>textbook
>
>H(f) = -j or -90degree, f>0
>H(f) =  j or +90degree, f<0
>H(f) =  0, f=0
>
>But when I plot the phase out in Matlab, I saw that the phase is not
>constant at -90 or +90degree across frequency. The code I have is as
>follow
>
>b = firpm(10,[.1 .9],[1 1],'Hilbert')
>w = linspace(-pi, pi, 2^12);
>h = freqz(b, 1, w);
>plot(w, angle(h)*180/pi);
>
>What do I miss?

"Hilbert transform" is not an algorithm. Its a concept. Any algorithm you
might use to realise a Hilbert transform is an approximation. It may work
well over the central part of the band, but don't expect it work work well
near the ends.

Just a few terms for an FIR implementation of a Hilbert transform can give
you pretty close to 90 degrees over a large part of the band. Don't expect
a perfect brick wall transition from + to - 90 at DC, though. Its the
amplitude response that is the greater problem. It takes a lot of terms to
get that close to flat at low and high frequencies.

Steve

```
```..still don't understand. What I am observing is the phase change linearly
with frequency! It is very clear when I plot(w, unwrap(angle(h))*180/pi);

Cfy30

>On 4/16/2010 12:43 AM, cfy30 wrote:
>> Hi all,
>>
>> I am a newbie to Hilbert transform. I found the follow definition from
>> textbook
>>
>> H(f) = -j or -90degree, f>0
>> H(f) =  j or +90degree, f<0
>> H(f) =  0, f=0
>>
>> But when I plot the phase out in Matlab, I saw that the phase is not
>> constant at -90 or +90degree across frequency. The code I have is as
>> follow
>>
>> b = firpm(10,[.1 .9],[1 1],'Hilbert')
>> w = linspace(-pi, pi, 2^12);
>> h = freqz(b, 1, w);
>> plot(w, angle(h)*180/pi);
>>
>> What do I miss?
>
>The phase is 90 degrees only over a limited band. All bets are off at
>Fs/2, and you can't include enough taps to get 90 degrees of delay at
>DC. What's more, there will be some amplitude ripple in the passband.
>
>Jerry
>--
>"It does me no injury for my neighbor to say there are 20 gods, or no
>God. It neither picks my pocket nor breaks my leg."
>          Thomas Jefferson to the Virginia House of Delegates in 1776.
>&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;
>
```
```What is that suppose to mean? Eddie current, not Eddy current?

>On Apr 16, 4:43=A0pm, "cfy30" <cfy30@n_o_s_p_a_m.yahoo.com> wrote:
>> Hi all,
>>
>> I am a newbie to Hilbert transform. I found the follow definition from
>> textbook
>>
>> H(f) =3D -j or -90degree, f>0
>> H(f) =3D =A0j or +90degree, f<0
>> H(f) =3D =A00, f=3D0
>>
>> But when I plot the phase out in Matlab, I saw that the phase is not
>> constant at -90 or +90degree across frequency. The code I have is as
>> follow
>>
>> b =3D firpm(10,[.1 .9],[1 1],'Hilbert')
>> w =3D linspace(-pi, pi, 2^12);
>> h =3D freqz(b, 1, w);
>> plot(w, angle(h)*180/pi);
>>
>> What do I miss?
>>
>> Cfy30
>
>What wire are you using for your Hilbert Transformer? Beware of Eddie
>Current.
>
>
>Hardy
>
```
```On 16 Apr., 06:43, "cfy30" <cfy30@n_o_s_p_a_m.yahoo.com> wrote:
> Hi all,
>
> I am a newbie to Hilbert transform. I found the follow definition from
> textbook
>
> H(f) = -j or -90degree, f>0
> H(f) = &#4294967295;j or +90degree, f<0
> H(f) = &#4294967295;0, f=0
>
> But when I plot the phase out in Matlab, I saw that the phase is not
> constant at -90 or +90degree across frequency. The code I have is as
> follow
>
> b = firpm(10,[.1 .9],[1 1],'Hilbert')
> w = linspace(-pi, pi, 2^12);
> h = freqz(b, 1, w);
> plot(w, angle(h)*180/pi);
>
> What do I miss?

You have to compensate for the delay of the FIR filter from the phase
response. In your case, it is 5 samples, so try

plot(w, angle(h.*exp(5i*w))/pi*180);

Regards,
Andor
```
```Thanks Andor! You are right!

Cfy30

>On 16 Apr., 06:43, "cfy30" <cfy30@n_o_s_p_a_m.yahoo.com> wrote:
>> Hi all,
>>
>> I am a newbie to Hilbert transform. I found the follow definition from
>> textbook
>>
>> H(f) =3D -j or -90degree, f>0
>> H(f) =3D =A0j or +90degree, f<0
>> H(f) =3D =A00, f=3D0
>>
>> But when I plot the phase out in Matlab, I saw that the phase is not
>> constant at -90 or +90degree across frequency. The code I have is as
>> follow
>>
>> b =3D firpm(10,[.1 .9],[1 1],'Hilbert')
>> w =3D linspace(-pi, pi, 2^12);
>> h =3D freqz(b, 1, w);
>> plot(w, angle(h)*180/pi);
>>
>> What do I miss?
>
>You have to compensate for the delay of the FIR filter from the phase
>response. In your case, it is 5 samples, so try
>
>plot(w, angle(h.*exp(5i*w))/pi*180);
>
>Regards,
>Andor
>
```
```On 4/16/2010 1:51 AM, cfy30 wrote:
> ..still don't understand. What I am observing is the phase change linearly
> with frequency! It is very clear when I plot(w, unwrap(angle(h))*180/pi);

What is the lower frequency of your observation? At the sample rate you
use, how many samples represent 90 degrees at .1 Hz?

Jerry
--
"It does me no injury for my neighbor to say there are 20 gods, or no
God. It neither picks my pocket nor breaks my leg."
Thomas Jefferson to the Virginia House of Delegates in 1776.
&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
```
```In article <Xs6dnbGFup7rZ1rWnZ2dnUVZ_t-dnZ2d@giganews.com>,
steveu@n_o_s_p_a_m.coppice.org says...

>
>Just a few terms for an FIR implementation of a Hilbert transform can give
>you pretty close to 90 degrees over a large part of the band. Don't expect
>a perfect brick wall transition from + to - 90 at DC, though. Its the
>amplitude response that is the greater problem. It takes a lot of terms to
>get that close to flat at low and high frequencies.

IIRC, as long as the impulse response of the FIR is stictly antimetric
around the center tap, you will have an exact 90 degree phase shift (+ a
fixed delay) at all frequencies regardless of the number of taps. (A
trivial example is a three-tap filter whose impulse response is -1, 0, +1.)
The problem, as other posters have commented, is that for a given amplitude
passband bandwidth, low-order FIR filters have larger amounts of amplitude
ripple in the filter passband than higher-order filters and no filter with
a finite number of taps can have an ampltude bandwidth extending from DC to
fs/2.

It is possible to transform the filter structure such that the amplitude
response is flat but the phase shift error varies over the passband. What
is not possible with a finite number of taps is to obtain a flat passband
from 0 to fs/2 Hz and a 90 degree phase shift (+ fixed delay)
simultaneously.

```