Question
I have been working on code to use the FFT to find the amplitude of a signal. However, despite my best efforts to window I seem to get incorrect amplitudes. When I manually find Amplitude by inspecting the signal I get A = 63.7. When I use the following code I get A = 54.8. This is causing significant errors in my Bode plot. I tried using a flat top window to maximize amplitude accuracy. My signal does not seem significantly noisy. I expected an amplitude much closer to the true value. function Amplitude = Gaindb(x) if size(x, 2) > 1 x = x'; end x = x - mean(x); N = length(x); win = flattopwin(N); x = fft(x.*flattopwin(N)); Amplitude = 2*max(abs(x))/N; end
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 25, 2026
When I run your code I get 14.5 for the answer, so I am not sure how you are getting 54.8. But the 14.5 is consistent with the Matlab definition of the flattop window. From the documentation, the flattop is a sum of cosines with certain coefficients, along with a constant coefficient a0 = .216. a0, the area of the window, is basically the amplitude reduction factor for the signal.
Without any windowing of x, the fft comes up with a signal amplitude of 67.1, and 67.1 x .216 = 14.5 which is consistent.
The Matlab window peaks out at a value of 1.
Wikipedia has an example a flattop window from SRS that multiplies all the coefficients by 4.639, so the window peaks out at that value and a0 = 1. For a continuous sinusoidal signal such as yours the resulting amplitude will be basically unchanged.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →