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) 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,x) 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