# How to automatically identify a surge in a periodic signal

Say I have a periodic signal i.e. Sine wave, which sometimes can have spikes that are 100% larger than the peak value. These spikes can be periodic as well. I'm trying to find an algorithm that could detect these spikes without human intervention. I was thinking for each point to average the value with the surrounding 3 or more points but it doesn't seem to be working. Any help is appreciated.

• you could approach this a lot of ways. do you know the frequency of your steady sin? – user28715 Aug 17 '19 at 12:37
• If the spikes are so much larger than your signal, why not simply use a threshold comparison? ( If signal > threshold then mark surrounding +- X seconds as spike). – JLo Aug 19 '19 at 5:38

My suggestion would be to plot the frequency response by taking the FFT of a reasonable length to see the spectrum. Apart from the two spikes in FFT output (corresponding to sinewave) you could see the DFT of the periodic spur signal with approximate amplitude of $$N$$ where $$N$$ is the period of the combined signal. The DFT of spur is a constant amplitude signal, which means, for all FFT bins, it will be constant value. If your signal is noisy, you could easily average out these values to find the amplitude of spur. You should first subtract amplitude of sinewave from the FFT before computing this. Here is the code I tried

clc
clear all
n=0:9999;
x = sin(pi/5*n);
spike = repmat([1 zeros(1,9)],1,1000);
x1 = x + spike;
plot(abs(fftshift(fft(x1,1000))))


I got the amplitude of spur signal to be $$N/N_{fft}$$.