I have signal containing a large amount of mains noise. I'm trying to feed this back into my signal to actively cancel it from future measurements, but I'm having trouble getting it to work. I have tried taking the fft bin with the maximum mains noise, generating a sin wave of the function:

bin.real * Sin ( bin.frequency * 2 * PI * T + bin.phase)

where bin.frequency is calculated to be the mains noise at the time of measurement (~$50\textrm{ Hz}$).

When I subtract this from my original signal it still looks very noisy, albeit a different kind of noisy. If my sample rate is $250\textrm{ Hz}$, I'm thinking I need to increment T by $1/250$ to correctly generate the signal.

What is the correct way to go about this?

  • 3
    $\begingroup$ if you're trying to remove a sinusoidal component of a known frequency from a signal, use a notch filter. $\endgroup$ Oct 21 '16 at 3:06
  • 1
    $\begingroup$ Mains is a known frequency, that varies very little in comparison to the width of a typical filter. So, any reasonable notch filter (whether analog or digital) designed for 50Hz will cover any variation in mains frequency that you are likely to encounter. $\endgroup$
    – JRE
    Oct 21 '16 at 8:36

If the transfer function between the mains signal and your contaminated signal is fixed forever, then you could cancel the interference with a sine wave that is locked to the mains, and adjusted in both amplitude and phase to cancel your interference. However, using an fft is not the optimal way to do this, as the true mains frequency will likely fall in between the bins, so you will have a frequency error. A better way is to use a dsp phase-locked loop, the details of which are too complex to describe here. However, it is unlikely that the transfer function is fixed. Therefore you will need an adaptive algorithm to adjust the amplitude and phase of your cancellation signal. This adaptive algorithm will look at (input signal - cancellation signal) and attempt to minimize the portion that is correlated to the mains frequency. Unfortunately the adaptive algorithm will be affected if there is a component in your desired signal that is close to the mains frequency, which will reduce the attenuation of the mains frequency and also add attenuation to the desired signal. So it behaves very much like a notch filter, so you might as well just use a notch filter as RBJ has recommended. You can minimize this interference effect by making the adaptive algorithm very slow, but again this is roughly equivalent to using a higher-q notch filter, and both systems will take a long time to settle out.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.