-
Notifications
You must be signed in to change notification settings - Fork 0
/
approx_entropy.m
72 lines (48 loc) · 2.2 KB
/
approx_entropy.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
66
67
68
69
70
71
function [apen] = approx_entropy(n,r,a)
%% Code for computing approximate entropy for a time series: Approximate
% Entropy is a measure of complexity. It quantifies the unpredictability of
% fluctuations in a time series
% To run this function- type: approx_entropy('window length','similarity measure','data set')
% i.e approx_entropy(5,0.5,a)
% window length= length of the window, which should be considered in each iteration
% similarity measure = measure of distance between the elements
% data set = data vector
% small values of apen (approx entropy) means data is predictable, whereas
% higher values mean that data is unpredictable
% concept boorowed from http://www.physionet.org/physiotools/ApEn/
% Author: Avinash Parnandi, parnandi@usc.edu, http://robotics.usc.edu/~parnandi/
%%
data =a;
for m=n:n+1; % run it twice, with window size differing by 1
set = 0;
count = 0;
counter = 0;
window_correlation = zeros(1,(length(data)-m+1));
for i=1:(length(data))-m+1,
current_window = data(i:i+m-1); % current window stores the sequence to be compared with other sequences
for j=1:length(data)-m+1,
sliding_window = data(j:j+m-1); % get a window for comparision with the current_window
% compare two windows, element by element
% can also use some kind of norm measure; that will perform better
for k=1:m,
if((abs(current_window(k)-sliding_window(k))>r) && set == 0)
set = 1; % i.e. the difference between the two sequence is greater than the given value
end
end
if(set==0)
count = count+1; % this measures how many sliding_windows are similar to the current_window
end
set = 0; % reseting 'set'
end
counter(i)=count/(length(data)-m+1); % we need the number of similar windows for every cuurent_window
count=0;
i;
end % for i=1:(length(data))-m+1, ends here
counter; % this tells how many similar windows are present for each window of length m
%total_similar_windows = sum(counter);
%window_correlation = counter/(length(data)-m+1);
correlation(m-n+1) = ((sum(counter))/(length(data)-m+1));
end % for m=n:n+1; % run it twice
correlation(1);
correlation(2);
apen = log(correlation(1)/correlation(2));