-
Notifications
You must be signed in to change notification settings - Fork 0
/
ant_time_series_traits.m
79 lines (61 loc) · 2.3 KB
/
ant_time_series_traits.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
72
73
74
75
76
77
78
79
clear all; close all
cd 'C:/Users/Andrew Burchill/Documents/Side Projects/spider-ant-mimic/sync' % Set directory
dinfo = dir; %opens the directory
A = {dinfo.name}; %gets names of files in the directory
%A=sort_nat(A) %sorts them
j=1;
for m=3:length(A) %goes through every file... except three?
%figure
filed=[char(A(m))];
activityt4=csvread(filed); %reads the file
time=(1:length(activityt4))/240; %converts index to hours
%1 sec = 0.0002778 hrs
%each time pt 30 sec apart
total_time = time(length(time));
% uncomment next line to normalize time series
% activityt4=rescale(activityt4);
% plot(time,activityt4,'k','LineWidth',5)
% xlabel('Seconds')
% set(gca,'fontsize',15)
% set(gca,'linewidth',2)
% set(gca,'TickDir','out')
% set(gca, 'FontName', 'Times')
% figure;
% cwt(activityt4,seconds(1/240)); %plots the wavelet thing
% xlabel(A(m))
%gets the wavelet transform, the sampling freq in Hz, & cone of influence
[dpoaeCWT,f,coi] = cwt(activityt4,240);
%breaks apart 0-9hrs by the number of the wavelet transforms
%t(1)=0, unlike the `time` variable
t=linspace(0,total_time,length(dpoaeCWT))';
%get the lefthand unique cone of infl. values
[coil, index] = unique(coi);
%coil=x, t(index)=y, f= sampling points
YIsx1 = interp1(coil, t(index), f);
midway = floor(length(dpoaeCWT)/2)
%repeat for the righthand side. (WHY 534?)
[coir, index] = unique(coi(midway:end));
%repeat, but add 4.5 hrs to time
YIsx2 = interp1(coir, t(index)+total_time/2, f);
%for each wavelet transform (freq)
for i=1:length(f)
cfsOAE = dpoaeCWT(i,:); %get its fourier series?
q=abs(cfsOAE);
h=vertcat(cfsOAE,t'); %two row matrix, time is second row
%only get time values within/outside cone of influence
q2 = h(2,:) < YIsx1(i) | h(2,:) > YIsx2(i)
h2=h; %not sure why this is called....
q(q2) = []; %only keep the "good" values of q?
power(i)=max(q); %find the maximum value for the wt
end
[M,Y] = max(power)
period(j)=1/f(Y)
rhythmicity(j)=M
sync(j)=[(std(activityt4)).^2/mean(activityt4)]
id(j)=A(m)
power=[];
j=j+1;
end
ant_time_series=table(id',sync',rhythmicity',period')
ant_time_series.Properties.VariableNames ={'Colony' 'Synchrony' 'Rhythmicity' 'Period'}
writetable(ant_time_series)