# Accurate Measurement of a Sinusoid's Peak Amplitude Based on FFT Data

There are two code snippets associated with this blog post:

Flat-Top Windowing Function for the Accurate Measurement of a Sinusoid's Peak Amplitude Based on FFT Data

and

Testing the Flat-Top Windowing Function

This blog discusses an accurate method of estimating time-domain sinewave peak amplitudes based on fast Fourier transform (FFT) data. Such an operation sounds simple, but the scalloping loss characteristic of FFTs complicates the process. We eliminate that complication by implementing 'flat-top' windowing by way of frequency-domain convolution in a way that greatly reduces scalloping-loss amplitude-estimation problems.

FFT SCALLOPING LOSS REVISITED
There are many applications that require the estimation of a time-domain sinewave's peak amplitude based on FFT data. Such applications include oscillator and analog-to-digital converter performance measurements, as well as standard total harmonic distortion (THD) testing. However, the scalloping loss inherent in FFTs creates an uncertainty in such time-domain peak amplitude estimations. This section provides a brief review of FFT scalloping loss.

As you know, if we perform an N-point FFT on N real-valued time-domain samples of a discrete sinewave, whose frequency is an integer multiple of fs/N (fs is the sample rate in Hz), the peak magnitude of the sinewave's positive-frequency spectral component will be where A is the peak amplitude of the time-domain sinewave. That phrase "whose frequency is an integer multiple of fs/N" means that the sinewave's frequency is located exactly at one of the FFT's bin centers.

Now, if an FFT's input sinewave's frequency is between two FFT bin centers (equal to a non-integer multiple of fs/N) the FFT magnitude of that spectral component will be less that the value of M in Eq. (1). Figure 1 illustrates this behavior. Figure 1(a) shows the frequency responses of individual FFT bins where, for simplicity, we show only the mainlobes (no sidelobes) of the FFT bins' responses. What this means is that if we were to apply a sinewave to an FFT, and scan the frequency of that sinewave over multiple bins, the magnitude of the FFT's largest normalized magnitude sample value will follow the curve in Figure 1(b). That curve describes what is called the "scalloping loss" of an FFT .
(As an aside, the word scallop is not related to my favorite shellfish. As it turns out, some window drapery, and table cloths, do not have linear borders. Rather they have a series of circular segments, or loops, of fabric defining their decorative borders. Those loops of fabric are called scallops.) What Figure 1(b) tells us is that if we examine the N-point FFT magnitude sample of an arbitrary-frequency, peak amplitude = A sinewave, that spectral component's measured peak magnitude Mpeak can be in anywhere in the range of: depending on the frequency of that sinewave. This is shown as the rectangular window curve in Figure 2, where the maximum scalloping error occurs at a frequency midpoint between two FFT bins. The variable M in Figure (2) is the M from (1). So if we want to estimate a sinewave's time-domain peak amplitude A, by measuring its maximum FFT spectral peak magnitude Mpeak, our estimated value of A, from Eq. (1), using can have an error as great as 36.3%. In many spectrum analysis applications such a large potential error, equivalent to 3.9 dB, is unacceptable. Hanning and Hamming windowing of the FFT input data reduce the unpleasant frequency-dependent fluctuations in a measured spectral Mpeak value, as shown in Figure 2, but not nearly enough to satisfy many applications.

One solution to this frequency-dependent, FFT-based, measured amplitude uncertainty is to multiply the original N time-domain samples by an N-sample flat-top window function and then perform a new FFT on the windowed data. Flat-top window functions are designed to overcome the scallop loss inherent in rectangular-windowed FFTs. While such a flat-top-windowed FFT technique will work, there are more computationally-efficient methods to solve our signal peak amplitude estimation uncertainty problem.

An Accurate Measurement Process
We will solve our sinusoidal-peak measurement problem by performing convolution in the frequency domain as opposed to window-function multiplication in the time domain [2,3]. Consider the FFT magnitude samples shown in Figure 3, and let's assume we want to estimate the peak amplitude of the time-domain sinusoid corresponding to the large |X(k)| FFT sample. We can compute the complex Xft(k) sample using Once we have the value of the complex Xft(k) sample from Eq. (4), we use in Eq. (3) to yield an accurate estimate of the sinewave's time-domain peak amplitude A. Our maximum error in an estimated value of peak amplitude A, using the |Xft(k)| from Eq. (4), is roughly 0.02 dB, and is depicted as the essentially-horizontal Flat-top curve in Figure 2. That's significantly smaller than the rectangular-windowed maximum error of 3.9 dB.

Three Important Issues
First, the flat-top window frequency-domain convolutions are most useful in accurately measuring the time-domain amplitude of a sinusoidal signal when that signal's spectral component is not contaminated by sidelobe leakage from a nearby spectral component. For example, if a positive-frequency spectral component is low in frequency, i.e., located in the first few FFT bins, leakage from a spectral component's corresponding negative-frequency spectral component will contaminate that positive-frequency spectral component. As such, this code should not be used for frequencies below the sixth FFT bin or above the (N/2–5)th FFT bin.

Second, the flat-top window frequency-domain convolutions are most useful when the FFT spectral component being measured is well above the background spectral noise floor.

Third, reference  gives more details regarding this flat-top windowing process plus some clever methods of efficiently implementing the process in programmable hardware.

In the Matlab code associated with this FFT-based sinewave peak amplitude estimation method, we perform time-domain flat-top windowing of FFT samples by way of frequency-domain convolution. The input to the code is a sequence of complex-valued FFT samples, and the output of the code is a sequence of complex-valued flat-top-windowed FFT samples. If the FFT's input was a sinusoidal signal, the amplitude of that sinusoid can be accurately estimated by using Eq. (3) where Mpeak is the maximum magnitude sample of the code's output sequence. References
 F. Harris, "On the use of windows for harmonic analysis with the discrete Fourier transform," Proceedings of the IEEE, Vol. 66, No. 1, pp. 51-83, January 1978.

 E. Jacobsen, and R. Lyons, "The Sliding DFT", IEEE Signal Processing Magazine, DSP Tips & Tricks column, March, 2003.

 R. Lyons, "Reducing FFT Scalloping Loss Errors Without Multiplication", IEEE Signal Processing Magazine, DSP Tips & Tricks column, March, 2011, pp. 112-116.

Previous post by Rick Lyons:
Generating Complex Baseband and Analytic Bandpass Signals
Next post by Rick Lyons:
The History of CIC Filters: The Untold Story

[ - ]
Comment by December 19, 2011 Rick, your articles are great. Thank you! BTW: In Chapter 8 of "Handbook of DSP Engineering Applications" Academic Press 1987; F. Harris treats Scallop loss as well. (Pp648, 684)
[ - ]
Comment by December 20, 2011 Hello Shep, If you'd like a copy of a more detailed article on this topic, send me an E-mail. [R.Lyons@ieee.org]
[ - ]
Comment by December 20, 2011 And what about noise? I mean will your method work when signal is corrupted? You wrote "the flat-top window frequency-domain convolutions are most useful when the FFT spectral component being measured is well above the background spectral noise floor." It's not enough. RMS error as function of SNR would be interesting. And one more question: can one measure peak Ð°mplitude(-s) of any kind of modulated signals by means of your method?
[ - ]
Comment by December 20, 2011 Hello Mariam, My my. You ask good questions. No, I have not modeled that 'peak-amplitude estimation' scheme in the presence of noise. Maybe you could investigate that scenario and post a blog here with your results. As for that scheme's performance for modulated signals, again, sorry but I have not studied that situation. My modeling was strictly for input sinusoids whose time-domain peak amplitudes remained constant. [-Rick-]
[ - ]
Comment by December 20, 2011 To post a blog here - Ð¾ no, thank you, Rick. I'm interested in modulation recognition problem and am looking for algorithms useful in conditions of high level of uncertainty. It's difficult to find any (or I'm searching badly). Usually developers suppose there is much more information than it is in reality. Unfortunately it is impossible to understand if your method is useful. To find carrier parameters is neÑessary but it isn't the main problem so far for me. Perhaps I'l have to think later about it.
[ - ]
Comment by May 12, 2017 Ha ha. Qualitatively, noise and signal appear identical to the FFT. The ratio between noise and signal won't change the detection threshold of the FFT. So you face the same issues using the FFT to detect the signal energy as you would with any other method. You can take it from there.

[ - ]
Comment by December 28, 2011 Hello Rick, This is a great article... I've never considered the duality of convolution in the frequency domain with multiplication in the time domain to solve this problem. I'm excited to try this technique out. In the past, I've used techniques to estimate frequency (given enough SNR) and apply a correction based on the windowing function's scalloping profile. Your technique seems much simpler. For the case of multiple (additive) sources, you seem to suggest about a 12 bin separation in order to get accuracy approaching the 0.2dB above. That's not too bad of a resolution requirement for many applications. Thanks again for the post. -Mike Williamson http://www.mitydsp.com
[ - ]
Comment by May 12, 2017 Interesting. I'm presuming the use of FFT when there are more than one frequency component.

Another way to extract amplitude (peak amplitude) data is by narrow-band filtering followed by RMS detection. But ... that limits the system to a single tone.

[ - ]
Comment by May 23, 2017 Another vote of thanks to Rick. This  post helped me finish a program I've been working on.

I've stumbled on what appears to be a fairly substantial literature sometimes called "fine frequency estimation" related to interpolating dft's to get more accurate frequency estimates. Some of these also allow for refined magnitude and phase estimates as well.

The program I was working on uses the method described in :

Rick's note helped me tie down the relation between the refined magnitude estimate and the peak amplitude of  a test sinusoid. If you work with unnormalized windows (i.e.those not summing to 1.0), then the relation between magnitude and amplitude is:   M = mean(window)* 2*A/N  This seems to work quite well with recovering off-bin-center  peak amplitudes using Duda's estimator.

The above paper (and several others I've stumbled on) includes simulations at various signal to noise ratios. A useful source of references (on the frequency refinement part only) is  .

There's also a fairly big literature on detecting multiple sinusoids; a lot of it relates to sinusoidal coding of speech and music. See for    for some useful references.

 Duda, K. (2011). DFT interpolation algorithm for Kaiser-Bessel and  Dolph-Chebyshev windows. IEEE Transactions on Instrumentation and Measurement, 60(3), 784-790.

 Candan, Ç. (2015). Fine resolution frequency estimation from three DFT samples: Case of windowed data. Signal Processing114, 245–250.

 Zheng, C., & Li, X. (2012). Detection of multiple sinusoids in unknown colored noise using truncated cepstrum thresholding and local signal-to-noise-ratio. Applied Acoustics73(8), 809–816. It has a good set of references on this issue.

[ - ]
Comment by July 17, 2017 Rick,

Great paper! Very clear explanation. Thank you for sharing this.

Now I can adapt this strategy to convert a Hamming windowed  FFT bin in a flat top windowed FFT bin. Once I get some free time I will submit a paper about this adaptation to non-rectangular windows.

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.