Spectral Medium, Edge and Dominant Frequency Functions

Grant McAuley gmcauley at LLU.EDU
Fri Mar 16 17:46:09 CET 2007


Thanks Christian,

This is very helpful.  I did not know about the 'cumsum' function - it
makes this almost trivial.

~ Grant


On Wed, 2007-03-14 at 22:39 +0100, Christian Hesse wrote:
> Hi Grant,
>
>
> > Pardon me if I missed it, but are there functions in FT for
> > computing Spectral Edge, Medium and Dominant Frequency for a data
> > trial?
> >
> >
> > If not, perhaps someone knows of an implementation of such
> > algorithms somewhere else?
>
>
> As far as I am aware, there are no direct functions in Fieldtrip for
> extracting these measures from power spectra (since this sort of
> approach to spectral analysis is a tad more reductionist that is
> useful for most FT purposes). There is also nothing in the Signal
> Processing Toolbox, since this has mainly to do with spectral
> estimation as such, filter design, prediction, etc ...
>
>
> However, computing these measures is quite straightforward in matlab
> assuming you have the power spectum of the data (The matlab help for
> FFT tells you how to compute the power spectrum in a few simple lines,
> which you can turn into your own function). The following is only
> pseudo/outline code for a little function to get median, spectral edge
> and dominant frequencies:
>
>
>
>
> function [mf, sef, df] = specstats(freq, pyy)
> % your frequency axis is freq (a vector)
> % your power spectrum is pyy (a vector)
>
>
> % normalize spectrum to get a density
> pyy_norm = pyy./sum(pyy);
>
>
> % compute cumulative density
> pyy_cum = cumsum(pyy_norm);
>
>
> % median frequency corresponds to the frequency at (nearest to)
> % the point on the freq axis where pyy_cum = 0.5
> [val, idx] = min(abs(pyy_cum-0.5));
> mf = freq(idx);
>
>
> % spectral edge frequency corresponds to the frequency at (nearest to)
> % the point on the freq axis where pyy_cum = 0.05
> [val, idx] = min(abs(pyy_cum-0.05));
> sef = freq(idx);
>
>
> % you can extend this code for dominant frequency accordingly ... if
> all you mean
> % is the peak frequency then you have
> [val, idx] = max(pyy);
> df = freq(idx);
>
>
>
>
> Depending on how sophisticated you want to get you can apply a bit of
> interpolation to pyy as well, but that is probably overkill.
>
>
>
>
> I hope that helps
> Christian
>
>
>
> ----------------------------------------------------------------------
> Christian Hesse, PhD, MIEEE
>
>
> F.C. Donders Centre for Cognitive Neuroimaging
> P.O. Box 9101
> NL-6500 HB Nijmegen
> The Netherlands
>
>
> Tel.: +31 (0)24 36 68293
> Fax: +31 (0)24 36 10989
>
>
> Email: c.hesse at fcdonders.ru.nl
> Web: www.fcdonders.ru.nl
> ----------------------------------------------------------------------
>
>
>
>
>
>
>
>
--
Grant McAuley
Research Affairs IS Support
Loma Linda University
909-558-1000 Ext 87750
gmcauley at llu.edu



More information about the fieldtrip mailing list