t = linspace(0, 10, 150);
y = sin(2*pi*t*3) .* cos(2*pi*t*2) + 0.01*randn(size(t));
L = numel(t);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
FTy = fft(y)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
areaFrac = 0.8;
areaTot = trapz(Fv, abs(FTy(Iv)));
areaCum = cumtrapz(Fv, abs(FTy(Iv)));
Fv80 = interp1(areaCum, Fv, areaTot*areaFrac, 'spline')
FTy80 = interp1(Fv, abs(FTy(Iv))*2, Fv80, 'spline')
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')
Best Answer