Calculate the area under the FFT plot in MATLAB

Currently, I have made an FFT dataset that gives me a graph with frequency along the x axis and amplitude along the y axis. I would like to calculate the area under the graph to give me energy.

I am not sure how to determine the area, because I am without an equation, and I also want only a certain area of ​​the plot, and not the entire area for the plot. Is there a way I can do this?

+5
source share
2 answers

There are many ways to integrate numerically with Matlab. Here is an example:

%# create some data
x = linspace(0,pi/2,100); %# 100 equally spaced points between 0 and pi/2
y = sin(x);

%# integrate using trapz, which calculates the area in the trapezoid defined by 
%# x(k),x(k+1),y(k),y(k+1) for k=1:length(x)
integral = trapz(x,y);

%# if you only want to integrate part of the data, do
partialIntegral = trapz(x(10:20),y(10:20));

%# show the integrated area
figure, 
area(x,y); 
hold on, 
area(x(10:20),y(10:20),'FaceColor','red')
+11
source

, - . ( ), /, (, , ) , ( , ).

+3

All Articles