Be the first to rate this file! 516 downloads (last 30 days) File Size: 6.06 KB File ID: #22163

EZFFT : An easy to use Power Spectrum (FFT)

by Frederic Moisy

 

19 Nov 2008 (Updated 20 Nov 2008)

Computes/displays the power spectrum of a real time series

I am interested in collaboration

Download Now | Watch this File

File Information
Description

EZFFT(T,U) plots the power spectrum of the signal U(T) , where T is a 'time' and U is a real signal (T can be considered as a space coordinate as well). If T is a scalar, then it is interpreted as the 'sampling time' of the signal U. If T is a vector, then it is interpreted as the 'time' itself. In this latter case, T must be equally spaced (as obtained by LINSPACE for instance), and it must have the same length as U. If T is not specified, then a 'sampling time' of unity (1 second for instance) is taken. Windowing (appodization) can be applied to reduce border effects (see below).  
   
[W,E] = EZFFT(T,U) returns the power spectrum E(W), where E is the energy density and W the pulsation 'omega'. W is *NOT* the frequency: the frequency is W/(2*pi). If T is considered as a space coordinate, W is a wave number (usually noted K = 2*PI/LAMBDA, where LAMBDA is a wavelength).  
   
EZFFT(..., 'Property1', 'Property2', ...) specifies the properties:  
     'hann' applies a Hann appodization window to the data (reduces aliasing).  
     'disp' displays the spectrum (by default if no output argument)  
     'freq' the frequency f is displayed instead of the pulsation omega (this applies for the display only: the output argument remains the pulsation omega, not the frequency f).  
     'space' the time series is considered as a space series. This simply renames the label 'omega' by 'k' (wave number) in the plot, but has no influence on the computation itself.  
     'handle' returns a handle H instead of [W,E] - it works only if the properties 'disp' is also specified. The handle H is useful to change the line properties (color, thickness) of the plot (see the example below).  
   
The length of the vectors W and E is N/2, where N is the length of U (this is because U is assumed to be a real signal.) If N is odd, the last point of U and T are ignored. If U is not real, only its real part is considered.  
   
        W(1) is always 0. E(1) is the energy density of the average of U (when plotted in log coordinates, the first point is W(2), E(2)).  
        W(2) is the increment of pulsation, Delta W, given by 2*PI/Tmax  
        W(end), the highest measurable pulsation, is PI/DT, where DT is the sampling time (Nyquist theorem).  
   
Parseval Theorem (Energy conservation):  
For every signal U, the 'energy' computed in the time domain and in the frequency domain are equal,  
        MEAN(U.^2) == SUM(E)*W(2)  
where W(2) is the pulsation increment Delta W.  
Note that, depending on the situation considered, the physical 'energy' is usually defined as 0.5*MEAN(U.^2). Energy conservation only applies if no appodization of the signal (windowing) is used. Otherwise, some energy is lost in the appodization, so the spectral energy is lower than the actual one.  
   
As for FFT, the execution time depends on the length of the signal. It is fastest for powers of two.  
   
    Example 1: simple display of a power spectrum  
       t = linspace(0,400,2000);  
       u = 0.2 + 0.7*sin(2*pi*t/47) + cos(2*pi*t/11);  
       ezfft(t,u);  
   
    Example 2: how to change the color of the plot  
       h = ezfft(t,u,'disp','handle');  
       set(h,'Color','red');  
   
    Example 3: how to use the output of ezfft  
       [w,e] = ezfft(t,u,'hann');  
       loglog(w,e,'b*');  

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
20 Nov 2008 help text improved

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com