-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeuristicRecastingFunctionMetSegs.m
258 lines (232 loc) · 5.91 KB
/
HeuristicRecastingFunctionMetSegs.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
function [ocSDprop,dcSDprop,sumdurs,sumdurs2,sumonsets,sumonsets2,onsets,durclusters,sumnewdurs]=HeuristicRecastingFunctionMetSegs(totalities,divs)
%totalities: include totalities or not?
%divs: how many divisions for slicing (e.g. 4 or 10)?
%close all
T = readtable('HeuristicData.csv');
if totalities==0
Told=T;
Tsize=size(T);
for i=Tsize(1):-1:1
if strcmp(char(table2array(T(i,6))),'T')==1
T(i,:)=[];
end
end
end
chapter=table2array(T(:,1))
RGsds=table2array(T(:,4))
comments=table2array(T(:,10))
ucomments=unique(comments);
for i=1:numel(RGsds)
if numel(RGsds{i})==2
RGSDsmat(i)=nan;
% if strmatch(RGsds{i},'7b')==1
% RGSDsmat(i)=4
% elseif strmatch(RGsds{i},'4#')==1
% RGSDsmat(i)=7
% end
else
RGSDsmat(i)=str2num(RGsds{i});
end
end
RGSDsmat=RGSDsmat';
match=table2array(T(:,9))
% Mean match by Scale Degree
%NOTE: MAKE CONFUSION MATRIX SCALE DEGREE BY EVERY TYPE OF IMF Position
for i=1:7
inds1{i}=find(RGSDsmat==i);
matchSDinds{i}=match(inds1{i});
meanSDs(i,1)=i;
meanSDs(i,2)=numel(inds1{i});
meanSDs(i,3)=nanmean(matchSDinds{i});
sizes(i)=length(inds1{i});
end
%Mean match by Chapter
chaps=unique(chapter);
for i=numel(chaps):-1:1
if isnan(chaps(i))==1
chaps(i)=[];
end
end
for i=1:numel(chaps)
inds2{i}=find(chapter==chaps(i))
meanchaps(i,1)=chaps(i);
meanchaps(i,2)=numel(inds2{i});
meanchaps(i,3)=nanmean(match(inds2{i}));
sizeschaps(i)=length(inds2{i});
end
% Do onsets cluster in the beginning (first quarter), middle 1 (second
% quarter), middle 2 (third quarter), or end (final quarter)?
%repeated pitches are considered a single note (e.g. like a tie)
% refers 12 segmentduration=segdurs and 13 onsetswithinsegment = onsets
segdurs=table2array(T(:,12));
% for i=1:numel(segdurs)
% temp=strsplit(segdurs{i},';')
% temp2=[];
% for j=1:numel(temp)
% temp2(end+1)=str2double(temp(j));
% end
% segdurs2(i)=[temp2];
% end
% segdurs=segdurs2;
%reinterpret chromatics
% RGSDsmatnan=RGSDsmat;
% for i=1:numel(RGSDsmat)
% if RGSDsmatnan(i)==4.4
% RGSDsmatnan(i)=7;
% elseif RGSDsmatnan(i)==6.6
% RGSDsmatnan(i)=4;
% end
% end
RGSDsmatnan=RGSDsmat;
onsets=table2array(T(:,13));
for i=1:numel(onsets)
temp=strsplit(onsets{i},';')
temp2=[];
for j=1:numel(temp)
temp2(end+1)=str2double(temp(j));
end
onsets2{i}=[temp2];
end
onsets=onsets2;
%sum all durs
sumonsets=0;
for i=1:numel(onsets)
for j=1:numel(onsets{i})
if isnan(onsets{i})==0
sumonsets=sumonsets+1;
end
end
end
%divs=4;
onsetclusters=zeros(1,divs);
onsetclustersSD=zeros(7,divs);
for i=1:numel(segdurs)
thisonset=onsets{i};
% thisonset=str2double(thisonset);
for j=1:numel(thisonset)
RGSDsmatnan(i)
i
try
for k=1:divs
if thisonset(j) < (k/divs)*segdurs(i)
onsetclusters(k)=onsetclusters(k)+1;
onsetclustersSD(RGSDsmatnan(i),k)=onsetclustersSD(RGSDsmatnan(i),k)+1;
break
end
end
catch
end
end
end
sumonsets2=sum(onsetclusters);
ocSD=onsetclustersSD;
for i=1:7
ocSDprop(i,:)=ocSD(i,:)/sum(ocSD(i,:));
end
% add proportions
for i=1:divs
ocSDfreqprop(:,i*2-1)=ocSD(:,i);
ocSDfreqprop(:,i*2)=ocSDprop(:,i);
end
%Same thing as before with durations
% refers 12 segmentduration=segdurs and 13 onsetswithinsegment = onsets and
% 14 coretone durations
%%go through and slice everything to fit within quarters
durs=table2array(T(:,14));
for i=1:numel(durs)
temp=strsplit(durs{i},';')
temp2=[];
for j=1:numel(temp)
temp2(end+1)=str2double(temp(j));
end
durs2{i}=[temp2];
end
durs=durs2;
%sum all durs
sumdurs=0;
for i=1:numel(durs)
for j=1:numel(durs{i})
if isnan(durs{i})==0
sumdurs=sumdurs+durs{i}(j);
end
end
end
sumdurs=floor(sumdurs);
%divs=4;
for i=1:numel(durs)
thisonsets=onsets{i};
%thisonsets=str2double(thisonsets);
thisdurs=durs{i};
%thisdurs=str2double(thisdurs);
qsize=segdurs(i)/divs; % quartersize
qsizes(i)=qsize;
newons=nan;
newdur=nan;
%no grid for slicing!! really hard
try
for j=1:numel(onsets{i})
dur=thisdurs(j);
ons=onsets{i}(j);
for k=divs:-1:1
if ons+dur>qsize*(k-1)
if ons<qsize*(k-1)
newons(end+1)=qsize*(k-1);
newdur(end+1)=ons+dur-(qsize*(k-1));
dur=dur-newdur(end);
else % if ons>=qsize*(k-1)
newons(end+1)=ons;
newdur(end+1)=dur;
break
end
% else % if ons+dur<=qsize*(k-1)
% newons(end+1)=ons;
% newdur(end+1)=dur;
end
end
end
newonsets{i}=newons(2:end);
newdurs{i}=newdur(2:end);
catch
newonsets{i}=nan;
newdurs{i}=nan;
end
end
sumnewdurs=0;
for i=1:numel(newdurs)
for j=1:numel(newdurs{i})
if isnan(newdurs{i})==0
sumnewdurs=sumnewdurs+newdurs{i}(j);
end
end
end
sumnewdurs=floor(sumnewdurs);
durclusters=zeros(1,divs);
durclustersSD=zeros(7,divs);
for i=1:numel(segdurs)
thisonset=newonsets{i};
for j=1:numel(thisonset)
RGSDsmatnan(i)
try
for k=1:divs
if thisonset(j) < (k/divs)*segdurs(i)
durclusters(k)=durclusters(k)+newdurs{i}(j);
durclustersSD(RGSDsmatnan(i),k)=durclustersSD(RGSDsmatnan(i),k)+newdurs{i}(j);
break
end
end
catch
end
end
end
sumdurs2=sum(durclusters);
sumdurs2=floor(sumdurs2);
dcSD=durclustersSD;
for i=1:7
dcSDprop(i,:)=dcSD(i,:)/sum(dcSD(i,:));
end
% add proportions
for i=1:divs
dcSDfreqprop(:,i*2-1)=dcSD(:,i);
dcSDfreqprop(:,i*2)=dcSDprop(:,i);
end
end