-
Notifications
You must be signed in to change notification settings - Fork 1
/
activity.m
178 lines (152 loc) · 6.02 KB
/
activity.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function af = activity(soundfile,varargin)
af=zeros(1,5);
if ~isempty(varargin);
if strcmp(varargin{1},'plot');
doplots = 1;
else strcmp(varargin{1},'noplot')||strcmp(varargin{1},'noplot');
doplots = 0;
end
else
doplots = 1;
end
%% RMS
soundfile = miraudio(soundfile);
disp('Computing RMS')
% RMS
rm = get(mirrms(soundfile,'Frame',.046,.5),'Data');
rmdata = rm{1}{1};
meanrmdata = mean(rmdata);
breakpoint = .0559;
contribution = .0337/.6664;
af(1) = (meanrmdata-breakpoint)/contribution;
if doplots
% Use this later as it can save a tad on computation.
numframes = length(rmdata);
subplot(3,2,1)
plot(rmdata,'r--','LineWidth',1)
hold on
lenrmdata = length(rmdata);
plot([0 lenrmdata], repmat(meanrmdata,1,2), 'b--','LineWidth',3); % plot the horizontal line
plot([0 lenrmdata], repmat(breakpoint,1,2), 'k--'); % plot the horizontal line
title('RMS Activity Contribution')
text(lenrmdata/20,breakpoint,'+/- 0','FontWeight','Bold','BackgroundColor',[1 1 1])
text(lenrmdata/20,meanrmdata, num2str(round(af(1)*100)/100),'FontWeight','Bold','BackgroundColor',[1 1 1])
legend('RMS','Mean RMS')
xlabel('Frame')
hold off
end
%% Maximum Value of the Summarized Fluctuation
disp('Computing Fluctuation')
fl = mirfluctuation(soundfile,'Summary');
fldata = get(fl,'Data');
flpos = get(fl,'Pos');
peak = mirpeaks(fl,'Total',1);
peakdata = get(peak,'PeakVal');
peakpos = get(peak,'PeakPosUnit');
breakpoint = 13270.1836;
contribution = 10790.655/.6099;
af(2) = (peakdata{1}{1}{1}-breakpoint)/contribution;
if doplots
subplot(3,2,3)
plot(flpos{1}{1},fldata{1}{1})
hold on
plot(peakpos{1}{1}{1},peakdata{1}{1}{1}, 'rx','MarkerSize',15,'LineWidth',3)
plot([0 10], repmat(breakpoint,1,2), 'k--'); % plot the horizontal line
plot([0 10], repmat(breakpoint+contribution,1,2), 'k:'); % plot the horizontal line
text(max(peakpos{1}{1}{1})/20,breakpoint,'+/- 0','FontWeight','Bold','BackgroundColor',[1 1 1])
text(max(peakpos{1}{1}{1})/20,breakpoint+contribution,'+ 1','FontWeight','Bold','BackgroundColor',[1 1 1])
text(peakpos{1}{1}{1}+0.3,peakdata{1}{1}{1},num2str(round(af(2)*100)/100),'FontWeight','Bold','BackgroundColor',[1 1 1])
title('Summarized Flucutation Valence Contribution')
xlabel('Frequency (Hz)')
hold off
end
%% Spectral Centroid
disp('Computing Centroid')
s = mirspectrum(soundfile,'Frame',0.046,0.5);
sc = get(mircentroid(s),'Data');
scdata = cell2mat(sc{1}{1});
meanscdata = mean(scdata);
breakpoint = 1677.7;
contribution = 570.34/.4486;
af(3) = (mean(scdata)-breakpoint)/contribution;
if doplots
subplot(3,2,5)
plot(scdata,'r--','LineWidth',1)
lenscdata = length(scdata);
hold on
title('Spectral Centroid Activity Contribution')
plot([0 lenscdata], repmat(meanscdata,1,2), '--','LineWidth',3); % plot the horizontal line
plot([0 lenscdata], repmat(breakpoint,1,2), 'k--'); % plot the horizontal line
text(lenscdata/20,breakpoint,'+/- 0','FontWeight','Bold','BackgroundColor',[1 1 1])
text(lenscdata/20,meanscdata,num2str(round(af(3)*100)/100),'FontWeight','Bold','BackgroundColor',[1 1 1])
legend('Spectral Centroid','Mean')
xlabel('Frame')
ylabel('Frequency')
hold off
end
%% Spectral Spread
disp('Computing Spread')
ss = get(mirspread(s),'Data');
ssdata = cell2mat(ss{1}{1});
meanssdata=mean(ssdata);
breakpoint = 250.5574;
contribution = 205.3147/(-.4639);
af(4) = (meanssdata - breakpoint)/contribution;
if doplots
subplot(3,2,4)
plot(ssdata,'r--','LineWidth',1)
lenssdata=length(ssdata);
hold on
title('Spectral Spread Activity Contribution')
plot([0 lenssdata], repmat(meanssdata,1,2), '--','LineWidth',3); % plot the horizontal line
plot([0 lenssdata], repmat(breakpoint,1,2), 'k--'); % plot the horizontal line
%plot([0 lenssdata], repmat(breakpoint+contribution,1,2), 'k:','LineWidth',1); % plot the horizontal line
text(lenssdata/20,breakpoint,'+/- 0','FontWeight','Bold','BackgroundColor',[1 1 1])
%text(lenssdata)/20,breakpoint+contribution,' + 1','FontWeight','Bold','BackgroundColor',[1 1 1])
text(lenssdata/20,meanssdata,num2str(round(af(4)*100)/100),'FontWeight','Bold','BackgroundColor',[1 1 1])
legend('Spread','Mean')
xlabel('Frame')
ylabel('Frequency')
hold off
end
%% Spectral Entropy
disp('Computing Entropy')
se = get(mirentropy(mirspectrum(soundfile,'Collapsed','Min',40,'Smooth',70,'Frame',1.5,0.5)),'Data');
sedata = se{1}{1};
meansedata=mean(sedata);
breakpoint = 0.954;
contribution = 0.0258/(0.7056);
af(5) = (meansedata - breakpoint)/contribution;
if doplots
subplot(3,2,6)
plot(sedata,'r--','LineWidth',1)
lensedata=length(sedata);
hold on
title('Spectral Entropy Activity Contribution')
plot([0 lensedata], repmat(meansedata,1,2), '--','LineWidth',3); % plot the horizontal line
plot([0 lensedata], repmat(breakpoint,1,2), 'k--'); % plot the horizontal line
%plot([0 lenssdata], repmat(breakpoint+contribution,1,2), 'k:','LineWidth',1); % plot the horizontal line
text(lensedata/20,breakpoint,'+/- 0','FontWeight','Bold','BackgroundColor',[1 1 1])
%text(lenssdata)/20,breakpoint+contribution,' + 1','FontWeight','Bold','BackgroundColor',[1 1 1])
text(lensedata/20,meansedata,num2str(round(af(5)*100)/100),'FontWeight','Bold','BackgroundColor',[1 1 1])
legend('Entropy','Mean')
xlabel('Frame')
hold off
end
%% Bar Graph Summary
if doplots
subplot(3,2,2)
factors = {'RMS', 'MaxFluc', 'Centroid', 'Spread', 'Entropy'};
bar(af)
hold on
plot([0 6], 2, 'k:','LineWidth',1); % plot the horizontal line
plot([0 6], -2, 'k:','LineWidth',1); % plot the horizontal line
colormap(cool)
title(strcat('Activity = ',num2str(round((5.4861+sum(af))*100)/100)),'FontSize', 14,...
'FontWeight','Bold','HorizontalAlignment','center','BackgroundColor',[1 1 1])
%text(2.6,2.2,strcat('Activity = ',num2str(round((5.4861+sum(af))*100)/100)),'BackgroundColor',[1 1 1])
text(1/6,0,'+ 5.49','BackgroundColor',[1 1 1])
set(gca,'XTickLabel',factors)
hold off
end
end