|
a |
|
b/Supporting Functions/MedianFrequency.m |
|
|
1 |
function [MedFreq,errormsg] = MedianFrequency(xV,leftcutoff,rightcutoff) |
|
|
2 |
% [MedFreq,errormsg] = MedianFrequency(xV,leftcutoff,rightcutoff) |
|
|
3 |
% MEDIANFREQUENCY computes the median frequency in a frequency range given |
|
|
4 |
% by 'leftcutoff' and 'rightcuroff' for a given time series 'xV'. |
|
|
5 |
% The standard periodogram is called to compute the power spectrum assuming |
|
|
6 |
% frequency=1, so that the largest frequency the power spectrum is computed |
|
|
7 |
% for is 0.5 if 'rightcuroff' is specified. The lower frequency is given |
|
|
8 |
% by 'leftcutoff' or 0 if 'leftcutoff' is not specified. The frequency |
|
|
9 |
% resolution is given by the length of the time series. |
|
|
10 |
% INPUT |
|
|
11 |
% - xV : the given time series |
|
|
12 |
% - leftcutoff: the left cutoff of frequency (to avoid the effect of drifts |
|
|
13 |
% in the signal). |
|
|
14 |
% - rightcutoff: the right cutoff of frequency (to avoid the effect of |
|
|
15 |
% high frequency elements in the signal). |
|
|
16 |
% OUTPUT |
|
|
17 |
% - MedFreq : The median frequency |
|
|
18 |
% - errormsg: a string of error message in case output cannot be generated. |
|
|
19 |
%======================================================================== |
|
|
20 |
% <MedianFrequency.m>, v 1.0 2010/02/11 22:09:14 Kugiumtzis & Tsimpiris |
|
|
21 |
% This is part of the MATS-Toolkit http://eeganalysis.web.auth.gr/ |
|
|
22 |
|
|
|
23 |
%======================================================================== |
|
|
24 |
% Copyright (C) 2010 by Dimitris Kugiumtzis and Alkiviadis Tsimpiris |
|
|
25 |
% <dkugiu@gen.auth.gr> |
|
|
26 |
|
|
|
27 |
%======================================================================== |
|
|
28 |
% Version: 1.0 |
|
|
29 |
|
|
|
30 |
% LICENSE: |
|
|
31 |
% This program is free software; you can redistribute it and/or modify |
|
|
32 |
% it under the terms of the GNU General Public License as published by |
|
|
33 |
% the Free Software Foundation; either version 3 of the License, or |
|
|
34 |
% any later version. |
|
|
35 |
% |
|
|
36 |
% This program is distributed in the hope that it will be useful, |
|
|
37 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
38 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
39 |
% GNU General Public License for more details. |
|
|
40 |
% |
|
|
41 |
% You should have received a copy of the GNU General Public License |
|
|
42 |
% along with this program. If not, see http://www.gnu.org/licenses/>. |
|
|
43 |
|
|
|
44 |
%========================================================================= |
|
|
45 |
% Reference : D. Kugiumtzis and A. Tsimpiris, "Measures of Analysis of Time Series (MATS): |
|
|
46 |
% A Matlab Toolkit for Computation of Multiple Measures on Time Series Data Bases", |
|
|
47 |
% Journal of Statistical Software, in press, 2010 |
|
|
48 |
|
|
|
49 |
% Link : http://eeganalysis.web.auth.gr/ |
|
|
50 |
%========================================================================= |
|
|
51 |
if nargin==2 |
|
|
52 |
rightcutoff = 0.5; |
|
|
53 |
elseif nargin==1 |
|
|
54 |
rightcutoff = 0.5; |
|
|
55 |
leftcutoff = 0.0; |
|
|
56 |
end |
|
|
57 |
errormsg = []; |
|
|
58 |
[psV,freqV]=periodogram(xV); |
|
|
59 |
MedFreq = []; |
|
|
60 |
if length((find(isnan(psV))))==0 |
|
|
61 |
d=length(psV(find(freqV<leftcutoff))); |
|
|
62 |
op=find(cumsum(psV(find(freqV>=leftcutoff)))>0.5*sum(psV(find(freqV>=leftcutoff & freqV<=rightcutoff)))); |
|
|
63 |
if length(op)>0 |
|
|
64 |
MedFreq=freqV(op(1)+d); |
|
|
65 |
end |
|
|
66 |
else |
|
|
67 |
errormsg = 'The periodogram could not be computed or cutoff values are not proper.'; |
|
|
68 |
end |