Can the instantaneous frequency be always derived from an analytic signal?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Instantaneous frequency can be defined as a derivative of an instantaneous phase of an analytic signal which can be nicely seen in practice in this example from Scipy's documentation. But it seems like it does not always work like this. I played with the code from the example and obtained varied results like for this sine wave with frequency gradually changing from 2 to 12Hz:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
w = 2*np.pi*(2 + 10*t)
signal = np.sin(w*t)
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = (np.diff(instantaneous_phase) /
(2.0*np.pi) * fs)
This is the resulting figure with the original frequency plotted in grey on the bottom subplot:
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(t, signal, label='signal')
ax0.plot(t, amplitude_envelope, label='envelope')
ax0.set_xlabel("time in seconds")
ax0.legend()
ax1 = fig.add_subplot(212)
ax1.plot(t, 0.5*w/np.pi, lw=2, color='gray')
ax1.plot(t[1:], instantaneous_frequency)
ax1.set_xlabel("time in seconds")
fig.show()
In the bottom plot the blue line and the grey line go in the same direction, but there is a huge discrepancy between the two and I do not mean the ever-present edge effect. The calculated instantaneous frequency is rising at the rate that is almost a double of the actual reaching values above 20Hz at the end.
I tried it for other sine waves with constant amplitudes and varied frequencies getting similar results. Only when I used a signal with a constant frequency the blue line was matching the grey line on the bottom plot. My question here is: are there any conditions a signal must meet for the definition of the instantaneous frequency to hold true, so it can be derived from the instantaneous phase of the analytic signal?
frequency phase hilbert-transform
add a comment |Â
up vote
2
down vote
favorite
Instantaneous frequency can be defined as a derivative of an instantaneous phase of an analytic signal which can be nicely seen in practice in this example from Scipy's documentation. But it seems like it does not always work like this. I played with the code from the example and obtained varied results like for this sine wave with frequency gradually changing from 2 to 12Hz:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
w = 2*np.pi*(2 + 10*t)
signal = np.sin(w*t)
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = (np.diff(instantaneous_phase) /
(2.0*np.pi) * fs)
This is the resulting figure with the original frequency plotted in grey on the bottom subplot:
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(t, signal, label='signal')
ax0.plot(t, amplitude_envelope, label='envelope')
ax0.set_xlabel("time in seconds")
ax0.legend()
ax1 = fig.add_subplot(212)
ax1.plot(t, 0.5*w/np.pi, lw=2, color='gray')
ax1.plot(t[1:], instantaneous_frequency)
ax1.set_xlabel("time in seconds")
fig.show()
In the bottom plot the blue line and the grey line go in the same direction, but there is a huge discrepancy between the two and I do not mean the ever-present edge effect. The calculated instantaneous frequency is rising at the rate that is almost a double of the actual reaching values above 20Hz at the end.
I tried it for other sine waves with constant amplitudes and varied frequencies getting similar results. Only when I used a signal with a constant frequency the blue line was matching the grey line on the bottom plot. My question here is: are there any conditions a signal must meet for the definition of the instantaneous frequency to hold true, so it can be derived from the instantaneous phase of the analytic signal?
frequency phase hilbert-transform
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Instantaneous frequency can be defined as a derivative of an instantaneous phase of an analytic signal which can be nicely seen in practice in this example from Scipy's documentation. But it seems like it does not always work like this. I played with the code from the example and obtained varied results like for this sine wave with frequency gradually changing from 2 to 12Hz:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
w = 2*np.pi*(2 + 10*t)
signal = np.sin(w*t)
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = (np.diff(instantaneous_phase) /
(2.0*np.pi) * fs)
This is the resulting figure with the original frequency plotted in grey on the bottom subplot:
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(t, signal, label='signal')
ax0.plot(t, amplitude_envelope, label='envelope')
ax0.set_xlabel("time in seconds")
ax0.legend()
ax1 = fig.add_subplot(212)
ax1.plot(t, 0.5*w/np.pi, lw=2, color='gray')
ax1.plot(t[1:], instantaneous_frequency)
ax1.set_xlabel("time in seconds")
fig.show()
In the bottom plot the blue line and the grey line go in the same direction, but there is a huge discrepancy between the two and I do not mean the ever-present edge effect. The calculated instantaneous frequency is rising at the rate that is almost a double of the actual reaching values above 20Hz at the end.
I tried it for other sine waves with constant amplitudes and varied frequencies getting similar results. Only when I used a signal with a constant frequency the blue line was matching the grey line on the bottom plot. My question here is: are there any conditions a signal must meet for the definition of the instantaneous frequency to hold true, so it can be derived from the instantaneous phase of the analytic signal?
frequency phase hilbert-transform
Instantaneous frequency can be defined as a derivative of an instantaneous phase of an analytic signal which can be nicely seen in practice in this example from Scipy's documentation. But it seems like it does not always work like this. I played with the code from the example and obtained varied results like for this sine wave with frequency gradually changing from 2 to 12Hz:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
duration = 1.0
fs = 400.0
samples = int(fs*duration)
t = np.arange(samples) / fs
w = 2*np.pi*(2 + 10*t)
signal = np.sin(w*t)
analytic_signal = hilbert(signal)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.unwrap(np.angle(analytic_signal))
instantaneous_frequency = (np.diff(instantaneous_phase) /
(2.0*np.pi) * fs)
This is the resulting figure with the original frequency plotted in grey on the bottom subplot:
fig = plt.figure()
ax0 = fig.add_subplot(211)
ax0.plot(t, signal, label='signal')
ax0.plot(t, amplitude_envelope, label='envelope')
ax0.set_xlabel("time in seconds")
ax0.legend()
ax1 = fig.add_subplot(212)
ax1.plot(t, 0.5*w/np.pi, lw=2, color='gray')
ax1.plot(t[1:], instantaneous_frequency)
ax1.set_xlabel("time in seconds")
fig.show()
In the bottom plot the blue line and the grey line go in the same direction, but there is a huge discrepancy between the two and I do not mean the ever-present edge effect. The calculated instantaneous frequency is rising at the rate that is almost a double of the actual reaching values above 20Hz at the end.
I tried it for other sine waves with constant amplitudes and varied frequencies getting similar results. Only when I used a signal with a constant frequency the blue line was matching the grey line on the bottom plot. My question here is: are there any conditions a signal must meet for the definition of the instantaneous frequency to hold true, so it can be derived from the instantaneous phase of the analytic signal?
frequency phase hilbert-transform
asked Aug 18 at 12:37
mac13k
1527
1527
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
This is because the phase term is changing with time at the rate of $t^2$ for the frequency ramp, and since the instantanous frequency is the derivative of the phase your result is as expected.
$m(t) = cos(2pi f(t) t)$
$phi = 2pi f(t) t$
$f(t) = Kt$ for a linear frequency ramp
thus phase versus time changes at the rate of $t^2$
$phi = 2pi Kt^2$
and the derivative of the phase (which is the instantaneous radian frequency) is:
$fracdphidt = 4pi Kt$
(Divide this by $2pi$ to get instaneous frequency, but the source of the 2x discrepancy should now be very clear).
See the answer to this DSP Challenge that I posted that further explains this:
Simulation of a Frequency ramp
add a comment |Â
up vote
3
down vote
You are doing it wrong. Your signal is $$sin(2pi(2+10t)t)$$ which makes the instantaneous frequency $$(2pi)^-1fracrm d rm dt(2pi(2+10t)t) = 2+20t$$. Basically your "change of frequency" additionally increases the already currently accumulated phase, resulting in double the frequency change you were planning for.
Very common error when creating chirps.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
This is because the phase term is changing with time at the rate of $t^2$ for the frequency ramp, and since the instantanous frequency is the derivative of the phase your result is as expected.
$m(t) = cos(2pi f(t) t)$
$phi = 2pi f(t) t$
$f(t) = Kt$ for a linear frequency ramp
thus phase versus time changes at the rate of $t^2$
$phi = 2pi Kt^2$
and the derivative of the phase (which is the instantaneous radian frequency) is:
$fracdphidt = 4pi Kt$
(Divide this by $2pi$ to get instaneous frequency, but the source of the 2x discrepancy should now be very clear).
See the answer to this DSP Challenge that I posted that further explains this:
Simulation of a Frequency ramp
add a comment |Â
up vote
3
down vote
accepted
This is because the phase term is changing with time at the rate of $t^2$ for the frequency ramp, and since the instantanous frequency is the derivative of the phase your result is as expected.
$m(t) = cos(2pi f(t) t)$
$phi = 2pi f(t) t$
$f(t) = Kt$ for a linear frequency ramp
thus phase versus time changes at the rate of $t^2$
$phi = 2pi Kt^2$
and the derivative of the phase (which is the instantaneous radian frequency) is:
$fracdphidt = 4pi Kt$
(Divide this by $2pi$ to get instaneous frequency, but the source of the 2x discrepancy should now be very clear).
See the answer to this DSP Challenge that I posted that further explains this:
Simulation of a Frequency ramp
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
This is because the phase term is changing with time at the rate of $t^2$ for the frequency ramp, and since the instantanous frequency is the derivative of the phase your result is as expected.
$m(t) = cos(2pi f(t) t)$
$phi = 2pi f(t) t$
$f(t) = Kt$ for a linear frequency ramp
thus phase versus time changes at the rate of $t^2$
$phi = 2pi Kt^2$
and the derivative of the phase (which is the instantaneous radian frequency) is:
$fracdphidt = 4pi Kt$
(Divide this by $2pi$ to get instaneous frequency, but the source of the 2x discrepancy should now be very clear).
See the answer to this DSP Challenge that I posted that further explains this:
Simulation of a Frequency ramp
This is because the phase term is changing with time at the rate of $t^2$ for the frequency ramp, and since the instantanous frequency is the derivative of the phase your result is as expected.
$m(t) = cos(2pi f(t) t)$
$phi = 2pi f(t) t$
$f(t) = Kt$ for a linear frequency ramp
thus phase versus time changes at the rate of $t^2$
$phi = 2pi Kt^2$
and the derivative of the phase (which is the instantaneous radian frequency) is:
$fracdphidt = 4pi Kt$
(Divide this by $2pi$ to get instaneous frequency, but the source of the 2x discrepancy should now be very clear).
See the answer to this DSP Challenge that I posted that further explains this:
Simulation of a Frequency ramp
edited Aug 18 at 13:48
answered Aug 18 at 13:40
Dan Boschen
7,9402930
7,9402930
add a comment |Â
add a comment |Â
up vote
3
down vote
You are doing it wrong. Your signal is $$sin(2pi(2+10t)t)$$ which makes the instantaneous frequency $$(2pi)^-1fracrm d rm dt(2pi(2+10t)t) = 2+20t$$. Basically your "change of frequency" additionally increases the already currently accumulated phase, resulting in double the frequency change you were planning for.
Very common error when creating chirps.
add a comment |Â
up vote
3
down vote
You are doing it wrong. Your signal is $$sin(2pi(2+10t)t)$$ which makes the instantaneous frequency $$(2pi)^-1fracrm d rm dt(2pi(2+10t)t) = 2+20t$$. Basically your "change of frequency" additionally increases the already currently accumulated phase, resulting in double the frequency change you were planning for.
Very common error when creating chirps.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You are doing it wrong. Your signal is $$sin(2pi(2+10t)t)$$ which makes the instantaneous frequency $$(2pi)^-1fracrm d rm dt(2pi(2+10t)t) = 2+20t$$. Basically your "change of frequency" additionally increases the already currently accumulated phase, resulting in double the frequency change you were planning for.
Very common error when creating chirps.
You are doing it wrong. Your signal is $$sin(2pi(2+10t)t)$$ which makes the instantaneous frequency $$(2pi)^-1fracrm d rm dt(2pi(2+10t)t) = 2+20t$$. Basically your "change of frequency" additionally increases the already currently accumulated phase, resulting in double the frequency change you were planning for.
Very common error when creating chirps.
answered Aug 18 at 13:58
user37282
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdsp.stackexchange.com%2fquestions%2f51319%2fcan-the-instantaneous-frequency-be-always-derived-from-an-analytic-signal%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password