Can the instantaneous frequency be always derived from an analytic signal?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












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()


enter image description here



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?







share|improve this question
























    up vote
    2
    down vote

    favorite
    1












    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()


    enter image description here



    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?







    share|improve this question






















      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      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()


      enter image description here



      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?







      share|improve this question












      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()


      enter image description here



      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?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 18 at 12:37









      mac13k

      1527




      1527




















          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






          share|improve this answer





























            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.






            share|improve this answer




















              Your Answer




              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "295"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              noCode: true, onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              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






              share|improve this answer


























                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






                share|improve this answer
























                  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






                  share|improve this answer














                  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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 18 at 13:48

























                  answered Aug 18 at 13:40









                  Dan Boschen

                  7,9402930




                  7,9402930




















                      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.






                      share|improve this answer
























                        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.






                        share|improve this answer






















                          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.






                          share|improve this answer












                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 18 at 13:58







                          user37282


































                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              Long meetings (6-7 hours a day): Being “babysat” by supervisor

                              Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                              Confectionery