Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate area under FFT graph in MATLAB

Currently I did a FFT of a set of data which gives me a plot with frequency at x axis and amplitude at y axis. I would like to calculate the area under the graph to give me the energy.

I am not sure how to determinate the area because I am without the equation and also I only want a certain area of the plot rather than whole area under the plot. Is there a way I can do it?

like image 954
lytheone Avatar asked Apr 14 '10 23:04

lytheone


People also ask

How do you find the area under a graph in MATLAB?

A = integral (Fx, Xminimum, Xmaximum) will calculate the numeric integration of input function 'Fx', which in turn signifies the area under a curve. A = trapz (x, y) will also give the area under the curve represented by 'y'. Here 'x' is used to define the range or limits between which we want the area.

How do you do FFT analysis in MATLAB?

Y = fft( X ) computes the discrete Fourier transform (DFT) of X using a fast Fourier transform (FFT) algorithm. If X is a vector, then fft(X) returns the Fourier transform of the vector. If X is a matrix, then fft(X) treats the columns of X as vectors and returns the Fourier transform of each column.

What is Fftshift MATLAB?

Y = fftshift( X ) rearranges a Fourier transform X by shifting the zero-frequency component to the center of the array. If X is a vector, then fftshift swaps the left and right halves of X . If X is a matrix, then fftshift swaps the first quadrant of X with the third, and the second quadrant with the fourth.

What is the Nfft in FFT?

The non-equidistant fast Fourier transform (NFFT) is an extension of the famous fast Fourier transform (FFT), which can be applied to non-equidistantly sampled data in time/space or frequency domain.


2 Answers

There are many ways to do numerical integration 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')
like image 104
Jonas Avatar answered Sep 23 '22 07:09

Jonas


The FFT is discrete, not continuous - you just need to sum all the bin values. If you're looking at the power spectrum (magnitude squared) then the bin values are in W/Hz, so you would need to multiply each value (or alternatively just the sum), by the bin width in Hz to get power (and hence the total energy in your input sample).

like image 31
Paul R Avatar answered Sep 25 '22 07:09

Paul R