|
a |
|
b/featurebased-approach/subfunctions/lib/DFA/DFA.m |
|
|
1 |
function output1=DFA(DATA,win_length,order) |
|
|
2 |
%Copyright (c) 2009, Guan Wenye |
|
|
3 |
%All rights reserved. |
|
|
4 |
% |
|
|
5 |
%Redistribution and use in source and binary forms, with or without |
|
|
6 |
%modification, are permitted provided that the following conditions are |
|
|
7 |
%met: |
|
|
8 |
% |
|
|
9 |
% * Redistributions of source code must retain the above copyright |
|
|
10 |
% notice, this list of conditions and the following disclaimer. |
|
|
11 |
% * Redistributions in binary form must reproduce the above copyright |
|
|
12 |
% notice, this list of conditions and the following disclaimer in |
|
|
13 |
% the documentation and/or other materials provided with the distribution |
|
|
14 |
% |
|
|
15 |
%THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
|
16 |
%AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
17 |
%IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
18 |
%ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
|
19 |
%LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
|
20 |
%CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
|
21 |
%SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
|
22 |
%INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
|
23 |
%CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
|
24 |
%ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
|
25 |
%POSSIBILITY OF SUCH DAMAGE. |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
N=length(DATA); |
|
|
31 |
n=floor(N/win_length); |
|
|
32 |
N1=n*win_length; |
|
|
33 |
y=zeros(N1,1); |
|
|
34 |
Yn=zeros(N1,1); |
|
|
35 |
|
|
|
36 |
fitcoef=zeros(n,order+1); |
|
|
37 |
mean1=mean(DATA(1:N1)); |
|
|
38 |
for i=1:N1 |
|
|
39 |
|
|
|
40 |
y(i)=sum(DATA(1:i)-mean1); |
|
|
41 |
end |
|
|
42 |
y=y'; |
|
|
43 |
for j=1:n |
|
|
44 |
fitcoef(j,:)=polyfit(1:win_length,y(((j-1)*win_length+1):j*win_length),order); |
|
|
45 |
end |
|
|
46 |
|
|
|
47 |
for j=1:n |
|
|
48 |
Yn(((j-1)*win_length+1):j*win_length)=polyval(fitcoef(j,:),1:win_length); |
|
|
49 |
end |
|
|
50 |
|
|
|
51 |
sum1=sum((y'-Yn).^2)/N1; |
|
|
52 |
sum1=sqrt(sum1); |
|
|
53 |
output1=sum1; |
|
|
54 |
|