-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigure4f.m
More file actions
137 lines (113 loc) · 4.27 KB
/
Figure4f.m
File metadata and controls
137 lines (113 loc) · 4.27 KB
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
clear all;
close all;
%% Path
addpath(fullfile('Romberg_noiselet','Measurements'));
addpath(fullfile('Romberg_noiselet','Optimization'));
addpath(fullfile('Romberg_noiselet','Utils'));
%% Size Specifications
M = 40; % length of h
J = 10; % Number of frames
it = 80;
success_freq = zeros(it/2,15);
for N = 1:1:15 % number of signals
ehP = zeros(it/2,J);
for IT = 2:2:it
K = IT; % length of signal expansion coefficents
Q = 1.5*K; % length of signals
L = 3*(K+M); % length of ffts L >= max(Q,M)
for num = 1:J
%% Synthetic Signals
m = cell(N,1);
for n = 1:N
m{n} = randn(K,1);
end
h = randn(M,1);
%% General functions
Nfft = @(x) (1/sqrt(L))*fft(x,L); %Normalized fft
Nifft = @(x) sqrt(L)*ifft(x,L);
%% Generating Coding Matrices C
EE = cell(N,1);
d = cell(N,1);
for n = 1:N
idx = randperm(Q);
% idx = 1:L;
idx = idx(1:K);
I = eye(Q);
EE{n} = I(:,idx); % Array of N matrices each of size L x K
d{n} = randsample([-1,1],Q,'true')';
end
CC = @(x,n) sqrt(L)*Nfft(d{n}.*(dct(EE{n}*x,Q)));
CCT = @(x,n) sqrt(L)*(EE{n}'*idct(d{n}.*(eye(Q,L)*Nifft(x))));
%% Implicit funtions for the action of B and B'
BB = @(h) Nfft(h);
BBT = @(w) speye(M,L)*Nifft(w);
%% Measurements
y = cell(N,1);
for n = 1:N
y{n} = BB(h).*CC(m{n},n);
end
%% Initialization
% Generate matrix Bhat
BB_exp = Nfft(eye(L,M));
% Generate matrix Chat
CC_exp = cell(N,1);
for n = 1:N
for i = 1:K
CC_exp{n}(:,i) = sqrt(L)*Nfft(d{n}.*dct(EE{n}(:,i),Q));
end
end
XX = adjcA1d(y,BB_exp,CC_exp,N); % initialized value
Xhat = concat1d(XX,N,K);
[h0,s,m0] = svds(Xhat,1);
h0 = sqrt(s)*h0; m0 = sqrt(s)*m0; %initial value for Gradient Descent
%% split
split = @(x,n) x((n-1)*K+1:n*K);
%% Gradient Descent
maxIter = 5000;
tau0 = 30;
mu = @(t) min(1-exp(-t/tau0), 0.2);
yi = cell(N,1);
mm = cell(N,1);
gradhh = zeros(M,1);
gradmm = cell(N,1);
for n = 1:N
mm{n} = split(m0,n);
end
hh = h0;
mF = transpose(concat1d(cellfun(@transpose,m,'UniformOutput',false),N,K));
error_m = zeros(maxIter,1);
error_h = zeros(maxIter,1);
for i = 1:maxIter
gradhh = zeros(M,1);
for n = 1:N
xx = CC(mm{n},n);
ww = BB(hh);
yi{n} = ww.*xx;
gradhh = gradhh + BBT((yi{n}-y{n}).*conj(xx));
gradmm{n} = CCT((yi{n}-y{n}).*conj(ww),n);
mm{n} = mm{n} - mu(i)*gradmm{n}/s;
end
hh = hh - mu(i)*gradhh/s;
mmF = transpose(concat1d(cellfun(@transpose,mm,'UniformOutput',false),N,K));
error_m(i) = norm(abs(mmF/norm(mmF))-abs(mF/norm(mF)));
error_h(i) = norm(abs(hh/norm(hh))-abs(h/norm(h)));
end
%% Quantize Recovery Error
xEst = cell(N,1);
xApp = cell(N,1);
for n = 1:N
xEst{n} = abs(Nifft(CC(mm{n},n))/sqrt(L));
xApp{n} = abs(Nifft(CC(m{n},n))/sqrt(L));
end
mmF = transpose(concat1d(cellfun(@transpose,mm,'UniformOutput',false),N,K));
ehm1 = norm(abs(hh*mmF'/norm(hh*mmF','fro'))-abs(h*mF'/norm(h*mF','fro')),'fro');
if ehm1 <= 0.001
ehP(IT/2,num) = ehP(IT/2,num) + 1;
else
ehP(IT/2,num) = ehP(IT/2,num) + 0;
end
end
end
success_freq(:,N) = sum(ehP,2)/J;
end
imagesc(flipud(success_freq)), colormap(gray), colorbar;