DSPRelated.com
Forums

Hilbert transformer for envelope detection

Started by Martin Trummer January 8, 2014
On 1/8/14 6:18 PM, clay@claysturner.com wrote:
> On Wednesday, January 8, 2014 12:27:26 PM UTC-5, robert bristow-johnson wrote: >> On 1/8/14 12:21 PM, Martin Trummer wrote: >> >>> On 2014-01-08 17:12:38 +0000, robert bristow-johnson said: >>> >>>> as i recall, the solution is to design a virtual all-pass filter with >>>> a phase shift of -45 degrees (plus the delay necessary to realize it). >>>> flip the coefs around and you have the +45 degree filter (with the >>>> same delay) and the outputs of those two filters are always 90 degrees>> >>>> apart and at *every* frequency, their gain is the same. ripple or not. >>> >>> Is that the the paper by Clay Turner? >> >> i think Clay wrote something like that. i cannot completely remember. >> >> Clay's pretty smart, so i wouldn't doubt it.
...
> I don't know if I'd call myself smart. Basically the way I came up with the idea of using two 45 deg filters with one being the time reversal of the other was as follows: > > "I was standing on the edge of my toilet hanging a clock, the porcelain was wet, I slipped, hit my head on the sink, and when I came to I had a revelation! A vision! A picture in my head! A picture of this!" > > Clay with a little license from Dr Emmitt Brown.
the one thing about this that i thought of when i was trying to make a very clean frequency-shifter using the analytical signal (to make you sound like an SSB-like duck quacking) and worked out was to create the 45 degree filters from a linear combination of the 90 degree and 0 degree "filter", all with the same delay. so i would use the +/- 45 filters in the heterodyning operation instead of the 0 and 90 filters. but i figured out that the images/error that would result because of ripples in the 90-degree filter that did not exist in the 0-degree filter, that those errors in the bumped up spectrum remained. it didn't solve or mitigate my problem because it was just a re-jiggering of the whole LTI process. like the same IIR filter done using two different canonical forms. but i wonder if it *does* help it when you square the two signals and add them to get the envelope? isn't that what you did, Clay? -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
On Wednesday, January 8, 2014 6:37:46 PM UTC-5, robert bristow-johnson wrote:
> On 1/8/14 6:18 PM, clay@claysturner.com wrote: > > > On Wednesday, January 8, 2014 12:27:26 PM UTC-5, robert bristow-johnson wrote: > > >> On 1/8/14 12:21 PM, Martin Trummer wrote: > > >> > > >>> On 2014-01-08 17:12:38 +0000, robert bristow-johnson said: > > >>> > > >>>> as i recall, the solution is to design a virtual all-pass filter with > > >>>> a phase shift of -45 degrees (plus the delay necessary to realize it). > > >>>> flip the coefs around and you have the +45 degree filter (with the > > >>>> same delay) and the outputs of those two filters are always 90 degrees>> > > >>>> apart and at *every* frequency, their gain is the same. ripple or not. > > >>> > > >>> Is that the the paper by Clay Turner? > > >> > > >> i think Clay wrote something like that. i cannot completely remember. > > >> > > >> Clay's pretty smart, so i wouldn't doubt it. > > ... > > > I don't know if I'd call myself smart. Basically the way I came up with the idea of using two 45 deg filters with one being the time reversal of the other was as follows: > > > > > > "I was standing on the edge of my toilet hanging a clock, the porcelain was wet, I slipped, hit my head on the sink, and when I came to I had a revelation! A vision! A picture in my head! A picture of this!" > > > > > > Clay with a little license from Dr Emmitt Brown. > > > > the one thing about this that i thought of when i was trying to make a > > very clean frequency-shifter using the analytical signal (to make you > > sound like an SSB-like duck quacking) and worked out was to create the > > 45 degree filters from a linear combination of the 90 degree and 0 > > degree "filter", all with the same delay. so i would use the +/- 45 > > filters in the heterodyning operation instead of the 0 and 90 filters. > > but i figured out that the images/error that would result because of > > ripples in the 90-degree filter that did not exist in the 0-degree > > filter, that those errors in the bumped up spectrum remained. it didn't > > solve or mitigate my problem because it was just a re-jiggering of the > > whole LTI process. like the same IIR filter done using two different > > canonical forms. > > > > but i wonder if it *does* help it when you square the two signals and > > add them to get the envelope? isn't that what you did, Clay? > > > > > > -- > > > > r b-j rbj@audioimagination.com > > > > "Imagination is more important than knowledge."
Robert, I was able to design the 0 an 90 degree band pass filters to match since I specified them in the frequency domain as piecewise combinations of low order trigonometric polynomials. A problem (although it often turns out to be quite small) is when you make the linear combination to form the +-45 degree filters. Since the impulse response no longer has a definite parity (symmetric or anti-symmetric impulse response), the resulting filter can't have linear phase. The example given in the paper has angular deviations of fractions of a degree. I used this trick for creating pseudo-analytic signals in a receiver. I used both envelope and angle measurements of the signal. I'm not sure how it would "sound" in your freq. shifter example. Clay
I start out by manually tuning a parallel set of allpass filters using staggered frequencies and then use Matlab lsqnonlin which is in the optimization toolbox. 

Bob
Randy

Yes sounds like that should work. If the desired frequency band was near DC, and you want unity magnitude in both paths, would that result in a very long filter?

Bob
radams2000@gmail.com writes:

> Randy > > Yes sounds like that should work. If the desired frequency band was > near DC, and you want unity magnitude in both paths, would that result > in a very long filter?
Bob, I'm not sure, but from the approximations for FIR filter order, I would think it would be. For example, [mitra], p.428, gives a simple approximation of filter order as N = (-20 * log10(\sqrt{\delta_p\delta_s}) - 13 ) / (14.6 * (\omega_s - \omega_p) / 2 * pi) where \delta_p is passband ripple, \delta_s is stopband attenuation, and \omega_p and \omega_s are the passband and stopband frequencies, respectively. So mainly the (\omega_s - \omega_p) term in the denominator would make N decrease. --Randy @BOOK{mitra, title = "{Digital Signal Processing: A Computer-Based Approach}", author = "Sanjit~K.~Mitra", publisher = "McGraw-Hill", edition = "second", year = "2001"} -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
Randy Yates <yates@digitalsignallabs.com> writes:

> radams2000@gmail.com writes: > >> Randy >> >> Yes sounds like that should work. If the desired frequency band was >> near DC, and you want unity magnitude in both paths, would that result >> in a very long filter? > > Bob, > > I'm not sure, but from the approximations for FIR filter order, I would > think it would be.
Correction: I would think it would NOT be. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
clay@claysturner.com writes:

> Randy, > > This approach is certainly doable as long as you can design the low > pass filter. What if you needed 10,000 taps? The following paper shows > how to do this and the needed constraints to do it cleanly. > > > A. Reilly, G. Frazer, and B. Boashash, &ldquo;Analytic > signal generation&mdash;Tips and traps,&rdquo; IEEE Trans. > Signal Processing, vol. 42, no. 11, Nov. 1994, pp. > 3241&ndash;3245.
Thanks for the reference, Clay. I see from that paper (namely, the way the stop-band edges line up in figure 2) that you really can't increase the transition band like I thought when reducing the passband bandwidth (otherwise you'd get some negative frequency leakage). Bummer. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
radams2000@gmail.com writes:

> Randy > > Yes sounds like that should work. If the desired frequency band was > near DC, and you want unity magnitude in both paths, would that result > in a very long filter?
Bob, see my response to Clay. The optimization of the filter length I thought you would get with a smaller passband bandwidth won't happen. :( Perhaps I'm a little thick, but can you please explain the technique I start out by manually tuning a parallel set of allpass filters using staggered frequencies and then use Matlab lsqnonlin which is in the optimization toolbox. a little more? -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
On Wednesday, January 8, 2014 10:08:52 AM UTC-5, Martin Trummer wrote:
> Hi DSP-experts, > > > > I'm using a FIR hilbert-transformer (designed with Matlab's fdatool, > > 200 coefficients) for a envlope detection. For eg: > > > > % Signal is x, h contains coefficients of hilbert transforemer > > x_analytical = filter(h,1,x); > > x_delay = filter([zeros([1,99]), 1],1,x); > > envelope = sqrt(x_analytical.^2+x_delay.^2); > > > > My problem is that the envelope doesn't fit very well since there is a > > lot ringing on the envelope itself as you can see on the following > > screenshot: > > > > http://s14.directupload.net/images/140108/8cmreir2.png > > > > What's the exact problem for this behavior and how can this be avoided? > > Thank you in advance! > > > > Cheers Martin
Sure. Basically you want to use two parallel allpass chains where the phase difference between their outputs is 90 degrees over some frequency range. You start by choosing 1st-order or 2nd-order sections (if you need to get close to DC then 2nd-order might be better). The phase of each allpass will start from from 0 degrees and go to 360 degrees (for 2nd-order) so if you cascade them with frequencies offset by some factor, you get a net phase curve that decreases continuously with wiggles, over frequency. Generally, you want to construct the 2nd chain with the center freqs of the allpass filters in between the center freqs of the 1st chain. By plotting the unwrapped phase difference you can manually wiggle the center freqs and Q's to get the phase diff as close as possible to 90 degrees over the frequency range of interest. You won't be able to do a very good job manually, but you just want to get close enough the the optimizer won't fall into some local minimum trap. Then you write a function for the optimizer that returns an array of phase errors over the desired frequency range, and give it the freedom to adjust the allpass center freqs and Q's. Then hit return and go get a cup of coffee. When you come back you will hopefully find that the phase has equiripple errors around 90 degrees. It's not very hard to get phase error numbers that are very small (hundredths of a degree). It's also nice that you benefit from all the usual benefits of allpass-based filters (coefficient sensitivity, etc).
radams2000@gmail.com writes:

> On Wednesday, January 8, 2014 10:08:52 AM UTC-5, Martin Trummer wrote: >> Hi DSP-experts, >> >> >> >> I'm using a FIR hilbert-transformer (designed with Matlab's fdatool, >> >> 200 coefficients) for a envlope detection. For eg: >> >> >> >> % Signal is x, h contains coefficients of hilbert transforemer >> >> x_analytical = filter(h,1,x); >> >> x_delay = filter([zeros([1,99]), 1],1,x); >> >> envelope = sqrt(x_analytical.^2+x_delay.^2); >> >> >> >> My problem is that the envelope doesn't fit very well since there is a >> >> lot ringing on the envelope itself as you can see on the following >> >> screenshot: >> >> >> >> http://s14.directupload.net/images/140108/8cmreir2.png >> >> >> >> What's the exact problem for this behavior and how can this be avoided? >> >> Thank you in advance! >> >> >> >> Cheers Martin > > Sure. Basically you want to use two parallel allpass chains where the > phase difference between their outputs is 90 degrees over some > frequency range. You start by choosing 1st-order or 2nd-order sections > (if you need to get close to DC then 2nd-order might be better). The > phase of each allpass will start from from 0 degrees and go to 360 > degrees (for 2nd-order) so if you cascade them with frequencies offset > by some factor, you get a net phase curve that decreases continuously > with wiggles, over frequency. Generally, you want to construct the 2nd > chain with the center freqs of the allpass filters in between the > center freqs of the 1st chain. By plotting the unwrapped phase > difference you can manually wiggle the center freqs and Q's to get the > phase diff as close as possible to 90 degrees over the frequency range > of interest. You won't be able to do a very good job manually, but you > just want to get close enough the the optimizer won't fall into some > local minimum trap. > Then you write a function for the optimizer that returns an array of > phase errors over the desired frequency range, and give it the freedom > to adjust the allpass center freqs and Q's. Then hit return and go get > a cup of coffee. When you come back you will hopefully find that the > phase has equiripple errors around 90 degrees. It's not very hard to > get phase error numbers that are very small (hundredths of a degree). > It's also nice that you benefit from all the usual benefits of > allpass-based filters (coefficient sensitivity, etc).
Bob, thanks for this. I'm not sure I follow it completely, but I think there's enough here to guide me if I decide to try it. Thanks for adding another item to my Hibert transform bag-of-tricks! -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com