# Calculate power of sinusoids with FFT

Suppose we have a signal which contains several sinusoids with different known frequencies and noise. My object is to find the total power of these sinusoids. There are two methods for this problem, in my opinion.

1. Frequency domain method: Take the FFT of the signal, square the amplitudes of sinusoids and sum.

This method is simple and easy to implement. But one drawback is spectral leakage since the sinusoid frequency may not be multiples of the frequency resolution. This side effect could be reduced if we sum the squares of the amplitudes in a small range, say 6 bins, near the sinusoid frequency. This has the same effect of zeroing the frequency bins outside the sinusoid bins. Since zeroing bins is equivalent to frequency domain filtering using a "brickwall filter" (the actual situation is this filter is not brickwall at wall, see this for more information), it suffers from alias as a result of circular convolution. Such alias error can not be eliminated because we are filtering in frequency domain and neither the signal nor the impulse response of the "brickwall filter" can be zero-padded.

2. Time domain method: design filters with several very narrow passband that are centered at the sinusoid frequency, filter and sum the squares of output time samples.

This method does not suffer from spectral leakage and circular convolution alias, but it is complex since we have to design very narrow passband filters. When the sampling frequency is large, the number of coefficients may be prohibitly large. Though we can use multistage filter to reduce the filter order, but it further complicates the problem.

How do you comment on the above methods? Which one would you choose?

For me, I prefer the frequency domain method. But how to reduce the effects of spectral leakage and circular convolution alias so as to improve accuracy?

If the time domain method is used, is there a method to design such narrowband filter that are centered respectively at the known frequency?

I would strongly advise against any approach using discrete filters in the time domain given the simplicity and robustness of using the FFT. The "best" approach in my mind for this application is clear and by far to window the time domain waveform and then take the FFT when the frequency content can arbitrarily be anywhere in the digital bandwidth.

The window is chosen by trading off frequency resolution and sidelobe rejection (spectral leakage) for a given number of samples (total duration). The assumption is the signal of interest is stationary over the duration taken, as the FFT will report the average power for each tone over that duration. I detail the specifics of doing this including properly factoring for window gain and resolution bandwidth at this post:

Find the Equivalent Noise Bandwidth

• How would the circular convolution alias be reduced if FFT is used? Apr 13, 2022 at 0:40
• @ecook The exact same way-- windowing reduces the aliasing in circular fashion. For eaxmple, without windowing, a single tone would extend as a Sinc function (with the peak of the sidelobes going down as 1/f) circularly through the result, resulting in an "aliased Sinc function" which we formally call the "Dirichlet Kernel". Windowing increases the width of this main lobe compared to a Sinc, at the benefit of significantly reducing the sidelobes. Apr 13, 2022 at 0:43
• The extent of reduction is not enough in my application. My thought is as follows, please point out if I am wrong. Zeroing frequency bins is equivalent to multiplying the signal's N-point FFT with an N-point rectangular window, which gives an N-point signal after IFFT. But with linear convolution, the result should be a (2N-1)-point signal. This means almost the left half of the (2N-1)-point signal is aliased to the right half. Using a window with tapering only attenuations the input signal at ends, but the alias is still serious when the input signal has an U-shaped amplitude of envelop. Apr 13, 2022 at 1:33
• @ecook sorry just seeing your comment now (use @ with my name to alert me). The aliasing is in the frequency domain, not the time domain-- we convolve in the frequency domain and multiply in the time domain. Zero padding the time domain signal does not reduce the aliasing but simply interpolates more samples in between the ones you have in the frequency domain. As you described the Kernel (FT) has a Sinc function, which has sidelobes that go down relatively slowly versus freq. THIS convolves in the frequency domain with your signal, smearing into other tones, and for a real tone... Apr 19, 2022 at 12:50
• ...the two components of the real tone at the positive and negative frequencies will interfere (in particular when the tone is close to f=0 or f=fs). You reduce this by windowing in the time domain at the expense of losing some frequency resolution which is usually the right trade to make. Look at the DTFT of common windows compared to a rectangular window and see the amazing performance you can get in reducing this aliasing and interaction I describe (what we typically call spectral leakage). Apr 19, 2022 at 12:52

"Best" always depends on what metric you will be using to determine what "better" means. These metric needs to be derived from the requirements of your specific application (desired accuracy, SNR, number of frequencies, resource constraints, latency, desired time resolution, etc.)

But how to reduce the effects of spectral leakage and circular convolution alias so as to improve accuracy?

Spectral leakage can be reduced by windowing. The choice of window provides a trade off between reducing leakage and width of the main lobe. For a simple power calculation, circular aliasing shouldn't make much of a difference and windowing will reduce the effects of it as well.

... the number of coefficients may be prohibitly large.

You can build very narrow and steep bandpass filters using IIR filters of relatively low order, regardless of sample rate. Downside would be large group delay and potentially numerical and/or stability problems.

Is there a method to design such narrowband filter that are centered respectively at the known frequency?

Sure. Any standard IIR bandpass will do.

Which one would choose?

Both methods are valid and both have their advantages and disadvantages. As stated earlier, it's hard to recommend one over the other without knowing your specific requirements.

• Thank you for answering the questions one by one. Do you have any reference to how to design narrowband IIR filters, especially filters that have multiple narrowbands which are centered at given number of sinusoid frequencies? Apr 13, 2022 at 0:39