I want to implement a Hilbert transform, but i'd like to avoid having to deal with a kernel to convolute with, mainly because I wouldn't know how many taps I'd need and whether I should make a odd or even kernel, and also because this way it seems to give such an unperfect result. Since Hilbert Transform is basically about shifting the phase by 90=B0, I thought of a few ways to do it, but I'm not sure whether or not it would give just what a Hilbert Transform would give (mostly as for the negative frequencies, which is not such an easy concept to master) To perform an Hilbert Transform on a signal, could I perform a FFT on a signal, and then make the imaginary part equal the real part and the real part equal minus the imaginary part, so it would do as if both parts had rotated by +j? I also read in a book that the analytic signal's real part is equal to the original real input signal. i got a little problem with that, it seems to me that it says that the analytic signal's real part is the input signal's real part, as if we discared the input signal's imaginary part. I probably got it wrong, so if someone could enlight me...

# Ways of implementing a Hilbert Transform

Started by ●January 11, 2006

Reply by ●January 11, 20062006-01-11

Michel Rouzic wrote:> I want to implement a Hilbert transform, but i'd like to avoid having > to deal with a kernel to convolute with, mainly because I wouldn't know > how many taps I'd needPick a number and see it it meets your spec. If too poor, make it bigger. If better than need be, make it smaller. Obviously, the minimum number of taps will provide a delay equal to a quarter period of the lowest frequency; in practice, you need a little more.> and whether I should make a odd or even kernel,Odd has the advantages that the signal at the middle tap has the same delay as the transformer output and the delay is a whole number of sample times. With an even number of taps, you get a (usually trivial) improvement in the high-frequency band edge of Q, but you need half a sample time delay in I.> and also because this way it seems to give such an unperfect result.There is no better result to be had. There are cheaper ones, though.> I thought of a few ways to do it, but I'm not sure whether or not it > would give just what a Hilbert Transform would give (mostly as for the > negative frequencies, which is not such an easy concept to master) > > To perform an Hilbert Transform on a signal, could I perform a FFT on a > signal, and then make the imaginary part equal the real part and the > real part equal minus the imaginary part, so it would do as if both > parts had rotated by +j?For continuous processing, you would need to string the IFFTs together with overlap. A Hilbert transform is done with convolution, just like most FIRs. Any of those can be accomplished with FFT-IFFT. Look up "fast convolution".> I also read in a book that the analytic signal's real part is equal to > the original real input signal. i got a little problem with that, it > seems to me that it says that the analytic signal's real part is the > input signal's real part, as if we discared the input signal's > imaginary part. I probably got it wrong, so if someone could enlight > me...You understand that to make an analytic signal, you perform a Hilbert transformation on it in order to generate the imaginary part. You now have two parts, real* and imaginary, which together are the analytic (complex) signal. If the imaginary part is discarded, you are back to the signal you started with. Jerry ______________________________________ * Of course, the original (real) part must be delayed to match the processing delay of the Hilbert transformation. -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Reply by ●January 11, 20062006-01-11

Michel Rouzic wrote:> I want to implement a Hilbert transform, but i'd like to avoid having > to deal with a kernel to convolute with, mainly because I wouldn't know > how many taps I'd need and whether I should make a odd or even kernel, > and also because this way it seems to give such an unperfect result. > > Since Hilbert Transform is basically about shifting the phase by 90=B0, > I thought of a few ways to do it, but I'm not sure whether or not it > would give just what a Hilbert Transform would give (mostly as for the > negative frequencies, which is not such an easy concept to master) > > To perform an Hilbert Transform on a signal, could I perform a FFT on a > signal, and then make the imaginary part equal the real part and the > real part equal minus the imaginary part, so it would do as if both > parts had rotated by +j? > > I also read in a book that the analytic signal's real part is equal to > the original real input signal. i got a little problem with that, it > seems to me that it says that the analytic signal's real part is the > input signal's real part, as if we discared the input signal's > imaginary part. I probably got it wrong, so if someone could enlight > me...What I do is take a real FFT of the taps, then zero the negative frequencies. That gives me a template to multiply the FFT of the input block by before performing inverse FFT and OLA. John

Reply by ●January 11, 20062006-01-11

On 10 Jan 2006 21:23:19 -0800, "Michel Rouzic" <Michel0528@yahoo.fr> wrote:>I want to implement a Hilbert transform, but i'd like to avoid having >to deal with a kernel to convolute with, mainly because I wouldn't know >how many taps I'd need and whether I should make a odd or even kernel, >and also because this way it seems to give such an unperfect result. > >Since Hilbert Transform is basically about shifting the phase by 90=B0, >I thought of a few ways to do it, but I'm not sure whether or not it >would give just what a Hilbert Transform would give (mostly as for the >negative frequencies, which is not such an easy concept to master) > >To perform an Hilbert Transform on a signal, could I perform a FFT on a >signal, and then make the imaginary part equal the real part and the >real part equal minus the imaginary part, so it would do as if both >parts had rotated by +j?Hi, off the top of my head, I don't think this will work. Sorry but I don't have the time to model this idea, but I'll bet you can find the answer pretty quick if you model this yourself with some software (MATLAB, MathCAD, Scilab, etc.).>I also read in a book that the analytic signal's real part is equal to >the original real input signal. i got a little problem with that, it >seems to me that it says that the analytic signal's real part is the >input signal's real part, as if we discared the input signal's >imaginary part. I probably got it wrong, so if someone could enlight >me...It sounds to me like you have a real signal, and you want to compute an analytic signal. (That's typically what the Hilbert transform is used for.) One way to generate an analytic signal is to perform the FFT of your original real signal. Next, zero-out all of the FFT results negative frequency components. (This will give you a spectrum having only positive-frequency components.) Then perform the inverse FFT of that new spectrum. The result of the inverse FFT will be your desired analytic signal, and the real part of the analytic signal will be the original a real signal samples that you started with. Good Luck, [-Rick-]

Reply by ●January 14, 20062006-01-14

Rick Lyons wrote:> On 10 Jan 2006 21:23:19 -0800, "Michel Rouzic" <Michel0528@yahoo.fr> > wrote: > > >I want to implement a Hilbert transform, but i'd like to avoid having > >to deal with a kernel to convolute with, mainly because I wouldn't know > >how many taps I'd need and whether I should make a odd or even kernel, > >and also because this way it seems to give such an unperfect result. > > > >Since Hilbert Transform is basically about shifting the phase by 90=B0, > >I thought of a few ways to do it, but I'm not sure whether or not it > >would give just what a Hilbert Transform would give (mostly as for the > >negative frequencies, which is not such an easy concept to master) > > > >To perform an Hilbert Transform on a signal, could I perform a FFT on a > >signal, and then make the imaginary part equal the real part and the > >real part equal minus the imaginary part, so it would do as if both > >parts had rotated by +j? > > Hi, > > off the top of my head, I don't think this will > work. Sorry but I don't have the time to > model this idea, but I'll bet you can find the > answer pretty quick if you model this yourself > with some software (MATLAB, MathCAD, Scilab, etc.).Main reason for that is that I have no idea of what it would do in the negative frequencies, mostly that so far I just thought that negative frequencies were somehow the mirror of positive frequencies.> >I also read in a book that the analytic signal's real part is equal to > >the original real input signal. i got a little problem with that, it > >seems to me that it says that the analytic signal's real part is the > >input signal's real part, as if we discared the input signal's > >imaginary part. I probably got it wrong, so if someone could enlight > >me... > > It sounds to me like you have a real signal, and you > want to compute an analytic signal. (That's typically > what the Hilbert transform is used for.) > > One way to generate an analytic signal is to perform the FFT of your > original real signal. Next, zero-out all of the FFT results negative > frequency components. (This will give you a spectrum having only > positive-frequency components.) Then perform the inverse FFT of that > new spectrum. The result of the inverse FFT will be your desired > analytic signal, and the real part of the analytic signal will be the > original a real signal samples that you started with. > > Good Luck, > [-Rick-]wow, wait, does Matlab/Scilab gives you both negative and positive frequencies, or is there something I didn't understand about telling a positive frequency from a negative one? Because I use FFTW 3 in my C program to perform my FFT's, and well all I see as a result is positive frequencies. I would surely have thought about zeroing negative frequencies to get an analytic signal if it displayed negative frequencies. That whole negative frequency thing is quite confusing, mostly that I didn't see anywhere how negative frequencies look compared to positive frequencies in the time domain. But i'll quit complaining, i'd just like to know how I can get negative frequencies from the FFT returned by FFTW 3 and zero them. Thanks.

Reply by ●January 14, 20062006-01-14

john wrote:> Michel Rouzic wrote: > > I want to implement a Hilbert transform, but i'd like to avoid having > > to deal with a kernel to convolute with, mainly because I wouldn't know > > how many taps I'd need and whether I should make a odd or even kernel, > > and also because this way it seems to give such an unperfect result. > > > > Since Hilbert Transform is basically about shifting the phase by 90=B0, > > I thought of a few ways to do it, but I'm not sure whether or not it > > would give just what a Hilbert Transform would give (mostly as for the > > negative frequencies, which is not such an easy concept to master) > > > > To perform an Hilbert Transform on a signal, could I perform a FFT on a > > signal, and then make the imaginary part equal the real part and the > > real part equal minus the imaginary part, so it would do as if both > > parts had rotated by +j? > > > > I also read in a book that the analytic signal's real part is equal to > > the original real input signal. i got a little problem with that, it > > seems to me that it says that the analytic signal's real part is the > > input signal's real part, as if we discared the input signal's > > imaginary part. I probably got it wrong, so if someone could enlight > > me... > > What I do is take a real FFT of the taps, then zero the negative > frequencies. That gives me a template to multiply the FFT of the input > block by before performing inverse FFT and OLA. > > JohnDamn, I'm just discovering that you can get negative frequencies out of a FFT. How do you get the negative frequencies of a FFT that appearently only displays positive frequencies? (I use FFTW 3 in my C program and it only displays positive frequencies)

Reply by ●January 14, 20062006-01-14

Jerry Avins wrote:> Michel Rouzic wrote: > > I want to implement a Hilbert transform, but i'd like to avoid having > > to deal with a kernel to convolute with, mainly because I wouldn't know > > how many taps I'd need > > Pick a number and see it it meets your spec. If too poor, make it > bigger. If better than need be, make it smaller. Obviously, the minimum > number of taps will provide a delay equal to a quarter period of the > lowest frequency; in practice, you need a little more. > > > and whether I should make a odd or even kernel, > > Odd has the advantages that the signal at the middle tap has the same > delay as the transformer output and the delay is a whole number of > sample times. With an even number of taps, you get a (usually trivial) > improvement in the high-frequency band edge of Q, but you need half a > sample time delay in I. > > > and also because this way it seems to give such an unperfect result. > > There is no better result to be had. There are cheaper ones, though. > > > I thought of a few ways to do it, but I'm not sure whether or not it > > would give just what a Hilbert Transform would give (mostly as for the > > negative frequencies, which is not such an easy concept to master) > > > > To perform an Hilbert Transform on a signal, could I perform a FFT on a > > signal, and then make the imaginary part equal the real part and the > > real part equal minus the imaginary part, so it would do as if both > > parts had rotated by +j? > > For continuous processing, you would need to string the IFFTs together > with overlap. A Hilbert transform is done with convolution, just like > most FIRs. Any of those can be accomplished with FFT-IFFT. Look up "fast > convolution".Um, I guess that by conitnuous processing you mean real-time. well no i don't need that, i'm dealing with a sound file. Anyways, I already implemented FFT Convolution (just not with overlap-add, I used to, but for some mysterious reason it was broke).> > I also read in a book that the analytic signal's real part is equal to > > the original real input signal. i got a little problem with that, it > > seems to me that it says that the analytic signal's real part is the > > input signal's real part, as if we discared the input signal's > > imaginary part. I probably got it wrong, so if someone could enlight > > me... > > You understand that to make an analytic signal, you perform a Hilbert > transformation on it in order to generate the imaginary part. You now > have two parts, real* and imaginary, which together are the analytic > (complex) signal. If the imaginary part is discarded, you are back to > the signal you started with.Well that's what confuses me. If you can get to the signal you started with by discarding its imaginary part, then it means the the signal you started with held all in the real part? In other words, you only perform the hilbert transform for the I part of the signal? cuz the signal I have to deal with has both real and imaginary parts. If you perform the hilbert transform on the I part of the signal, what do you do with the Q part of the original signal?

Reply by ●January 14, 20062006-01-14

Rick Lyons wrote: ...> One way to generate an analytic signal is to perform the FFT of your > original real signal. Next, zero-out all of the FFT results negative > frequency components. (This will give you a spectrum having only > positive-frequency components.) Then perform the inverse FFT of that > new spectrum. The result of the inverse FFT will be your desired > analytic signal, and the real part of the analytic signal will be the > original a real signal samples that you started with.Rick, I tried out this procedure. It turned out that, in addition to what you describe, I had to scale the DC and the Nyquist term of the spectrum (both real only due to Hermitian symmetry) by a factor of 1/2 to get the desired result. I've never used the Hilbert transform before. I understand that it can be used to determine "instantaneous" amplitude (magnitude of the Hilbert transform pair) and frequency (rate of change of the phase of the Hilbert transfrom pair) of a time signal. Zeno would have a feast with that :-) ! In what type of processing are we interested in that information? Regards, Andor

Reply by ●January 14, 20062006-01-14

Andor wrote:> Rick Lyons wrote: > > ... > > One way to generate an analytic signal is to perform the FFT of your > > original real signal. Next, zero-out all of the FFT results negative > > frequency components. (This will give you a spectrum having only > > positive-frequency components.) Then perform the inverse FFT of that > > new spectrum. The result of the inverse FFT will be your desired > > analytic signal, and the real part of the analytic signal will be the > > original a real signal samples that you started with. > > Rick, I tried out this procedure. It turned out that, in addition to > what you describe, I had to scale the DC and the Nyquist term of the > spectrum (both real only due to Hermitian symmetry) by a factor of 1/2 > to get the desired result. > > I've never used the Hilbert transform before. I understand that it can > be used to determine "instantaneous" amplitude (magnitude of the > Hilbert transform pair) and frequency (rate of change of the phase of > the Hilbert transfrom pair) of a time signal. Zeno would have a feast > with that :-) ! > > In what type of processing are we interested in that information?I'm trying to do a frequency shifting. I could do that by just moving the content of the FFT of the signal i'm trying to shit, but only the shift is not flat, it varies over time (because I'm trying to turn a frequency sweep to flat)

Reply by ●January 14, 20062006-01-14

Michel Rouzic wrote:> Jerry Avins wrote:...>>For continuous processing, you would need to string the IFFTs together >>with overlap. A Hilbert transform is done with convolution, just like >>most FIRs. Any of those can be accomplished with FFT-IFFT. Look up "fast >>convolution". > > > Um, I guess that by conitnuous processing you mean real-time. well no i > don't need that, i'm dealing with a sound file. Anyways, I already > implemented FFT Convolution (just not with overlap-add, I used to, but > for some mysterious reason it was broke).No, I don't. I mean processing a long input in shorter pieces. If your FFT is large enough to handle the whole file at once, fine. Otherwise you have to process the file in pieces and string the pieces together. Every filter, including FFT-modify-IFFT and analog, mangles the ends of its inputs. When you process the file in pieces, there are lots of mangled ends in the middle. Ouch! Overlap methods allow the ending garbage of one chunk to be corrected by the beginning garbage of the next, giving proper output (except for the actual ends).>>>I also read in a book that the analytic signal's real part is equal to >>>the original real input signal. i got a little problem with that, it >>>seems to me that it says that the analytic signal's real part is the >>>input signal's real part, as if we discared the input signal's >>>imaginary part. I probably got it wrong, so if someone could enlight >>>me... >> >>You understand that to make an analytic signal, you perform a Hilbert >>transformation on it in order to generate the imaginary part. You now >>have two parts, real* and imaginary, which together are the analytic >>(complex) signal. If the imaginary part is discarded, you are back to >>the signal you started with. > > > Well that's what confuses me. If you can get to the signal you started > with by discarding its imaginary part, then it means the the signal you > started with held all in the real part?You started with only the real part, then constructed the imaginary part from it. Why does it confuse you that you can do it a second time?> In other words, you only perform the hilbert transform for the I part > of the signal? cuz the signal I have to deal with has both real and > imaginary parts. If you perform the hilbert transform on the I part of > the signal, what do you do with the Q part of the original signal?If the signal is already analytic, you don't need to make it so. Non-analytic complex signals rarely arise at baseband. Did I miss an explanation of what you're up to? -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������