# Compensate for FIR filter attenuation

Is there a simple way to compensate for the reduction in amplitude of a low pass filter of a noisy sine wave signal that has been smoothed using a FIR filter so that the amplitude of the smoothed sine wave matches that of the approximately known amplitude of the noisy original signal? The approximate amplitude of the original data could be estimated empirically from the RMS value over one full (estimated) period. The FIR filter coefficients I am using are

h = [ 1 2 3 3 2 1 ] / 12

• what's the "amplitude of the noisy signal"? Can you try to formulate that mathematically? That could mean very different things, depending on how you defined it (RMS, expectation of |·|, amplitude of the original sine…) – Marcus Müller Jan 18 '18 at 14:58
• what's the frequency of the sine wave ? – Fat32 Jan 18 '18 at 18:21

## 1 Answer

FIR definition:

$$y[n] = \sum_{k=0}^{N} { b_k x[n-k] }$$

Sinusoid signal definition:

$$x[n] = M \cos( \alpha n + \phi )$$

A whole bunch of math:

$$y[n] = M \sum_{k=0}^{N} { b_k \cos( \alpha (n-k) + \phi ) }$$

$$y[n] = M \sum_{k=0}^{N} { b_k [ \cos( \alpha n + \phi ) \cos( \alpha k ) + \sin( \alpha n + \phi ) \sin( \alpha k ) ] }$$

$$y[n] = M \cos( \alpha n + \phi ) \sum_{k=0}^{N} { b_k \cos( \alpha k ) } + M \sin( \alpha n + \phi ) \sum_{k=0}^{N} { b_k \sin( \alpha k ) }$$

$$y[n] = A \cos( \alpha n + \phi ) + B \sin( \alpha n + \phi )$$

$$A = M \sum_{k=0}^{N} { b_k \cos( \alpha k ) }$$

$$B = M \sum_{k=0}^{N} { b_k \sin( \alpha k ) }$$

$$y[n] = M_2 \cos( \alpha n + \phi + \theta )$$

$$y[n] = M_2 \cos( \theta ) \cos( \alpha n + \phi ) - M_2 \sin( \theta ) \sin( \alpha n + \phi )$$

$$A = M_2 \cos( \theta )$$

$$B = -M_2 \sin( \theta )$$

$$A^2 + B^2 = M_2^2 = M^2 \left[ \left( \sum_{k=0}^{N} { b_k \cos( \alpha k ) } \right)^2 + \left( \sum_{k=0}^{N} { b_k \sin( \alpha k ) } \right)^2 \right]$$

Your desired equation:

$$\frac{M}{M_2} = \frac{ 1 }{ \sqrt{ \left( \sum_{k=0}^{N} { b_k \cos( \alpha k ) } \right)^2 + \left( \sum_{k=0}^{N} { b_k \sin( \alpha k ) } \right)^2 } }$$

I think I've done the math right. The $b_k$s are your FIR coefficients and $\alpha$ is your frequency in radians per sample. $M_2$ is the amplitude of your smoothed sinusoid and $M$ is the original amplitude.

So you want multiply your smoothed results by $\frac{M}{M_2}$.

Hope this helps. I just did this and haven't tested it.

Ced

• Love the "definition, definition, heap of math" style of yours :) – Marcus Müller Jan 18 '18 at 20:25
• @MM, Thanks. Then you'll love my blog articles. You an also find the link on my profile page. dsprelated.com/blogs-1/nf/Cedron_Dawg.php – Cedron Dawg Jan 18 '18 at 20:45