DSPRelated.com
Forums

instantaneous frequency wiht Hilbert transform?

Started by Unknown February 9, 2006
Hi,

Sorry if this is a familiar post, but I haven't found an explicit
answer.  In Matlab, how can I find the instantaneous frequency using
the Hilbert transform?  This is the code I have so far:

load('x');          % a real signal, e.g., speech
X = hilbert(x);   % analytic signal
fs = 1000;        % sample rate

% -- here is where I "mysteriously" do If estimate, but seems to fail
if = diff(unwrap(angle(X)));


Thanks for the help!
Marcus

magoldfish@gmail.com wrote:
> Hi, > > Sorry if this is a familiar post, but I haven't found an explicit > answer. In Matlab, how can I find the instantaneous frequency using > the Hilbert transform? This is the code I have so far: > > load('x'); % a real signal, e.g., speech > X = hilbert(x); % analytic signal > fs = 1000; % sample rate > > % -- here is where I "mysteriously" do If estimate, but seems to fail > if = diff(unwrap(angle(X))); > > > Thanks for the help! > Marcus
Compute angles of differences instead of differences of angles: z=hilbert(x); N=length(x); f=angle(z(2:N).*conj(x(1:N-1)))/2/pi; % mult by Fs to get Hertz John
john wrote:
> magoldfish@gmail.com wrote: > > Hi, > > > > Sorry if this is a familiar post, but I haven't found an explicit > > answer. In Matlab, how can I find the instantaneous frequency using > > the Hilbert transform? This is the code I have so far: > > > > load('x'); % a real signal, e.g., speech > > X = hilbert(x); % analytic signal > > fs = 1000; % sample rate > > > > % -- here is where I "mysteriously" do If estimate, but seems to fail > > if = diff(unwrap(angle(X))); > > > > > > Thanks for the help! > > Marcus > > Compute angles of differences instead of differences of angles: > > z=hilbert(x); > N=length(x); > f=angle(z(2:N).*conj(x(1:N-1)))/2/pi; % mult by Fs to get Hertz > > John
Typo, sorry. the x in the equation for f should also be a z. John
magoldfish@gmail.com writes:

> Hi, > > Sorry if this is a familiar post, but I haven't found an explicit > answer. In Matlab, how can I find the instantaneous frequency using > the Hilbert transform? This is the code I have so far: > > load('x'); % a real signal, e.g., speech > X = hilbert(x); % analytic signal > fs = 1000; % sample rate > > % -- here is where I "mysteriously" do If estimate, but seems to fail > if = diff(unwrap(angle(X)));
Isn't "if" a matlab keyword? (if (X==1)...). What do you mean by "seems to fail" ? Ciao, Peter K. -- "And he sees the vision splendid of the sunlit plains extended And at night the wondrous glory of the everlasting stars."



Peter K. wrote:
> magoldfish@gmail.com writes: > > > Hi, > > > > Sorry if this is a familiar post, but I haven't found an explicit > > answer. In Matlab, how can I find the instantaneous frequency using > > the Hilbert transform? This is the code I have so far:
> Isn't "if" a matlab keyword? (if (X==1)...).
Of course "if" is a Matlab keyword-- sorry, typo. Replace with "If".
> What do you mean by "seems to fail" ?
Fails, as in it does not give me the instantaneous frequency. Thanks to John in the previous threaded post for pointing out the correct order of operations. Marcus
On 9 Feb 2006 16:02:30 -0800, magoldfish@gmail.com wrote:

>Hi, > >Sorry if this is a familiar post, but I haven't found an explicit >answer. In Matlab, how can I find the instantaneous frequency using >the Hilbert transform? This is the code I have so far: > >load('x'); % a real signal, e.g., speech >X = hilbert(x); % analytic signal >fs = 1000; % sample rate > >% -- here is where I "mysteriously" do If estimate, but seems to fail >if = diff(unwrap(angle(X))); > > >Thanks for the help! >Marcus
Hi Marcus, your code above should work fine. (After eliminating the "if" variable name.) I'm assuming your "x" sequence is much longer than the length of the filter built in to the "hilbert()" command. The only thing I can think might be causin' you trouble is that the "diff()" command is only accurate for low-frequency signals relative to the sample rate. Ya' might try differentiating your "unwrap(angle(X))" sequence with a wider-bandwidth differentiator that you can design using the "remez()" command. Good Luck, [-Rick-]
On Thu, 16 Feb 2006 01:35:32 +0000, Rick Lyons wrote:

> On 9 Feb 2006 16:02:30 -0800, magoldfish@gmail.com wrote: > >>Hi, >> >>Sorry if this is a familiar post, but I haven't found an explicit >>answer. In Matlab, how can I find the instantaneous frequency using >>the Hilbert transform? This is the code I have so far: >> >>load('x'); % a real signal, e.g., speech >>X = hilbert(x); % analytic signal >>fs = 1000; % sample rate >> >>% -- here is where I "mysteriously" do If estimate, but seems to fail >>if = diff(unwrap(angle(X))); >> >> >>Thanks for the help! >>Marcus > > Hi Marcus, > > your code above should work fine. > (After eliminating the "if" variable name.) > > I'm assuming your "x" sequence is much longer > than the length of the filter built in to the > "hilbert()" command. > > The only thing I can think might be causin' you > trouble is that the "diff()" command is only > accurate for low-frequency signals relative to the > sample rate. > > Ya' might try differentiating your > "unwrap(angle(X))" sequence with a wider-bandwidth > differentiator that you can design using the > "remez()" command. > > Good Luck, > [-Rick-]
Aside from that, this model of "instantaneous frequency" really only makes any sense if the signal in question only has one significant frequency at any point in time. If the signal is broad-band (noise or multi-component periodic), then the sample-by-sample answer that differentiated phase gives you is not terribly useful, in my experience. Since Marcus' original question had 'x' be eg speech, that pretty much counts this simple notion of instantaneous frequency out, IMO. His best bet might be some sort of spectrogram peak tracker. Peter K's web site has a really good paper on the subject. Cheers, -- Andrew
Andrew Reilly wrote:

   ...

> Aside from that, this model of "instantaneous frequency" really only makes > any sense if the signal in question only has one significant frequency at > any point in time. If the signal is broad-band (noise or multi-component > periodic), then the sample-by-sample answer that differentiated phase > gives you is not terribly useful, in my experience.
While it's true that frequency can be defined as rate of phase change, phase itself is only relevant at a single frequency. What possible meaning could the relative phase of adjacent-channel carriers have? Except in special cases, the sample-by-sample answer that differentiated phase gives you is not only useless, but meaningless. [ducks for cover] Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
On Thu, 16 Feb 2006 17:56:11 +1100, Andrew Reilly
<andrew-newspost@areilly.bpc-users.org> wrote:

  (snipped)

>Aside from that, this model of "instantaneous frequency" really only makes >any sense if the signal in question only has one significant frequency at >any point in time. If the signal is broad-band (noise or multi-component >periodic), then the sample-by-sample answer that differentiated phase >gives you is not terribly useful, in my experience. > >Since Marcus' original question had 'x' be eg speech, that pretty much >counts this simple notion of instantaneous frequency out, IMO. > >His best bet might be some sort of spectrogram peak tracker. > >Peter K's web site has a really good paper on the subject. > >Cheers, > >-- >Andrew
Hi Andrew, I've modeled that "instantaneous frequency" computation scheme for triangular time sequences that have a "fundamental plus harmonics" spectral content. The scheme seems to work fine sl long as the differentiator has a sufficiently wideband frequency range of operation. Maybe, when I have a chance, I should experiment with that FM demod scheme against actual speech signals. See Ya', [-Rick-]
Andrew Reilly wrote:

> If the signal is broad-band (noise or multi-component > periodic), then the sample-by-sample answer that differentiated phase > gives you is not terribly useful, in my experience.
But one of the postgrads in the lab where you did your PhD did his entire thesis on estimating the instantaneous frequency of White noise! Ciao, Peter K.