# Remove constant noise from Goertzel output

I'm trying to analyze a signal recorded from an analogue phone line and do DTMF recognition using a Goertzel algorithm. However, due to a fault in the hardware, there is a constant 50Hz power line noise with a lot of harmonics included in the recorded signal. In short term there is no possibility to change the hardware so I was wondering if it is possible to 'substract' a known noise level (from a periodic noise) from the Goertzel results?

Until now, I'm doing the Goertzel calculations like this:

samplesCount = 320, scalingFactor = samplesCount/2

Magnitude

rawRelMagnitudeSquared = (q1*q1 + q2*q2 - q1*q2*frequency.coeff);

Decibel level

db = 10.0f * log10f(rawRelMagnitudeSquared / 3225);

Power ratio

scaledRelMagnitudeSquared = 2*rawRelMagnitudeSquared / scalingFactor;

signalAbsPower = sum each sample*sample

powerRatio = scaledRelMagnitudeSquared / signalAbsPower;

I was running this for a recording that only contains noise and measuring the average rawRelMagnitudeSquared and signalAbsPower for each DTMF frequency. I then subtracted this from the normal results I get from other signals that have the same noise. As the formula above for powerRatio gives values >1 I assume my approach is faulty. Can you help me out to understand whats wrong or if this is possible at all?