Discussion:
[music-dsp] Envelope Detection and Hilbert Transform
Bob M
2004-09-22 02:42:11 UTC
Permalink
I've been a lurker for quite some time now and have learned a lot from
everybody's questions and answers. Now it's time to jump in..

I'm trying to implement an envelope detector for the first time. I've
done some reading on the web and in a few books, and my understanding
is that a process using the Hilbert transform works well. However, I'm
unable to find a clear description of how to implement it for
real-time operation. This is the process as I understand it:

1. Find the Hilbert transform of x. This gives a pi/2 phase shift.
2. Find the magnitude using a sum of squares: (x^2 + hilbert(x)^2)^0.5
3. Low-pass filter the above result.

First, is this correct?

Is low-pass filtering the result necessary? I did a quick trial in
Excel with a couple of sine waves and a triangular shaped envelope
and, while this is a very simple example, it perfectly finds the
envelope (using only steps 1 and 2 above). There seems to be no need
for low-pass filtering in this case.

How is a hilbert transform implemented? My understanding is that
coefficients can be generated (using Scilab for example), and
implemented as an FIR filter. But how dependent is the outcome on the
number of coefficients used?

Thanks for any help,
Bob
Joshua Scholar
2004-09-22 02:55:34 UTC
Permalink
I have no practical experience with this (though I've played with it)...

You tested with a single frequency in your signal. In that case the Hilbert
transform does a perfect job, no filtering necessary. But from the
standpoint of a hilbert transform a signal is made from a single occilator
that may be changing frequency and amplitude rapidly. Unless that describes
your signal, you're probably in for some surprises.

So while using a hilbert transform lessens the need for a lowpass filter for
envelope detection, it doesn't eliminate it.

Joshua Scholar

----- Original Message -----
From: Bob M
To: music-***@ceait.calarts.edu
Sent: Tuesday, September 21, 2004 7:42 PM
Subject: [music-dsp] Envelope Detection and Hilbert Transform


I've been a lurker for quite some time now and have learned a lot from
everybody's questions and answers. Now it's time to jump in..

I'm trying to implement an envelope detector for the first time. I've
done some reading on the web and in a few books, and my understanding
is that a process using the Hilbert transform works well. However, I'm
unable to find a clear description of how to implement it for
real-time operation. This is the process as I understand it:

1. Find the Hilbert transform of x. This gives a pi/2 phase shift.
2. Find the magnitude using a sum of squares: (x^2 + hilbert(x)^2)^0.5
3. Low-pass filter the above result.

First, is this correct?

Is low-pass filtering the result necessary? I did a quick trial in
Excel with a couple of sine waves and a triangular shaped envelope
and, while this is a very simple example, it perfectly finds the
envelope (using only steps 1 and 2 above). There seems to be no need
for low-pass filtering in this case.

How is a hilbert transform implemented? My understanding is that
coefficients can be generated (using Scilab for example), and
implemented as an FIR filter. But how dependent is the outcome on the
number of coefficients used?

Thanks for any help,
Bob
--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp
links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
James Chandler Jr
2004-09-22 03:24:48 UTC
Permalink
Hi Bob

Have not tried Hilbert transform for envelope detection, but it looks
interesting.

Re: LoPass filtering the output-- You could test an un-filtered Hilbert envelope
on a 1 percent duty-cycle pulse wave. Real music has numerous weird looking
waves and brief transients.

The Hilbert transform MIGHT blur out envelope ripple on high crest factor
waveforms. There are lots of harmonics in a high crest factor wave, so maybe the
Hilbert actually would work minor miracles. Dunno. If you test, please let us
know.

Simple IIR Hilbert code can be found in csound sources you can locate online.
The csound Hilbert transform was adapted from an old analog circuit, published
long ago in the electronic music hardware magazine "ElectroNotes". The design is
a clever series of allpass filters.

The IIR Hilbert isn't perfect, but is pretty good considering its simplicity and
efficiency.

HTH

JCJR
Angelo Farina
2004-09-22 06:34:15 UTC
Permalink
I use the hilbert transform for getting the envelope of wide-band, pulsive
signals, such as room impulse response or the cross-correlation function
between the input and the output of an electroacoustical system.
In both cases it works perfectly without any filtering. It is very good for
finding the "true" peak position of an oscillating signal, which can be
"hidden" by the fact that it occurs in correspondance with a zero-crossing
of the oscillating waveform.
In general, no frequency-domain filtering, nor time-domain integration, is
required after an hilbert transform: it produces a very smooth and nice
envelope. However, in some cases, it would be advisable to add some
exponential time averaging, for example for emulating the behaviour of an
analog RMS meter, such as the RC circuit employed in a sound level meter
with "fast" or "slow" time constants.
The only problem of the Hilbert tansform is that it requires to be computed
in the frequency domain, processing the signal in data blocks, and applying
the FFT. Of consequence, a proper window-overlap is required for
applications in real time, and I have seen that a 75% overlap is required
for getting a perfect enevelope (employing Hanning windows).
With 50% overlap, the envelope is "modulated" by the Hanning Wiindows.....
Bye!

Angelo Farina

> -----Original Message-----
> From: music-dsp-***@ceait.calarts.edu
> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
> Joshua Scholar
> Sent: 22 September 2004 04:56
> To: Bob M; a list for musical digital signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> I have no practical experience with this (though I've played
> with it)...
>
> You tested with a single frequency in your signal. In that
> case the Hilbert transform does a perfect job, no filtering
> necessary. But from the standpoint of a hilbert transform a
> signal is made from a single occilator that may be changing
> frequency and amplitude rapidly. Unless that describes your
> signal, you're probably in for some surprises.
>
> So while using a hilbert transform lessens the need for a
> lowpass filter for envelope detection, it doesn't eliminate it.
>
> Joshua Scholar
>
> ----- Original Message -----
> From: Bob M
> To: music-***@ceait.calarts.edu
> Sent: Tuesday, September 21, 2004 7:42 PM
> Subject: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> I've been a lurker for quite some time now and have learned a lot from
> everybody's questions and answers. Now it's time to jump in..
>
> I'm trying to implement an envelope detector for the first time. I've
> done some reading on the web and in a few books, and my understanding
> is that a process using the Hilbert transform works well. However, I'm
> unable to find a clear description of how to implement it for
> real-time operation. This is the process as I understand it:
>
> 1. Find the Hilbert transform of x. This gives a pi/2 phase shift.
> 2. Find the magnitude using a sum of squares: (x^2 + hilbert(x)^2)^0.5
> 3. Low-pass filter the above result.
>
> First, is this correct?
>
> Is low-pass filtering the result necessary? I did a quick trial in
> Excel with a couple of sine waves and a triangular shaped envelope
> and, while this is a very simple example, it perfectly finds the
> envelope (using only steps 1 and 2 above). There seems to be no need
> for low-pass filtering in this case.
>
> How is a hilbert transform implemented? My understanding is that
> coefficients can be generated (using Scilab for example), and
> implemented as an FIR filter. But how dependent is the outcome on the
> number of coefficients used?
>
> Thanks for any help,
> Bob
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive,
> book reviews, dsp
> links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive,
> book reviews, dsp links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
Joshua Scholar
2004-09-22 21:56:12 UTC
Permalink
All this talk about windows, does that mean you have a way to use FFTs to do
Hilbert Transforms __other__ than convolution?

----- Original Message -----
From: Angelo Farina
To: 'a list for musical digital signal processing'
Sent: Tuesday, September 21, 2004 11:34 PM
Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
...
The only problem of the Hilbert tansform is that it requires to be computed
in the frequency domain, processing the signal in data blocks, and applying
the FFT. Of consequence, a proper window-overlap is required for
applications in real time, and I have seen that a 75% overlap is required
for getting a perfect enevelope (employing Hanning windows).
With 50% overlap, the envelope is "modulated" by the Hanning Wiindows.....
Bye!

Angelo Farina
Erik de Castro Lopo
2004-09-22 22:10:26 UTC
Permalink
On Wed, 22 Sep 2004 14:56:12 -0700
"Joshua Scholar" <***@yahoo.com> wrote:

>
> All this talk about windows, does that mean you have a way to use FFTs to do
> Hilbert Transforms __other__ than convolution?

Yes, take the FFT of a signal, which creates a N frequency domain
samples, with the up half of the being a reflection of the lower
half. Zero out the upper half, do an inverse FFT and viola, you
have the analytic version of the original signal (ie its Hilbert
transform).

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo ***@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
The National Multiple Sclerosis Society of America recently started an
advertising campaign with the slogan "MS: It's not a software company".

Seasoned IT professionals will have no trouble telling the two MS's
apart. One is a debilitating and surprisingly widespread affliction
that renders the sufferer barely able to perform the simplest task.
The other is a disease.
vesa norilo
2004-09-22 22:12:25 UTC
Permalink
Couldn't you just FFT, do the phase shifts and iFFT. Of course this will
trash the signal around the window boundaries but with sufficient window
headroom (would need as much as the longest phase shift will be in
samples?) it might work. I think Angelo's post inidactes phase
manipulation in the freq domain. Please correct me if I'm wrong!

Vesa

Joshua Scholar wrote:

>All this talk about windows, does that mean you have a way to use FFTs to do
>Hilbert Transforms __other__ than convolution?
>
>----- Original Message -----
>From: Angelo Farina
>To: 'a list for musical digital signal processing'
>Sent: Tuesday, September 21, 2004 11:34 PM
>Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
>...
>The only problem of the Hilbert tansform is that it requires to be computed
>in the frequency domain, processing the signal in data blocks, and applying
>the FFT. Of consequence, a proper window-overlap is required for
>applications in real time, and I have seen that a 75% overlap is required
>for getting a perfect enevelope (employing Hanning windows).
>With 50% overlap, the envelope is "modulated" by the Hanning Wiindows.....
>Bye!
>
>Angelo Farina
>
>--
>dupswapdrop -- the music-dsp mailing list and website:
>subscription info, FAQ, source code archive, list archive, book reviews, dsp links
>http://shoko.calarts.edu/musicdsp
>http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
>
Angelo Farina
2004-09-23 06:57:07 UTC
Permalink
????
The (real) FFT of a real signal does not produce any "negative frequency"
spectrum, it only produces N/2+1 positive frequency spectral lines....
Or are You doing a complex FFT on a real signal? This is really stupid, it
takes more than twice the computational power required for a real FFT...
Bye!

Angelo Farina


> -----Original Message-----
> From: music-dsp-***@ceait.calarts.edu
> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
> Erik de Castro Lopo
> Sent: 23 September 2004 00:10
> To: a list for musical digital signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> On Wed, 22 Sep 2004 14:56:12 -0700
> "Joshua Scholar" <***@yahoo.com> wrote:
>
> >
> > All this talk about windows, does that mean you have a way
> to use FFTs
> > to do Hilbert Transforms __other__ than convolution?
>
> Yes, take the FFT of a signal, which creates a N frequency
> domain samples, with the up half of the being a reflection of
> the lower half. Zero out the upper half, do an inverse FFT
> and viola, you have the analytic version of the original
> signal (ie its Hilbert transform).
>
> Erik
> --
> +-----------------------------------------------------------+
> Erik de Castro Lopo ***@mega-nerd.com (Yes it's valid)
> +-----------------------------------------------------------+
> The National Multiple Sclerosis Society of America recently
> started an advertising campaign with the slogan "MS: It's not
> a software company".
>
> Seasoned IT professionals will have no trouble telling the
> two MS's apart. One is a debilitating and surprisingly
> widespread affliction that renders the sufferer barely able
> to perform the simplest task.
> The other is a disease.
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive,
> book reviews, dsp links http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
>
Dave Gamble
2004-09-23 10:34:18 UTC
Permalink
On 23 Sep 2004, at 07:57, Angelo Farina wrote:

> ????
> The (real) FFT of a real signal does not produce any "negative
> frequency"
> spectrum, it only produces N/2+1 positive frequency spectral lines....
Umm... yes it does; it's Hermitian symmetric.

> Or are You doing a complex FFT on a real signal? This is really
> stupid, it
> takes more than twice the computational power required for a real
> FFT...
Perhaps you're referring to "failing to employ an optimisation trick"
rather than the maths itself.

The FFT of a real N-point signal produces N points of complex spectrum,
with Hermitian symmetry
The Hilbert transform is defined as:
1) Take FFT
2) Zeroise the "negative" (or "above nyquist") frequencies; those which
are present purely for symmetry.
3) Take iFFT

Dave.

> Bye!
>
> Angelo Farina
>
>
>> -----Original Message-----
>> From: music-dsp-***@ceait.calarts.edu
>> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
>> Erik de Castro Lopo
>> Sent: 23 September 2004 00:10
>> To: a list for musical digital signal processing
>> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>>
>> On Wed, 22 Sep 2004 14:56:12 -0700
>> "Joshua Scholar" <***@yahoo.com> wrote:
>>
>>>
>>> All this talk about windows, does that mean you have a way
>> to use FFTs
>>> to do Hilbert Transforms __other__ than convolution?
>>
>> Yes, take the FFT of a signal, which creates a N frequency
>> domain samples, with the up half of the being a reflection of
>> the lower half. Zero out the upper half, do an inverse FFT
>> and viola, you have the analytic version of the original
>> signal (ie its Hilbert transform).
>>
>> Erik
>> --
>> +-----------------------------------------------------------+
>> Erik de Castro Lopo ***@mega-nerd.com (Yes it's valid)
>> +-----------------------------------------------------------+
>> The National Multiple Sclerosis Society of America recently
>> started an advertising campaign with the slogan "MS: It's not
>> a software company".
>>
>> Seasoned IT professionals will have no trouble telling the
>> two MS's apart. One is a debilitating and surprisingly
>> widespread affliction that renders the sufferer barely able
>> to perform the simplest task.
>> The other is a disease.
>> --
>> dupswapdrop -- the music-dsp mailing list and website:
>> subscription info, FAQ, source code archive, list archive,
>> book reviews, dsp links http://shoko.calarts.edu/musicdsp
>> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>>
>>
>
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book
> reviews, dsp links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
Angelo Farina
2004-09-23 07:06:36 UTC
Permalink
I do not know how to do an Hilbert transform with convolution.
The only technique which I know is as follows:
1) take a buffer of data x[i] (possibly the entire signal, if You already
recorded it). This is the "real" signal xre[i]
2) make the FFT - the results of the real FFT of a real signal are N/2+1
complex spectral lines, for positive frequencies ranging from zero to fNyq
(=fsampling/2).
3) change the sign of the real part of the spectrum: for any frequency,
Xre[f]=-Xre[f]
4) Swap the real and imaginary parts of each spectral value: for any
frequency, Temp=Xre[f];Xre[f]=Xim[f];Xim[f]=Temp;
5) make the IFFT and get the "imaginary" part of the "analytical function"
6) compute the envelope, sample by sample, making sqrt(xre[i]^2+xim[i]^2)

What other method do You know?

Bye!

Angelo Farina

> -----Original Message-----
> From: Joshua Scholar [mailto:***@yahoo.com]
> Sent: 22 September 2004 23:56
> To: ***@pcfarina.eng.unipr.it; a list for musical digital
> signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> All this talk about windows, does that mean you have a way to
> use FFTs to do Hilbert Transforms __other__ than convolution?
>
> ----- Original Message -----
> From: Angelo Farina
> To: 'a list for musical digital signal processing'
> Sent: Tuesday, September 21, 2004 11:34 PM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform ...
> The only problem of the Hilbert tansform is that it requires
> to be computed in the frequency domain, processing the signal
> in data blocks, and applying the FFT. Of consequence, a
> proper window-overlap is required for applications in real
> time, and I have seen that a 75% overlap is required for
> getting a perfect enevelope (employing Hanning windows).
> With 50% overlap, the envelope is "modulated" by the Hanning
> Wiindows.....
> Bye!
>
> Angelo Farina
>
>
>
Erik de Castro Lopo
2004-09-23 07:24:02 UTC
Permalink
On Thu, 23 Sep 2004 09:06:36 +0200
"Angelo Farina" <***@pcfarina.eng.unipr.it> wrote:

> What other method do You know?

Well the neatest way to take the Hilbert transform of a real
valued signal is to pass it through an FIR filter with
specially designed complex valued coefficients.

I'll point you to the comp.dsp FAQ:

http://www.bdti.com/faq/2.htm#210

The FFT method I posted earlier was the method used in the
matlab signal processing toolbox last time I looked (1994).

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo ***@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"It's far too easy to make fun of Microsoft products, but it takes a
real man to make them work, and a god to make them do anything useful"
-- Anonymous
Joshua Scholar
2004-09-23 07:48:26 UTC
Permalink
Yeah, I should have remembered that...
I do always assume that filtering sound directly in an FFT is usually wrong
and that it's better to use FFTs for convolution, that way there's no edge
effects or other such wierdnesses.


Anyway it's easy to do a Hilbert transform with convolution.

The real part of the signal is the original.

The imaginary part is the result of an all-pass filter whos impulse response
is (1-cos(k pi))/(k pi) when k!= 0
and 0 at k=0.

Which by the way is the same a sinc function for a 50% lowpass changed by
making the first half negative and the second half positive.


Joshua Scholar


----- Original Message -----
From: Angelo Farina
To: 'Joshua Scholar'
Sent: Wednesday, September 22, 2004 11:54 PM
Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform


I do not know how to do an Hilbert transform with convolution. The only
technique which I know is as follows:
1) take a buffer of data x[i] (possibly the entire signal, if You already
recorded it). This is the "real" signal xre[i]
2) make the FFT
3) change the sign of the imaginary part of the spectrum: forr any
frequency, Xim(omega)=-Xim(omega)
4) make the IFFT and get the "imaginary" part of the "anlytical function"
5) compute the envelope, sample by sample, making sqrt(xre[i]^2+xim[i]^2)
What other method do You know?

Bye!

Angelo Farina
> -----Original Message-----
> From: Joshua Scholar [mailto:***@yahoo.com]
> Sent: 22 September 2004 23:56
> To: ***@pcfarina.eng.unipr.it; a list for musical digital
> signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> All this talk about windows, does that mean you have a way to
> use FFTs to do Hilbert Transforms __other__ than convolution?
>
> ----- Original Message -----
> From: Angelo Farina
> To: 'a list for musical digital signal processing'
> Sent: Tuesday, September 21, 2004 11:34 PM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform ...
> The only problem of the Hilbert tansform is that it requires
> to be computed in the frequency domain, processing the signal
> in data blocks, and applying the FFT. Of consequence, a
> proper window-overlap is required for applications in real
> time, and I have seen that a 75% overlap is required for
> getting a perfect enevelope (employing Hanning windows).
> With 50% overlap, the envelope is "modulated" by the Hanning
> Wiindows.....
> Bye!
>
> Angelo Farina
>
>
>
Dave Gamble
2004-09-23 10:40:06 UTC
Permalink
On 23 Sep 2004, at 08:06, Angelo Farina wrote:

> I do not know how to do an Hilbert transform with convolution.
> The only technique which I know is as follows:

> 1) take a buffer of data x[i] (possibly the entire signal, if You
> already
> recorded it). This is the "real" signal xre[i]
> 2) make the FFT - the results of the real FFT of a real signal are
> N/2+1
> complex spectral lines, for positive frequencies ranging from zero to
> fNyq
> (=fsampling/2).
> 3) change the sign of the real part of the spectrum: for any frequency,
> Xre[f]=-Xre[f]
> 4) Swap the real and imaginary parts of each spectral value: for any
> frequency, Temp=Xre[f];Xre[f]=Xim[f];Xim[f]=Temp;
> 5) make the IFFT and get the "imaginary" part of the "analytical
> function"
Does this "Real IFFT" reconstruct the hermitian symmetric component on
your behalf?

Is this the "Real FFT/iFFT" similar to proposed in Numerical Recipes,
where they split the
signal into two, use one as the real component, the other as the
imaginary, then perform
a complex FFT, and use a recombination step?

Dave.

> 6) compute the envelope, sample by sample, making
> sqrt(xre[i]^2+xim[i]^2)
>
> What other method do You know?
>
> Bye!
>
> Angelo Farina
>
>> -----Original Message-----
>> From: Joshua Scholar [mailto:***@yahoo.com]
>> Sent: 22 September 2004 23:56
>> To: ***@pcfarina.eng.unipr.it; a list for musical digital
>> signal processing
>> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>>
>>
>> All this talk about windows, does that mean you have a way to
>> use FFTs to do Hilbert Transforms __other__ than convolution?
>>
>> ----- Original Message -----
>> From: Angelo Farina
>> To: 'a list for musical digital signal processing'
>> Sent: Tuesday, September 21, 2004 11:34 PM
>> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform ...
>> The only problem of the Hilbert tansform is that it requires
>> to be computed in the frequency domain, processing the signal
>> in data blocks, and applying the FFT. Of consequence, a
>> proper window-overlap is required for applications in real
>> time, and I have seen that a 75% overlap is required for
>> getting a perfect enevelope (employing Hanning windows).
>> With 50% overlap, the envelope is "modulated" by the Hanning
>> Wiindows.....
>> Bye!
>>
>> Angelo Farina
>>
>>
>>
>
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book
> reviews, dsp links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
Matt Flax
2004-09-23 11:39:33 UTC
Permalink
Hello,

I would like to point out a method which doesn't use the Hilbert
Transform to find the envelope.

It is based on zero crossing analysis and then peak picking and then
interpolation ... all in the same domain... no FFTs.

Like so :

a] Put the indexes of the positive waveform (the stuff above the
zero line) in an array. i.e. x=[1 1 -1 -2 2 3 5 -1 -3 -6]
indexes=[1 2 3 4 5]
b] find the index array differences. diff (indexes)
Those > 1 delineate the beginning and end of the positive waveform.
You have now segmented your signal.
c] peak pick each positive segment. Find the maximum waveform value of a
segment.
d] Interpolate between segment peaks. Join the dots !

This gives you the upper envelope. To find the lower envelope, start off
by working with the negative envelope and minimum peak pick and then
join the dots.

Matt
--
http://www.flatmax.org

WSOLA TimeScale Audio Mod : http://mffmtimescale.sourceforge.net/
FFTw C++ : http://mffmfftwrapper.sourceforge.net/
Vector Bass : http://mffmvectorbass.sourceforge.net/
Multimedia Time Code : http://mffmtimecode.sourceforge.net/
Angelo Farina
2004-09-23 13:33:23 UTC
Permalink
OK, I will test this method and compare with the ones whih I did employ
previously....
At least, this explanation is quite clear!
Bye!

Angelo

> -----Original Message-----
> From: Joshua Scholar [mailto:***@yahoo.com]
> Sent: 23 September 2004 09:45
> To: ***@pcfarina.eng.unipr.it
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> Yeah, I should have remembered that...
> I do always assume that filtering sound directly in an FFT is
> usually wrong and that it's better to use FFTs for
> convolution, that way there's no edge effects or other such
> wierdnesses.
>
>
> Anyway it's easy to do a Hilbert transform with convolution.
>
> The real part of the signal is the original.
>
> The imaginary part is the result of an all-pass filter whos
> impulse response is (1-cos(k pi))/(k pi) when k!= 0 and 0 at k=0.
>
> Which by the way is the same a sinc function for a 50%
> lowpass changed by making the first half negative and the
> second half positive.
>
>
> Joshua Scholar
>
>
> ----- Original Message -----
> From: Angelo Farina
> To: 'Joshua Scholar'
> Sent: Wednesday, September 22, 2004 11:54 PM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> I do not know how to do an Hilbert transform with
> convolution. The only
> technique which I know is as follows:
> 1) take a buffer of data x[i] (possibly the entire signal, if
> You already
> recorded it). This is the "real" signal xre[i]
> 2) make the FFT
> 3) change the sign of the imaginary part of the spectrum: forr any
> frequency, Xim(omega)=-Xim(omega)
> 4) make the IFFT and get the "imaginary" part of the
> "anlytical function"
> 5) compute the envelope, sample by sample, making
> sqrt(xre[i]^2+xim[i]^2)
> What other method do You know?
>
> Bye!
>
> Angelo Farina
> > -----Original Message-----
> > From: Joshua Scholar [mailto:***@yahoo.com]
> > Sent: 22 September 2004 23:56
> > To: ***@pcfarina.eng.unipr.it; a list for musical digital
> > signal processing
> > Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
> >
> >
> > All this talk about windows, does that mean you have a way to
> > use FFTs to do Hilbert Transforms __other__ than convolution?
> >
> > ----- Original Message -----
> > From: Angelo Farina
> > To: 'a list for musical digital signal processing'
> > Sent: Tuesday, September 21, 2004 11:34 PM
> > Subject: RE: [music-dsp] Envelope Detection and Hilbert
> Transform ...
> > The only problem of the Hilbert tansform is that it requires
> > to be computed in the frequency domain, processing the signal
> > in data blocks, and applying the FFT. Of consequence, a
> > proper window-overlap is required for applications in real
> > time, and I have seen that a 75% overlap is required for
> > getting a perfect enevelope (employing Hanning windows).
> > With 50% overlap, the envelope is "modulated" by the Hanning
> > Wiindows.....
> > Bye!
> >
> > Angelo Farina
> >
> >
> >
>
>
>
Joshua Scholar
2004-09-23 23:10:19 UTC
Permalink
If you don't mind running IIR filters forward AND backward in time then a
simple filter with an approximate 1/x decay running on even samples
seperately from odd samples would do a great job I think. Run one on even
samples forward one on odd samples forward, subtract one on even samples
backward and subtract one on odd samples backward. There's no way (as far
as I know) to get exactly 1/x decay from an IIR though.

----- Original Message -----
From: Angelo Farina
To: 'a list for musical digital signal processing'
Sent: Thursday, September 23, 2004 6:33 AM
Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform


OK, I will test this method and compare with the ones whih I did employ
previously....
At least, this explanation is quite clear!
Bye!

Angelo

> -----Original Message-----
> From: Joshua Scholar [mailto:***@yahoo.com]
> Sent: 23 September 2004 09:45
> To: ***@pcfarina.eng.unipr.it
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> Yeah, I should have remembered that...
> I do always assume that filtering sound directly in an FFT is
> usually wrong and that it's better to use FFTs for
> convolution, that way there's no edge effects or other such
> wierdnesses.
>
>
> Anyway it's easy to do a Hilbert transform with convolution.
>
> The real part of the signal is the original.
>
> The imaginary part is the result of an all-pass filter whos
> impulse response is (1-cos(k pi))/(k pi) when k!= 0 and 0 at k=0.
>
> Which by the way is the same a sinc function for a 50%
> lowpass changed by making the first half negative and the
> second half positive.
>
>
> Joshua Scholar
>
>
> ----- Original Message -----
> From: Angelo Farina
> To: 'Joshua Scholar'
> Sent: Wednesday, September 22, 2004 11:54 PM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> I do not know how to do an Hilbert transform with
> convolution. The only
> technique which I know is as follows:
> 1) take a buffer of data x[i] (possibly the entire signal, if
> You already
> recorded it). This is the "real" signal xre[i]
> 2) make the FFT
> 3) change the sign of the imaginary part of the spectrum: forr any
> frequency, Xim(omega)=-Xim(omega)
> 4) make the IFFT and get the "imaginary" part of the
> "anlytical function"
> 5) compute the envelope, sample by sample, making
> sqrt(xre[i]^2+xim[i]^2)
> What other method do You know?
>
> Bye!
>
> Angelo Farina
> > -----Original Message-----
> > From: Joshua Scholar [mailto:***@yahoo.com]
> > Sent: 22 September 2004 23:56
> > To: ***@pcfarina.eng.unipr.it; a list for musical digital
> > signal processing
> > Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
> >
> >
> > All this talk about windows, does that mean you have a way to
> > use FFTs to do Hilbert Transforms __other__ than convolution?
> >
> > ----- Original Message -----
> > From: Angelo Farina
> > To: 'a list for musical digital signal processing'
> > Sent: Tuesday, September 21, 2004 11:34 PM
> > Subject: RE: [music-dsp] Envelope Detection and Hilbert
> Transform ...
> > The only problem of the Hilbert tansform is that it requires
> > to be computed in the frequency domain, processing the signal
> > in data blocks, and applying the FFT. Of consequence, a
> > proper window-overlap is required for applications in real
> > time, and I have seen that a 75% overlap is required for
> > getting a perfect enevelope (employing Hanning windows).
> > With 50% overlap, the envelope is "modulated" by the Hanning
> > Wiindows.....
> > Bye!
> >
> > Angelo Farina
> >
> >
> >
>
>
>


--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp
links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
Angelo Farina
2004-09-23 13:33:30 UTC
Permalink
Ah, yes, Matlab does not perform real FFT, only complex FFT....

I will have a look at the FIR method, although I do not understand well how
a FIR can have "complex coefficients". Usually a set of FIR coefficients is
just an impulse response, a real signal, which convolved with the real input
signal, creates a real output signal.
If the FIR coefficients are complex, I suppose that also the result of the
convolution will be complex....
Does this method provides directly the "analytical signal" ? If Yes,
computing the real part is useless, because the real part of the analytical
signal is simply the original signal itself...
However, I am writing this before carefully working out the contents of the
refernces which You did provide.
A quick reading of it makes me even more confuse, I do not understand
anything of it!
Bye!

Angelo

> -----Original Message-----
> From: music-dsp-***@ceait.calarts.edu
> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
> Erik de Castro Lopo
> Sent: 23 September 2004 09:24
> To: music-***@shoko.calarts.edu
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> On Thu, 23 Sep 2004 09:06:36 +0200
> "Angelo Farina" <***@pcfarina.eng.unipr.it> wrote:
>
> > What other method do You know?
>
> Well the neatest way to take the Hilbert transform of a real
> valued signal is to pass it through an FIR filter with
> specially designed complex valued coefficients.
>
> I'll point you to the comp.dsp FAQ:
>
> http://www.bdti.com/faq/2.htm#210
>
> The FFT method I posted earlier was the method used in the
> matlab signal processing toolbox last time I looked (1994).
>
> Erik
Angelo Farina
2004-09-23 13:40:16 UTC
Permalink
> -----Original Message-----
> From: Dave Gamble [mailto:***@yahoo.co.uk]
> The FFT of a real N-point signal produces N points of complex
> spectrum, with Hermitian symmetry The Hilbert transform is defined as:
> 1) Take FFT
> 2) Zeroise the "negative" (or "above nyquist") frequencies;
> those which are present purely for symmetry.
> 3) Take iFFT

This definition does not correspond with the real-FFT definition given in
the manual of widely employed numerical packages, such as IMSL , Intel
Performances Primitives or Numerical Recipes. In these packages, two "kinds"
of FFT routines are defined, complex and real.

Your phrase above should be rewritten as:

The COMPLEX FFT of a real N-point signal produces N points of complex
spectrum....

The complex FFT behaves as You described, but the real FFT is what I
described: it only produces the positive-frequencies spectrum, and the
number of spectral lines is N/2+1. So, as I am doing real FFTs on real
signals, I do not see how to implement the "recipe" which you give. It seems
to me that this recipe is only good for complex FFTs.
Of course, I am pretty sure that, working out the math, it is possible to
demonstrate that my "recipe" and Your one will provide exactly the same
result.

Bye!

Angelo Farina
Angelo Farina
2004-09-23 13:53:54 UTC
Permalink
> -----Original Message-----
> From: Dave Gamble [mailto:***@focusrite.com]
> Does this "Real IFFT" reconstruct the hermitian symmetric
> component on your behalf?
>
> Is this the "Real FFT/iFFT" similar to proposed in Numerical
> Recipes, where they split the signal into two, use one as the
> real component, the other as the imaginary, then perform a
> complex FFT, and use a recombination step?

Yes, I usually employ the Numerical Recipes Real-FFt subroutine, which works
great and is much faster than employing the Complex-FFT.
The same employing IPP3.
I do not understand why to employ complex-FFT when managing real signals....
And of course, the real-IFFT of this positive-frequencies-only spectrum
provides back the original real signal!
Bye!

Angelo
Yaakov Stein
2004-09-23 13:01:50 UTC
Permalink
Hi all,

I haven't been following the list on a daily basis,
so excuse my joining this thread at this late stage.

Using the Hilbert transform method is definitely the method
of choice for tracking instantaneous amplitude
(or instantaneous frequency for that matter).

The suggestion to use peak picking is, of course,
only valid for severly oversampled signals,
while the Hilbert method works right down to Nyquist.

The Hilbert can be implemented as an FIR filter
(always use an odd number of coefficients
and note that every other coefficient is zero!),
or as an IIR filter
(based on the Cauchy principle part
of the Hilbert integral 1/pi INTEGRAL f(t)/(t-u) dt )
or via the FFT
(either directly creating the full complex signal,
or creating the imaginary portion).

You can designing the FIR filter using Parks McClellan,
taking into account the usual ripple vs. bandwidth tradeoffs.

Alternatively, complex heterodyning down to zero frequency
followed by a complex low-pass filter also works
(and in fact is equivalent to the Hilbert followed by
a real heterodyne, the latter not changing the amplitude).

Jonathan (Y) Stein
robert bristow-johnson
2004-09-23 20:09:22 UTC
Permalink
on 09/23/2004 06:34, Dave Gamble at ***@yahoo.co.uk wrote:

> The Hilbert transform is defined as:
> 1) Take FFT
> 2) Zeroise the "negative" (or "above nyquist") frequencies; those which
> are present purely for symmetry.
> 3) Take iFFT

this will give you 1/2 of the so-called "analytic signal" which is

1/2 * ( x[n] + j*Hilbert{ x[n] } )

so, to get the Hilbert transform, you need two more small steps:

4) Yank out the imaginary part (or alternatively zeroize, that's american
for "zeroise", the real part :-).
5) Double that (or alternatively multiply by -2*j).

r b-j
Citizen Chunk
2004-09-23 20:56:51 UTC
Permalink
call me Mr. Stupid, but ... why is the Hilbert so accurate at finding
the peak amplitude? why not just rectify? hmmm ... TO THE INTERNET,
BATMAN! ...

anyway, just to play devil's advocate: are you sure that you really
need to use the Hilbert Transform for whatever you're doing? i've been
messing around with envelope detector's for my various dynamics tools,
and i've found that 1-pole IIR's work just fine. unless you're
creating a tool whose main function is to accurately detect the
instantaneous peak value, in which case, i'll shut up now ... ;)
Bengt-Inge Dalenbäck
2004-09-24 11:23:56 UTC
Permalink
Hi,

Chipping in:

At 16:56 2004-09-23 -0400, you wrote:
>call me Mr. Stupid, but ... why is the Hilbert so accurate at finding
>the peak amplitude? why not just rectify? hmmm ... TO THE INTERNET,
>BATMAN! ...
>
>anyway, just to play devil's advocate: are you sure that you really
>need to use the Hilbert Transform for whatever you're doing? i've been
>messing around with envelope detector's for my various dynamics tools,
>and i've found that 1-pole IIR's work just fine. unless you're
>creating a tool whose main function is to accurately detect the
>instantaneous peak value, in which case, i'll shut up now ... ;)

When I worked on this some years ago I first thought that Hilbert was
just one way to detect "an envelope". But I think it is so that an envelope
actually is *defined* as being the magnitude of the analytical signal (that
you can get using Hilbert as discussed), but I don't remember the text-book
reference. Then there can of course be many other ways to estimate
envelope-like useful or good-enough functions for special purposes, but
when talking about *the* envelope I think it must be via the analytical signal.

Best,

--
Bengt-Inge Dalenback / CATT
Kumaran
2004-09-24 08:01:34 UTC
Permalink
Dear All,

I would like to separate between the Small, Large Spaekers and Subwoofers
automatically using the Pink noise. How can I do it... Is there any paper
available on that? Is this the correct place to post it? Or where else
should I post this question...

Sorry for the trouble...

Thanks and Regards,
Kumaran.
Angelo Farina
2004-09-24 09:33:26 UTC
Permalink
> -----Original Message-----
> From: music-dsp-***@ceait.calarts.edu
> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
> Citizen Chunk
> Sent: 23 September 2004 22:57
> To: a list for musical digital signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> call me Mr. Stupid, but ... why is the Hilbert so accurate at
> finding the peak amplitude? why not just rectify? hmmm ... TO
> THE INTERNET, BATMAN! ...

The explanation is simple. Let's take a sinusoidal signal, say at 440 Hz.
Then we apply an amplitude modulation with a triangular shape.
The "maximum" amplitude should occur at the vertex of the triangle.
But if, by chance, this corresponds exactly with a zero-crossing of the sine
wave, You will not get the maximum sample at that exact position! Instead,
you will get two quasi-maximum values in correspondence of the two local
maxima of the sine wave just before and above the theoretical true maximum
point. The Hilbert transform reconstruct correctly the shape of the
trinagular modulation, and provides You an accurate estimate both of the
maximum amplitude of it and of its exact time position.
Bye!

Angelo Farina
James Chandler Jr
2004-09-24 15:39:05 UTC
Permalink
Thanks for the explanation, Angelo

Here is a dummie followup question--

Your explanation well-explains the Hilbert advantage for finding the exact time
of an envelope peak. However, if writing a dynamics plugin, a common aspiration
is to minimize the envelope ripple (for any given release time constant).

Envelope ripple in a dynamics plugin causes intermodulation distortion. One
might adopt a holy grail quest to write a compressor which responds very quickly
to amplitude, but also has very low intermodulation distortion.

Many music tracks do not have well-behaved low-crest-factor signals.

Perhaps a good 'nightmare' envelope test signal, would be a triangle-modulated 1
percent duty-cycle pulse wave.

I understand how a Hilbert envelope detector would help avoid ripple on 'well
behaved' signals. But if the object is to minimize envelope ripple regardless of
wave shape, would a Hilbert envelope detector be smart enough to smooth out
'nightmare signals'? Perhaps one would also require post-Hilbert lowpass
filtering? Dunno.

Admittedly this is a rather vague question, but if you have any thoughts on the
issue, it will be appreciated.

Thanks

JCJR

----- Original Message -----
From: "Angelo Farina" <***@pcfarina.eng.unipr.it>
To: "'Citizen Chunk'" <***@gmail.com>; "'a list for musical digital
signal processing'" <music-***@ceait.calarts.edu>
Sent: Friday, September 24, 2004 5:33 AM
Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform


>
>
>> -----Original Message-----
>> From: music-dsp-***@ceait.calarts.edu
>> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
>> Citizen Chunk
>> Sent: 23 September 2004 22:57
>> To: a list for musical digital signal processing
>> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>>
>> call me Mr. Stupid, but ... why is the Hilbert so accurate at
>> finding the peak amplitude? why not just rectify? hmmm ... TO
>> THE INTERNET, BATMAN! ...
>
> The explanation is simple. Let's take a sinusoidal signal, say at 440 Hz.
> Then we apply an amplitude modulation with a triangular shape.
> The "maximum" amplitude should occur at the vertex of the triangle.
> But if, by chance, this corresponds exactly with a zero-crossing of the sine
> wave, You will not get the maximum sample at that exact position! Instead,
> you will get two quasi-maximum values in correspondence of the two local
> maxima of the sine wave just before and above the theoretical true maximum
> point. The Hilbert transform reconstruct correctly the shape of the
> trinagular modulation, and provides You an accurate estimate both of the
> maximum amplitude of it and of its exact time position.
> Bye!
>
> Angelo Farina
>
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book reviews, dsp
> links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
Citizen Chunk
2004-09-24 23:22:17 UTC
Permalink
hi James. i just did a little reading on the good ole "interweb" and
found this page on the Hilbert Transform:
http://www.numerix-dsp.com/envelope.html

from what I can gather, because of the 90 degree phase shift, the HT
(not hyper threading ;) ) helps to "fill in the gaps" that would be
present in a rectified oscillating signal. this seems a lot like the
RMS value--but RMS is an average level, not the peak level. so the HT
is kind of like an average that just follows the peak value. hope i'm
making sense and properly understanding this thingy.

if you have a sidechain signal that is tracing the rectified peak
signal, it will attack/release as the signal rises/falls, which can
cause envelope ripple. you could get a smoother envelope by using RMS,
but that will slow down reaction time. from what i gather here, if you
use the HT, you get a very smooth peak signal, which can then be
averaged (for something like an RMS) or passed to an attack/release
detector, for typical compressor behavior. so perhaps using the HT can
actually reduce envelope ripple and IM distortion.

or do i have it all wrong? ...

== chunk

On Fri, 24 Sep 2004 11:39:05 -0400, James Chandler Jr
<***@bellsouth.net> wrote:
> ...
> I understand how a Hilbert envelope detector would help avoid ripple on 'well
> behaved' signals. But if the object is to minimize envelope ripple regardless of
> wave shape, would a Hilbert envelope detector be smart enough to smooth out
> 'nightmare signals'? Perhaps one would also require post-Hilbert lowpass
> filtering? Dunno.
Bob M
2004-09-25 00:33:43 UTC
Permalink
First off, thanks to everyone for a phenomenal discussion. There's a
lot for me to sort through!

To share with other some things I have learned here..

First off, I was confused because of the name "Hilbert Transform", or
more specifically that it contains the word "transform." I thought
transforms (such as Fourier, LaPlace, z...) are meant to go from one
domain to another. However, it seems the Hilbert Transform goes from
time domain to time domain. The end result seems to be that it
produces the imaginary component of the real signal.

I can understand the instantaneous magnitude concept from this. The
way I gather it, it's analogous to the magnitude of a frequency bin in
the frequency domain. That is:

(Re^2 + Im^2)^0.5

Conceptually, I think doing the above operation in the time domain
could be thought of as the sum of the magnitudes of all frequencies at
that instant: instantaneous amplitude.

But "instantaneous frequency" is new to me. I can understand it
mathematically. Now that we have the Re,Im components in the time
domain, we can find the phase just as we would in the frequency
domain. Then the derivative of the phase is the instantaneous
frequency. But conceptually, I'm lost. I'd be interested to know what
this figure looks like when there are sine waves of multiple
frequencies present.

I also asked if low-pass filtering the result of the Hilbert Transform
is necessary, and now I'm convinced that it is not. For example, how
could you resolve a triangular envelope accurately if you low-pass
filter that envelope? I think the triangular shape would not be
resolved.

I'm still new to performing FIR filters in the frequency domain
(overlap and add), which was recommended. However, from what I could
see, an extremely flat all-pass frequency response (except near the
DC/Nyquist bins) can be had with a fairly small number of Hilbert
Transform coefficients and a window applied. For example, I checked
the gain plot of a HT using 29 coefficients and a Hanning window, and
it looked extremely flat to me. Is it really necessary to do FFT
filtering, or is that only if you're looking for a flat response all
the way out to DC and Nyquist?

Thanks again,
Bob

On Fri, 24 Sep 2004 19:22:17 -0400, Citizen Chunk
<***@gmail.com> wrote:
> hi James. i just did a little reading on the good ole "interweb" and
> found this page on the Hilbert Transform:
> http://www.numerix-dsp.com/envelope.html
>
> from what I can gather, because of the 90 degree phase shift, the HT
> (not hyper threading ;) ) helps to "fill in the gaps" that would be
> present in a rectified oscillating signal. this seems a lot like the
> RMS value--but RMS is an average level, not the peak level. so the HT
> is kind of like an average that just follows the peak value. hope i'm
> making sense and properly understanding this thingy.
>
> if you have a sidechain signal that is tracing the rectified peak
> signal, it will attack/release as the signal rises/falls, which can
> cause envelope ripple. you could get a smoother envelope by using RMS,
> but that will slow down reaction time. from what i gather here, if you
> use the HT, you get a very smooth peak signal, which can then be
> averaged (for something like an RMS) or passed to an attack/release
> detector, for typical compressor behavior. so perhaps using the HT can
> actually reduce envelope ripple and IM distortion.
>
> or do i have it all wrong? ...
>
> == chunk
Joshua Scholar
2004-09-25 02:13:46 UTC
Permalink
I played a little bit with instantanious frequency to see how well it
cooresponds to actual frequency content of in a polyphonic signal (Ie could
you use it for filtering?). The answer was - very very badly. I don't
remember exactly how bad it was, but it was something like: a mixture of two
lower frequency signals would periodically show an instanious frequecy that
was much higher than either of the componants - the spread was huge.

Since the frequency description is useless unless the signal really only has
one frequency present, I think the only thing that saves the instantanious
magnitude from being useless is that it's constrained to be greater than or
equal to the magnitude of the real signal.

Joshua Scholar

----- Original Message -----
From: Bob M
To: a list for musical digital signal processing
Sent: Friday, September 24, 2004 5:33 PM
Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform


First off, thanks to everyone for a phenomenal discussion. There's a
lot for me to sort through!

To share with other some things I have learned here..

First off, I was confused because of the name "Hilbert Transform", or
more specifically that it contains the word "transform." I thought
transforms (such as Fourier, LaPlace, z...) are meant to go from one
domain to another. However, it seems the Hilbert Transform goes from
time domain to time domain. The end result seems to be that it
produces the imaginary component of the real signal.

I can understand the instantaneous magnitude concept from this. The
way I gather it, it's analogous to the magnitude of a frequency bin in
the frequency domain. That is:

(Re^2 + Im^2)^0.5

Conceptually, I think doing the above operation in the time domain
could be thought of as the sum of the magnitudes of all frequencies at
that instant: instantaneous amplitude.

But "instantaneous frequency" is new to me. I can understand it
mathematically. Now that we have the Re,Im components in the time
domain, we can find the phase just as we would in the frequency
domain. Then the derivative of the phase is the instantaneous
frequency. But conceptually, I'm lost. I'd be interested to know what
this figure looks like when there are sine waves of multiple
frequencies present.

I also asked if low-pass filtering the result of the Hilbert Transform
is necessary, and now I'm convinced that it is not. For example, how
could you resolve a triangular envelope accurately if you low-pass
filter that envelope? I think the triangular shape would not be
resolved.

I'm still new to performing FIR filters in the frequency domain
(overlap and add), which was recommended. However, from what I could
see, an extremely flat all-pass frequency response (except near the
DC/Nyquist bins) can be had with a fairly small number of Hilbert
Transform coefficients and a window applied. For example, I checked
the gain plot of a HT using 29 coefficients and a Hanning window, and
it looked extremely flat to me. Is it really necessary to do FFT
filtering, or is that only if you're looking for a flat response all
the way out to DC and Nyquist?

Thanks again,
Bob
Angelo Farina
2004-09-25 12:46:36 UTC
Permalink
If the signal is very "crackling", of course also its envelope will be very
"rough". And our hearing system cannot "follow" this roughness really
(although we perceive it in terms of frequency-spreading of the formants),
as the internal "integration time" of the human ear is of several
milliseconds (5 to 50, depending on the the type of signal and on its
frequency content).
So, it could be advisable, for having a metrics which closely resembles the
human perception of the amplitude of the signal, to apply some time-domain
averaging to the "pure" envelope. For example, the ITU-P56 standard for
averaging the speech level employs a two-stages time-domain averaging with a
time constant of approximately 30 ms. I generally find this to be quite well
corresponding to what I hear (in the sense that looking at the graph
produced by my ITU-P56 plugin I see the same time history which I hear).
Although a time-domain integration can also be seen as a low-pass filtering,
I think that it is, in general, misleading to refer to it in these terms. We
are talking about time-domain effects, and explaining them in
frequency-domain does not help understanding the psychoacoustic
phenomena....
Bye!

Angelo Farina

> -----Original Message-----
> From: music-dsp-***@ceait.calarts.edu
> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of
> James Chandler Jr
> Sent: 24 September 2004 17:39
> To: a list for musical digital signal processing
> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
>
> Thanks for the explanation, Angelo
>
> Here is a dummie followup question--
>
> Your explanation well-explains the Hilbert advantage for
> finding the exact time of an envelope peak. However, if
> writing a dynamics plugin, a common aspiration is to minimize
> the envelope ripple (for any given release time constant).
>
> Envelope ripple in a dynamics plugin causes intermodulation
> distortion. One might adopt a holy grail quest to write a
> compressor which responds very quickly to amplitude, but also
> has very low intermodulation distortion.
>
> Many music tracks do not have well-behaved low-crest-factor signals.
>
> Perhaps a good 'nightmare' envelope test signal, would be a
> triangle-modulated 1 percent duty-cycle pulse wave.
>
> I understand how a Hilbert envelope detector would help avoid
> ripple on 'well behaved' signals. But if the object is to
> minimize envelope ripple regardless of wave shape, would a
> Hilbert envelope detector be smart enough to smooth out
> 'nightmare signals'? Perhaps one would also require
> post-Hilbert lowpass filtering? Dunno.
>
> Admittedly this is a rather vague question, but if you have
> any thoughts on the issue, it will be appreciated.
>
> Thanks
>
> JCJR
>
> ----- Original Message -----
> From: "Angelo Farina" <***@pcfarina.eng.unipr.it>
> To: "'Citizen Chunk'" <***@gmail.com>; "'a list for
> musical digital signal processing'" <music-***@ceait.calarts.edu>
> Sent: Friday, September 24, 2004 5:33 AM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> >
> >
> >> -----Original Message-----
> >> From: music-dsp-***@ceait.calarts.edu
> >> [mailto:music-dsp-***@ceait.calarts.edu] On Behalf Of Citizen
> >> Chunk
> >> Sent: 23 September 2004 22:57
> >> To: a list for musical digital signal processing
> >> Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
> >>
> >> call me Mr. Stupid, but ... why is the Hilbert so accurate
> at finding
> >> the peak amplitude? why not just rectify? hmmm ... TO THE
> INTERNET,
> >> BATMAN! ...
> >
> > The explanation is simple. Let's take a sinusoidal signal,
> say at 440 Hz.
> > Then we apply an amplitude modulation with a triangular shape.
> > The "maximum" amplitude should occur at the vertex of the triangle.
> > But if, by chance, this corresponds exactly with a zero-crossing of
> > the sine wave, You will not get the maximum sample at that exact
> > position! Instead, you will get two quasi-maximum values in
> > correspondence of the two local maxima of the sine wave just before
> > and above the theoretical true maximum point. The Hilbert transform
> > reconstruct correctly the shape of the trinagular modulation, and
> > provides You an accurate estimate both of the maximum
> amplitude of it and of its exact time position.
> > Bye!
> >
> > Angelo Farina
> >
> >
> > --
> > dupswapdrop -- the music-dsp mailing list and website:
> > subscription info, FAQ, source code archive, list archive, book
> > reviews, dsp links http://shoko.calarts.edu/musicdsp
> > http://ceait.calarts.edu/mailman/listinfo/music-dsp
> >
>
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive,
> book reviews, dsp links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
>
Philip Mcleod
2004-10-07 01:15:05 UTC
Permalink
An idea for halving the filter size.
The all-pass filter has zero coefficients for every 2nd value. This seems
a bit of a waste. I had the thought, that if you upsample the signal by 2,
then do an HT then every second result it is the same as just doing the HT
on the original signal with a filter 1/2 the coefficients (+0.5) by
removing all the zeros. Although the now created complex side of your
original signal has its time values at times half way in between the
original. So if it is not that important that the time samples line up
exactly then this can make your filter smaller.
Is this valid?
I did a few experiments in matlab and it seems to work.
Then if you want to calculate the magnitude you can interpolate to get the
value at time 1/2 way between samples. Except I don't know how much error
this will introduce. But if there is already noise in the signal, maybe
this error is minimal?
Does this allow frequencies all the way up to the nyquist limit now? and
only to 1/2 the nyquist limit previously?

I am very interested in using HT's on real-time audio data (44100Hz
16bit).
What is a reasonable number of coefficients needed?
And do I need to taper them off with a windowing function (eg hamming)
to stop the hard ends?

Comments please?
Thanks
Philip McLeod

On Thu, 23 Sep 2004, Joshua Scholar wrote:

> Yeah, I should have remembered that...
> I do always assume that filtering sound directly in an FFT is usually wrong
> and that it's better to use FFTs for convolution, that way there's no edge
> effects or other such wierdnesses.
>
>
> Anyway it's easy to do a Hilbert transform with convolution.
>
> The real part of the signal is the original.
>
> The imaginary part is the result of an all-pass filter whos impulse response
> is (1-cos(k pi))/(k pi) when k!= 0
> and 0 at k=0.
>
> Which by the way is the same a sinc function for a 50% lowpass changed by
> making the first half negative and the second half positive.
>
>
> Joshua Scholar
>
>
> ----- Original Message -----
> From: Angelo Farina
> To: 'Joshua Scholar'
> Sent: Wednesday, September 22, 2004 11:54 PM
> Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform
>
>
> I do not know how to do an Hilbert transform with convolution. The only
> technique which I know is as follows:
> 1) take a buffer of data x[i] (possibly the entire signal, if You already
> recorded it). This is the "real" signal xre[i]
> 2) make the FFT
> 3) change the sign of the imaginary part of the spectrum: forr any
> frequency, Xim(omega)=-Xim(omega)
> 4) make the IFFT and get the "imaginary" part of the "anlytical function"
> 5) compute the envelope, sample by sample, making sqrt(xre[i]^2+xim[i]^2)
> What other method do You know?
>
> Bye!
>
> Angelo Farina
> > -----Original Message-----
> > From: Joshua Scholar [mailto:***@yahoo.com]
> > Sent: 22 September 2004 23:56
> > To: ***@pcfarina.eng.unipr.it; a list for musical digital
> > signal processing
> > Subject: Re: [music-dsp] Envelope Detection and Hilbert Transform
> >
> >
> > All this talk about windows, does that mean you have a way to
> > use FFTs to do Hilbert Transforms __other__ than convolution?
> >
> > ----- Original Message -----
> > From: Angelo Farina
> > To: 'a list for musical digital signal processing'
> > Sent: Tuesday, September 21, 2004 11:34 PM
> > Subject: RE: [music-dsp] Envelope Detection and Hilbert Transform ...
> > The only problem of the Hilbert tansform is that it requires
> > to be computed in the frequency domain, processing the signal
> > in data blocks, and applying the FFT. Of consequence, a
> > proper window-overlap is required for applications in real
> > time, and I have seen that a 75% overlap is required for
> > getting a perfect enevelope (employing Hanning windows).
> > With 50% overlap, the envelope is "modulated" by the Hanning
> > Wiindows.....
> > Bye!
> >
> > Angelo Farina
> >
> >
> >
>
> --
> dupswapdrop -- the music-dsp mailing list and website:
> subscription info, FAQ, source code archive, list archive, book reviews, dsp links
> http://shoko.calarts.edu/musicdsp
> http://ceait.calarts.edu/mailman/listinfo/music-dsp
>
Loading...