Return X coordinate of a fft plot where 80% of the total area under the curve is achieved

1 次查看(过去 30 天)
How to get X coordinate of a fft plot which covers 80% of the area of the total area covered by the whole plot.

采纳的回答

Star Strider
Star Strider 2019-4-13
Try this:
t = linspace(0, 10, 150); % Create Data
y = sin(2*pi*t*3) .* cos(2*pi*t*2) + 0.01*randn(size(t)); % Create Data
L = numel(t);
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTy = fft(y)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
areaFrac = 0.8; % Desired Fraction Of Total Area
areaTot = trapz(Fv, abs(FTy(Iv))); % Total Area
areaCum = cumtrapz(Fv, abs(FTy(Iv))); % Cumulative Integral
Fv80 = interp1(areaCum, Fv, areaTot*areaFrac, 'spline') % Frequency Corresponding To 80% Total Area
FTy80 = interp1(Fv, abs(FTy(Iv))*2, Fv80, 'spline') % Value of Fourier Transform At ‘Fv80’
figure
plot(Fv, abs(FTy(Iv))*2, '-b')
hold on
plot(Fv, areaCum, '-k')
plot([0 max(Fv)], [1 1]*areaTot, '--k')
plot([0 max(Fv)], [1 1]*areaFrac*areaTot, ':k')
plot([1 1]*Fv80, [0 FTy80], '-r')
plot(Fv80, areaTot*areaFrac, 'r+')
hold off
legend('Fourier Transform', 'Cumulative Area', 'Maximum Area', '80% Maximum Area', 'Fourier Transform at 80% Maximum Area')
Experiment to get the result you want.
  5 个评论
Star Strider
Star Strider 2019-4-13
As always, my pleasure.
I have no idea what you tweaked or what your signals are. The code appears to be correct.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parametric Spectral Estimation 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by