-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval_mat2.m
329 lines (314 loc) · 12.1 KB
/
eval_mat2.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
function eval_mat2()
% --------------
clc;
close all;
clear all;
per=1:20;
fs=0.2:0.2:3;
tt=5:5:100;
noise=0;
for i=1:1
switch i
case 1
str='Auto';
case 2
str='Enright';
case 3
str='DFT';
end
mat=[];
for j=1:2
f=sprintf('simulations/mat_%s_per_%d_%d_noise_%d.mat',noise,str,10*j-9,10*j,noise);
s=load(f);
mat=[mat;s.mat];
end
mat(find(mat==0))=Inf;
% Plot results obtained from simulations
plot_np(i);
%plot_nppp(i);
%plot_Z(i,str);
%plot_x_y_z_1(i,str);
%plot_hist(i,1);
%plot_x_frequency(i,1);
%plot_x_time(i,1);
end
% Plot average error percentage and number of
% non significant points over number of periods
function plot_np(i)
figure(i);
ngroups=10;
col=['b','r','g','k'];
res1=zeros(1,ngroups);
res2=zeros(1,ngroups);
for j=1:4
aux1=mat2(find((mat2(:,1)>=(j*5-4))&(mat2(:,1)<=(j*5))),:);
ind=ceil(ngroups*tiedrank(aux1(:,2))/length(aux1(:,2)));
middlep=zeros(1,ngroups);
for k=1:ngroups
aux2=aux1(find(ind==k),:);
middlep(k)=(min(aux2(:,2))+max(aux2(:,2)))/2;
aux3=min(aux2(:,4:8),[],2);
aux4=abs(aux2(:,1)-aux3)./(aux2(:,1));
res1(k)=mean(aux4(find(aux4~=Inf)));
res2(k)=length(find(aux4==Inf))./length(aux4);
end
subplot(2,4,j);
hold on;
y1=plot(middlep,res1,col(j),'LineWidth',4,'MarkerSize',4);
set(gca,'fontweight','b','fontsize',13);
xlabel('Number of periods','fontweight','b','fontsize',13);
ylabel('Average Difference Error','fontweight','b','fontsize',13);
axis([min(middlep) max(middlep) 0 1]);
set(gca,'fontweight','b','fontsize',13);
title(str,'fontweight','b','fontsize',13);
grid on;
subplot(2,4,j+4);
hold on;
y2=plot(middlep,res2,col(j),'LineWidth',4,'MarkerSize',4);
set(gca,'fontweight','b','fontsize',13);
xlabel('Number of periods','fontweight','b','fontsize',13);
ylabel('Fraction of NSP','fontweight','b','fontsize',13);
axis([min(middlep) max(middlep) 0 0.2]);
set(gca,'fontweight','b','fontsize',13);
title(str,'fontweight','b','fontsize',13);
grid on;
end
end
% Plot average error percentage and number of
% non significant points over number of points per period
function plot_nppp(i)
figure(i);
ngroups=10;
col=['b','r','g','k'];
res1=zeros(1,ngroups);
res2=zeros(1,ngroups);
for j=1:4
aux1=mat2(find((mat2(:,1)>=(j*5-4))&(mat2(:,1)<=(j*5))),:);
ind=ceil(ngroups*tiedrank(aux1(:,3))/length(aux1(:,3)));
middlep=zeros(1,ngroups);
for k=1:ngroups
aux2=aux1(find(ind==k),:);
middlep(k)=(min(aux2(:,3))+max(aux2(:,3)))/2;
aux3=min(aux2(:,4:8),[],2);
aux4=abs(aux2(:,1)-aux3)./(aux2(:,1));
res1(k)=mean(aux4(find(aux4~=Inf)));
res2(k)=length(find(aux4==Inf))./length(aux4);
end
subplot(2,4,j);
hold on;
y1=plot(middlep,res1,col(j),'LineWidth',4,'MarkerSize',4);
set(gca,'fontweight','b','fontsize',13);
xlabel('Number of points per period','fontweight','b','fontsize',13);
ylabel('Average Difference Error','fontweight','b','fontsize',13);
axis([min(middlep) max(middlep) 0 1]);
set(gca,'fontweight','b','fontsize',13);
title(str,'fontweight','b','fontsize',13);
grid on;
subplot(2,4,j+4);
hold on;
y2=plot(middlep,res2,col(j),'LineWidth',4,'MarkerSize',4);
set(gca,'fontweight','b','fontsize',13);
xlabel('Number of points per period','fontweight','b','fontsize',13);
ylabel('Fraction of NSP','fontweight','b','fontsize',13);
axis([min(middlep) max(middlep) 0 0.2]);
set(gca,'fontweight','b','fontsize',13);
title(str,'fontweight','b','fontsize',13);
grid on;
end
end
% Plot Z_1
function plot_Z(i,str)
uscmat=unique(mat2(:,2))'; % unique second column of mat
utcmat=unique(mat2(:,3))'; % unique third column of mat
Z=ones(length(per),length(fs)).*-1;
count=0;
for j=2:2:(length(tt)/2)
count=count+1;
for k=1:length(per)
for l=1:length(fs)
pos=find((mat(:,1)==per(k)) & (mat(:,2)==fs(l)) & (mat(:,3)==tt(j)));
minim=min(mat(pos,4:8),[],2);
Z(k,l)=abs(minim-mat(pos,1))./mat(pos,1);
end
end
figure(i);
subplot(2,5,count);
surf(fs,per,Z);
axis([min(fs) max(fs) min(per) max(per) 0 Inf 0 0.2]);
set(gca,'fontweight','b','FontSize',11)
view(0,90);
%shading interp;
grid on;
xlabel('SF','fontweight','b','fontsize',11);
ylabel('Period','fontweight','b','fontsize',11);
s=sprintf('TR-1:%d %s',tt(j),str);
title(s,'fontweight','b','fontsize',11);
colorbar;
set(gca,'fontweight','b','FontSize',11)
end
end
% Plot x_y_z_1
function plot_x_y_z_1(i,str)
Z=ones(length(per),length(fs)).*-1;
count=0;
for j=2:2:(length(tt)/2)
count=count+1;
for k=1:length(per)
for l=1:length(fs)
pos=find((mat(:,1)==per(k)) & (mat(:,2)==fs(l)) & (mat(:,3)==tt(j)));
minim=min(mat(pos,4:8),[],2);
Z(k,l)=abs(minim-mat(pos,1))./mat(pos,1);
end
end
figure(i);
subplot(2,5,count);
surf(fs,per,Z);
axis([min(fs) max(fs) min(per) max(per) 0 Inf 0 0.2]);
set(gca,'fontweight','b','FontSize',11)
view(0,90);
%shading interp;
grid on;
xlabel('SF','fontweight','b','fontsize',11);
ylabel('Period','fontweight','b','fontsize',11);
s=sprintf('TR-1:%d %s',tt(j),str);
title(s,'fontweight','b','fontsize',11);
colorbar;
set(gca,'fontweight','b','FontSize',11)
end
end
% Plot histogram of positions
function plot_hist(i,plt)
maxh=3; % maximum number of harmonics
res1=zeros(6,maxh);
res2=zeros(6,maxh);
for j=1:length(tt)
aux1=mat(find(mat(:,3)==tt(j)),:);
for k=1:length(fs)
aux2=aux1(find(aux1(:,2)==fs(k)),:);
for l=1:length(per)
aux3=aux2(find(aux2(:,1)==per(l)),:);
[aux4 ind1]=min(aux3(:,4:8),[],2);
if ~(aux4==Inf)
aux5=floor(tt(j)/per(l)); % number of times real period repeats
aux6=abs((1:aux5).*per(l)-(ones(1,aux5).*aux4)); % take differences to ff and harmonics
[aux7 ind2]=min(aux6,[],2); % checks where minimum occurs
if ~(ind2>maxh)
res1(ind1+1,ind2)=(res1(ind1+1,ind2)*res2(ind1+1,ind2)+(aux7/(per(l)*ind2)))/(res2(ind1+1,ind2)+1);
res2(ind1+1,ind2)=res2(ind1+1,ind2)+1;
end
else
res2(1,1)=res2(1,1)+1;
end
end
end
end
figure(plt);
subplot(3,2,2*i);
bar(1:6,res1);
ylim([0 1]);
set(gca,'fontweight','b','fontsize',13,'XTickLabel',['0';'1';'2';'3';'4';'5']);
xlabel('Position in the results vector','fontweight','b','fontsize',13);
ylabel('Average Difference Error','fontweight','b','fontsize',13);
legend('Fundamental frequency','First harmonic','Second harmonic');
grid;
title('Harmonics according to position error (20% noise)','fontweight','b','fontsize',13);
figure(plt+1);
subplot(3,2,2*i);
res2=res2./sum(sum(res2)); % normalize result matrix
bar(1:6,res2);
ylim([0 1]);
set(gca,'fontweight','b','fontsize',13,'XTickLabel',['0';'1';'2';'3';'4';'5']);
xlabel('Position in the results vector','fontweight','b','fontsize',13);
ylabel('Normalized Count','fontweight','b','fontsize',13);
legend('Fundamental frequency','First harmonic','Second harmonic');
grid;
title('Harmonics according to position count (20% noise)','fontweight','b','fontsize',13);
end
% Plot average error percentage over sampling frequency and number of
% non significant points
function plot_x_frequency(i,plt)
figure(plt);
col=['r','b','g','c','k'];
res1=zeros(1,length(fs));
res2=zeros(1,length(fs));
count=1;
for j=4:4:length(tt)
aux1=mat(find(mat(:,3)==tt(j)),:);
for k=1:length(fs)
aux2=aux1(find(aux1(:,2)==fs(k)),:);
aux3=min(aux2(:,4:8),[],2);
aux4=abs(aux2(:,1)-aux3)./(aux2(:,1));
res1(k)=mean(aux4(find(aux4~=Inf)));
res2(k)=length(find(aux4==Inf))./length(aux4);
end
subplot(3,2,2*i-1);
hold on;
y1=plot(fs,res1,col(count),'LineWidth',2,'MarkerSize',3);
subplot(3,2,2*i);
hold on;
y2=plot(fs,res2,col(count),'LineWidth',2,'MarkerSize',3);
count=count+1;
end
subplot(3,2,2*i-1);
set(gca,'FontSize',14);
xlabel('Sampling Frequency','fontweight','b','fontsize',13);
ylabel('Average Error','fontweight','b','fontsize',13);
axis([min(fs) max(fs) 0 3]);
set(gca,'fontweight','b','fontsize',13);
legend('TR-1:20','TR-1:40','TR-1:60','TR-1:80','TR-1:100');
title(str);
grid on;
subplot(3,2,2*i);
set(gca,'FontSize',14);
xlabel('Sampling Frequency','fontweight','b','fontsize',13);
ylabel('Fraction of NSP','fontweight','b','fontsize',13);
axis([min(fs) max(fs) 0 1]);
set(gca,'fontweight','b','fontsize',13);
legend('TR-1:20','TR-1:40','TR-1:60','TR-1:80','TR-1:100');
title(str,'fontweight','b','fontsize',13);
grid on;
end
% Plot average error percentage over time and number of non significant points
function plot_x_time(i,plt)
figure(plt);
col=['b','g','r','c','m','y','k'];
res1=zeros(1,length(tt));
res2=zeros(1,length(tt));
count=0;
for j=2:2:15
count=count+1;
aux1=mat(find(mat(:,2)==fs(j)),:);
for k=1:length(tt)
aux2=aux1(find(aux1(:,3)==tt(k)),:);
aux3=min(aux2(:,4:8),[],2);
aux4=abs(aux2(:,1)-aux3)./(aux2(:,1));
res1(k)=mean(aux4(find(aux4~=Inf)));
res2(k)=length(find(aux4==Inf))./length(aux4);
end
subplot(3,2,2*i-1);
hold on;
y1=plot(tt,res1,col(count),'LineWidth',2,'MarkerSize',2);
subplot(3,2,2*i);
hold on;
y2=plot(tt,res2,col(count),'LineWidth',2,'MarkerSize',2);
end
subplot(3,2,2*i-1);
set(gca,'FontSize',14);
xlabel('Time Range','fontweight','b','fontsize',13);
ylabel('Average Error','fontweight','b','fontsize',13);
axis([min(tt) max(tt) 0 2]);
set(gca,'fontweight','b','fontsize',13);
legend(num2str(fs(2:2:15)'));
title(str);
grid on;
subplot(3,2,2*i);
set(gca,'fontweight','b','fontsize',13);
xlabel('Time Range','fontweight','b','fontsize',13);
ylabel('Fraction of NSP','fontweight','b','fontsize',13);
axis([min(tt) max(tt) 0 1]);
set(gca,'fontweight','b','fontsize',13);
legend(num2str(fs(2:2:15)'));
title(str);
grid on;
end
end