在MATLAB中计算FFT图下的面积

lyt*_*one 5 matlab plot fft area

目前我对一组数据进行了FFT,这给出了一个频率为x轴,幅度为y轴的图.我想计算图下的面积给我能量.

我不确定如何确定该区域因为我没有方程式而且我只想要一个区域的情节而不是整个区域的情节.有没有办法可以做到?

Jon*_*nas 10

有许多方法可以与Matlab进行数值积分.这是一个例子:

%# 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')
Run Code Online (Sandbox Code Playgroud)