I would like to detect signals in the frequency domain. That is, having a spectrogram, automatically determine the signal in it (its frequency and bandwidth). I tried to apply the algorithm described here Peak signal detection in realtime timeseries data, but I get incorrect data (noise and incorrect signal values are detected). An example of a spectrogram with which I work is in the picture. The detection of broadband signals and signals with frequency modulation is especially interesting. Perhaps someone will suggest similar implementations in python. Thank you in advance. This is how I process the spectrum:
self.L = 15 # L-point filter
self.b = (np.ones(self.L)) / self.L # numerator co-effs of filter transfer function
self.a = np.ones(1) # denominator co-effs of filter transfer function
fft_data = np.fft.fft(balanced_signal, n=self.fft_size) / self.fft_size
_fft_log = (np.abs(np.fft.fftshift(fft_data)))
_fft_log = ss.lfilter(self.b, self.a, _fft_log)
spectrum = savgol_filter(_fft_log, 100, 5,mode='nearest')
Then I pass this data to the signal detection function expecting to get 1 where there is a signal and 0 where there is a noise value spectrum of mine signal:
lag = 30
threshold = 5
influence = 0
def thresholding_algo(self,y, lag, threshold, influence):
signals = np.zeros(len(y))
filteredY = np.array(y)
avgFilter = [0] * len(y)
stdFilter = [0] * len(y)
avgFilter[lag - 1] = np.mean(y[0:lag])
stdFilter[lag - 1] = np.std(y[0:lag])
for i in range(lag, len(y)):
if abs(y[i] - avgFilter[i - 1]) > threshold * stdFilter[i - 1]:
if y[i] > avgFilter[i - 1]:
signals[i] = 1
else:
signals[i] = -1
filteredY[i] = influence * y[i] + (1 - influence) * filteredY[i - 1]
avgFilter[i] = np.mean(filteredY[(i - lag + 1):i + 1])
stdFilter[i] = np.std(filteredY[(i - lag + 1):i + 1])
else:
signals[i] = 0
filteredY[i] = y[i]
avgFilter[i] = np.mean(filteredY[(i - lag + 1):i + 1])
stdFilter[i] = np.std(filteredY[(i - lag + 1):i + 1])
return dict(signals=np.asarray(signals),
avgFilter=np.asarray(avgFilter),
stdFilter=np.asarray(stdFilter))
But I get detected noises. As soon as I raise the threshold to 6, I have no detection at all.