Spectral Medium, Edge and Dominant Frequency Functions

Christian Hesse c.hesse at FCDONDERS.RU.NL
Wed Mar 14 22:39:08 CET 2007

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 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20070314/ccb6e9e3/attachment-0002.html>

More information about the fieldtrip mailing list