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