-
Notifications
You must be signed in to change notification settings - Fork 1
/
builddictionary_1.m
executable file
·93 lines (87 loc) · 3 KB
/
builddictionary_1.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
function [ Signature, TypeNum, Sc, Tc ] = builddictionary_1( ...
stream_length, roots, step, trivial )
% use trivial under default
if nargin < 4
trivial = 0;
end
%% keep all roots the same length
scale = cellfun('length',roots);
max_scale = max(scale);
if length(roots{1}) == max_scale
root_pattern_gen = roots{1};
else
root_pattern_gen = [roots{1}; repmat(roots{1}(end,:), ...
max_scale-length(roots{1}),1)];
end
if length(roots{2}) == max_scale
root_pattern_line = roots{2};
else
root_pattern_line = [roots{2}; repmat(roots{2}(end,:), ...
max_scale-length(roots{2}),1)];
end
if length(roots{3}) == max_scale
root_pattern_load = roots{3};
else
root_pattern_load = [roots{3}; repmat(roots{3}(end,:), ...
max_scale-length(roots{3}),1)];
end
% Endmember = [root_pattern_gen(301*4+1:301*5,:), root_pattern_line(301*4+1:301*5,:), root_pattern_load(301*4+1:301*5,:)];
Endmember = [root_pattern_gen(1:301,:), root_pattern_line(1:301,:), root_pattern_load(1:301,:)];
TypeNum = [size(root_pattern_gen, 2), size(root_pattern_line, 2), ...
size(root_pattern_load, 2)];
%% build a variational dictionary
Endmember = Endmember - repmat(Endmember(1,:), size(Endmember,1), 1);
[nr,nc] = size(Endmember);
if stream_length < nr
%fprintf('stream length is smaller than signature length, mistake\n');
%error('Stream length is smaller than signature length');
Endmember = Endmember(1:stream_length, :);
else
Endmember = [Endmember; repmat(Endmember(end,:),stream_length-nr,1)];
end
Signature = [];
% shift step
% step = 2;
for i=1:nc
vectemp = Endmember(:,i);
% shift untile 15s is left
for j=1:step:(stream_length-15/0.1)
sigtemp = vectemp;
sigtemp(1:j) = sigtemp(1);
sigtemp(j:end) = vectemp(1:end-j+1);
Signature = [Signature, sigtemp];
end
end
% for i=1:nc
% vectemp = Endmember(:,i);
% for j=1:step:(stream_length-nr+1)
% sigtemp = zeros(stream_length,1);
% sigtemp(j:nr+j-1) = sigtemp(j:nr+j-1) + vectemp;
% sigtemp(nr+j:end) = vectemp(end);
% Signature = [Signature, sigtemp];
% end
% end
Sc = size(Signature,2);
%% build trivial signals
Tc = 0;
Tuple = [];
if trivial
% width of trival signal
span = 6;
for i=1:span:stream_length-span+1
sigtemp = zeros(stream_length,1);
sigtemp([i:i+(span-1)]) = 1;
Tuple = [Tuple, sigtemp];
sigtemp = -1*sigtemp;
Tuple = [Tuple, sigtemp];
end
Tc = size(Tuple,2);
end
Signature = [Signature, Tuple];
% normalization
ratio = min(1./abs(max(Signature)), 1./abs(min(Signature)));
% ratio = min(min(1./abs(max(Signature)), 1./abs(min(Signature))));
Signature = Signature * diag(ratio);
% Signature = Signature .* ratio;
%fprintf('Dictionary building finished\n');
end