Hilbert Transform/filter
Reply #1 – 2005-02-04 16:01:58
Answer 1: The impulse response of a perfect hilbert transformer is of infinite length. If you want to approximate the transform via a FIR filter you have to limit the impulse response's length. By just chopping some samples off you'll get pass band ripples which is a not so good thing. By applying a smooth weightening of the finite impulse response sample set you can smooth the filter's frequency response curve. The perfect Hilbert transformer's transfer function is given by:H(z) = 2/(1*pi) * (z^1 - z^{-1}) + 2/(3*pi) * (z^3 - z^{-3}) + 2/(5*pi) * (z^5 - z^{-5}) + ... Note: There are positive powers of z. Answer 2: If you approximated a Hilbert transformer with a 35 coefficient FIR filter you have to compensate for the filter's delay of 17 samples. This is because of the positive powers of z in H(z) which actually means you need samples of the original signal in advance to compute the current sample. Answer 3: phase shift != time shift (this only works for infinite sines). BTW: shifting -90 is equivalent to shifting +90 and multiplying the result by -1. Moreover, if you have calculated the 90 degree shifted version you can simply create other phase shifts by a smart weighted addidion of those two. Let x be your original signal and y be the 90 degree shifted signal. Then z = cos(alpha) * x + sin(alpha) * y will be a phase shifted version (alpha degree) of your original signal x. Answer of 2nd question you numbered with 3: Just take a look at the optimal filter's transfer function I gave in form of a polynomial. Generating the coefficients is now a very simple task. First, you have to decide about the length of the filter's response. The only lengths that make sense are of the form 3+4k where k is any non-negative integer. In your case k was 8. For my example I choose k=2. The unweighted ir coefficients are ir = [ -2/(5*pi) 0 -2/(3*pi) 0 -2/(1*pi) 0 2/(1*pi) 0 2/(3*pi) 0 2/(5*pi) ] Now you should smooth the filter's frequency response curve by applying a window. I usually prefer the Blackman window for such tasks. weighted_ir = ir .* blackman(length(ir))' // Matlab style code, ".*" denotes to component-wise multiplication After the filter creation you should check the filter's properties by applying an FFT on a zero-padded version of your impulse response and observation of the FFT bin's magnitudes. edit: since the Blackman function implementation of Matlab (i just checked) returns a vector starting and ending with a zero component the first and last coeff will be zeroed and this practically lowers the filter's order. You may want to compute the window for size n+2 and use just the middle n (non-zero) samples as weights. edit2: This approach is fairly simple. There are more advanced methods like (REMEZ = equi-ripple optimization) which actually lets you optimize the filter so that certain constraints are met but these are usually not that trivial. (btw: Matlab comes with a REMEZ implementation which lets you design all sorts of FIR filters) SebastianG