# Generating a sine wave from FFT bin

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.

• if you're trying to remove a sinusoidal component of a known frequency from a signal, use a notch filter. – robert bristow-johnson Oct 21 '16 at 3:06
• 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. – JRE Oct 21 '16 at 8:36