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

조회 수: 3 (최근 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
Samyak Mohapatra
Samyak Mohapatra 2019년 4월 13일
I think I am getting the right answer with my latest tweak. Thank you.
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에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by