I am driving a system with a step-wise frequency chirp from 50-400 hz with a frequency step of 0.01 hz. I am having difficulty identifying the points of frequency change as the data collected has an indeterminate amount of time at 50 Hz and an indeterminate amount of time at 400 Hz. Since the time between frequency changes is 0.1 seconds an fft calculation doesn't provide the proper frequency resolution to determine this change. I also tried calculating the gradient of the frequency chirp with inconclusive results as well as attempting a lock-in calculation. I wrote some sample code that has a randomly located frequency step followed by another 0.1 secs later that I have been trying to diagnose with varying success. Ultimately I am trying to identify the beginning and end of the frequency chirp since at that point the step changes are known but this change point identification was attempted to identify the point of change between 50 and 50.01, then backtracking to find the beginning of the series. Any suggestions would be very much appreciated.

import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

fs = 10000
t = np.linspace(0,1,1*fs)
x = np.zeros(len(t))

step_loc = int(2500 + 5000*np.random.random(1))

x[:step_loc] = np.sin(50*2*pi*t[:step_loc])
x[step_loc:step_loc+1000] = np.sin(50.01*2*pi*t[step_loc:step_loc+1000])
x[step_loc+1000:] = np.sin(50.02*2*pi*t[step_loc+1000:])

grad = np.gradient(x,t[1])

lock = x*(np.cos(50*2*pi*t) + 1j*np.sin(50*2*pi*t))
b, a = signal.butter(5,30/10000, 'low')
lock_filt = signal.filtfilt(b, a, lock)

plt.plot(t,grad*3e-3)     #this is offering very inconsistent identifiable results
plt.plot(t,lock_filt*1e1) #although this can identify the general area of the random frequency change i
                      # dont know how to extend it to identifying the actual point 
  • $\begingroup$ Have you tried monitoring phase versus time instead of frequency? $\endgroup$ – Dan Boschen Mar 22 '20 at 19:52
  • $\begingroup$ @DanBoschen Thank you, it doesnt seem that the phase noticeably changes with the change of frequency. Should it? $\endgroup$ – Jon Mar 22 '20 at 21:02
  • $\begingroup$ Or is there a method aside from a lockin calculation that would find the wave's phase with time? $\endgroup$ – Jon Mar 22 '20 at 21:13
  • $\begingroup$ Yes it should as frequency by definition is the slope (derivative) of phase. I recommend detrending the phase versus time at your starting frequency and then monitor for when it starts to ramp up. $\endgroup$ – Dan Boschen Mar 22 '20 at 21:23
  • $\begingroup$ @DanBoschen That worked, thank you! $\endgroup$ – Jon Mar 22 '20 at 22:50

I suggest monitoring the phase versus time directly instead of frequency. Frequency is the derivative of phase so the slope of the phase would indicate the frequency. Detrend the phase slope for the starting frequency and then the point in time where the phase starts to ramp up should be easier to detect. The window in which to detect this change will be balanced with the SNR of the signal itself.

Since frequency is the derivative of phase, it will be more sensitive to high frequency noise (the derivative is a high pass function), which is why monitoring phase directly could be a more reliable approach.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.