forked from kndiaye/matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detrend2.m
65 lines (55 loc) · 1.54 KB
/
detrend2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function [X]=detrend2(X,o,i,d)
% detrend2 - polynomial detrending
% Y = detrend2(X,o,i,d) removes trends in data
%
% X: input data array
% o: order of the fitted polynom (default 1, i.e. linear detrending)
% i: indices of the control points (default: [], i.e. all points)
% d: dimension to work on (default: 1)
% See also: detrend
% Author: K. N'Diaye (kndiaye01<at>yahoo.fr)
% Copyright (C) 2010
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version: http://www.gnu.org/copyleft/gpl.html
%
% ----------------------------- Script History ---------------------------------
% KND 2010-04-21 Creation
%
% ----------------------------- Script History ---------------------------------
if nargin < 2
o = 1;
end
if nargin < 3
i = [];
end
if nargin < 2
d = 1;
end
nd = ndims(X);
if d>nd
error(sprintf('X has only %d dimensions', nd));
end
sx = size(X);
if o==0
r = ones(1,nd);
r(d) = sx(d);
S.type='()';
S.subs = repmat({':'},1,nd);
S.subs{d} = i;
X = X - repmat(mean(subsref(X,S),d),r);
return
end
error
% polynomial adjustment
%---------------------------------------------------------------------------
G = [];
for i = 0:p
d = [1:m].^i;
G = [G d(:)];
end
y = x - G*(pinv(G)*x);
% detrend - remove linear trend
% addpath('/pclxserver2/home/ndiaye/mtoolbox/spm2')
% F=spm_detrend(F',1)';