Filtering out a specific frequency in an analog signal I'm wondering how I would go about filtering out a regular sine-wave signal with a constant frequency and voltage.

I'm really new to the whole DSP-area but imagine I would have a regular sinewave at a specific frequency (let's say 30Hz), and on top of that signal I have a bunch of other small peaks (which are the ones I would want to sample and read). What method would I choose?

Here is a visualization of what I meant:



Excuse my terrible Paint-skills but how would I filter out that sinewave, and just keep the small spikes in voltage? What might be worth sharing is that the time between the spikes does have an impact on my measurement of the spikes, or to rephrase: The amount of spikes within x-units of time does have an impact.

Any guidance to the right direction would really be appreciated.

Thank you.
A notch filter is a good approach in general for removing an unwanted frequency. But if you are certain of the exact frequency, phase and amplitude of the unwanted sine wave, then you may also consider adding the noisy signal to a sine wave of the same frequency and amplitude but 180 degrees out of phase with the unwanted sine wave.



To illustrate the notch filter example, the plot below shows an attempt to generate a sine wave with some odd impulses (black), and then filter it with a notch filter knowing the exact frequency (red).



R code for implementing it below.



# 24782
# install.packages('signal')

T &lt;- 1024
t &lt;- 0:(T-1)

fs &lt;- 1000
omega &lt;- 2*pi*30/1000
phi &lt;- 0.9279835

x &lt;- sin(omega*t + phi)

changed &lt;- sample(1:T, 10)

y &lt;- x
y[changed] &lt;- y[changed] + 3

alpha &lt;- 0.9
num &lt;- c(1, -2*cos(omega), 1)
den &lt;- c(1, -2*alpha*cos(omega), alpha*alpha)

yf &lt;- signal::filter(num, den, y)

plot(t,y, type="l", lwd=10)
lines(t,yf, col="red", lwd=4)

legend(850, 4, c("Original", "Filtered"), lwd=c(2.5,2.5),col=c("black","red"))