-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcochannel_approxfg_gmm.m
412 lines (307 loc) · 13.5 KB
/
cochannel_approxfg_gmm.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
function [ b1_est, b2_est, sig_stop, sig_nan] = cochannel_approxfg_gmm( r, sys, user, Xconst_fctr, h1, h2, gmm, fg1_ind, fg2_ind, x1_fg_ind, x2_fg_ind, b1_fg_ind, b2_fg_ind )
%COCHANNEL_APPROXFG_GMM Factor graph and message passing for cochannel
%detection using the approximate MAP FG method.
% Joint detection of 2 co-channel signals
% GMM noise model (2 mixture components)
%
% Created: Thursday Aug 27, 2015
% Modified: Friday Aug 28, 2015
% verbose option
% Modified: Monday Sept 7, 2015
% inherited from "cochannel_approxfg.m"
% Modified: Wednesday Sept 23, 2015
% improved variable updates in fw/bw pass
% Modified: Thursday Oct 1, 2015
% corrections to message passing
% Modified: Saturday Oct 17, 2015
% handled case in which NaNs result from detector
% Modified: Sunday Oct 18, 2015
% debugging/corrections
% Modified: Saturday Nov 14, 2015
% tracking iterations run
% Modified: Tuesday May 3, 2016
% added damping option for message updates (factor to var)
%
if isfield(sys,'v')==0, sys.v=0; end
if isfield(sys,'eta')==0, sys.eta=0; end
% Initialize FG symbol variables for detection
x_u1_initialize.M = user(1).M;
x_u1_initialize.dom = user(1).constellation;
x_u1_initialize.n = ones(x_u1_initialize.M,1)/x_u1_initialize.M;
x_u1_initialize.m = ones(x_u1_initialize.M,1)/x_u1_initialize.M;
x_u1_initialize.mu = 0;
x_u1_initialize.sigmasqrd = 1;
x_u2_initialize.M = user(2).M;
x_u2_initialize.dom = user(2).constellation;
x_u2_initialize.n = ones(x_u2_initialize.M,1)/x_u2_initialize.M;
x_u2_initialize.m = ones(x_u2_initialize.M,1)/x_u2_initialize.M;
x_u2_initialize.mu = 0;
x_u2_initialize.sigmasqrd = 1;
X_u1(1:sys.frameLen,1:sys.numSymbols) = x_u1_initialize;
x_u1_demod(1:sys.numSymbols,1) = x_u1_initialize;
X_u2(1:sys.frameLen,1:sys.numSymbols) = x_u2_initialize;
x_u2_demod(1:sys.numSymbols,1) = x_u2_initialize;
% Initialize demodulation and decoding FGs
fg1_ind.initialize();
fg2_ind.initialize();
% Results variables
b1_est = zeros(user(1).numBits,sys.numIter);
b2_est = zeros(user(2).numBits,sys.numIter);
sig_stop = zeros(2,1);
sig_nan = 0;
% Flags to signify completing a user (when beliefs are VERY confident)
u1_flag = 0;
u2_flag = 0;
% -------------------------------------------------------------------------
% Run APPROX MAP FG for joint detection
% -------------------------------------------------------------------------
for w=1:sys.numIter
% Detector iterations
for z=1:sys.numDetectIter
% Forward pass
for i=1:sys.frameLen
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u1(i,ii) = variable_detect_single( [X_u1(II,ii); x_u1_demod(ii)], X_u1(i,ii) );
X_u2(i,ii) = variable_detect_single( [X_u2(II,ii); x_u2_demod(ii)], X_u2(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
Ltmp = length(colIdx);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = [ X_u1(i,colIdx).'; X_u2(i,colIdx).' ];
hIN = [ h1( hIdx ); h2( hIdx ) ];
Xout = factor_detect_approx_gmm( r(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u1(i,colIdx) = Xout(1:Ltmp).';
X_u2(i,colIdx) = Xout(Ltmp+1:2*Ltmp).';
end
% Backward pass
for i=sys.frameLen:-1:1
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u1(i,ii) = variable_detect_single( [X_u1(II,ii); x_u1_demod(ii)] , X_u1(i,ii) );
X_u2(i,ii) = variable_detect_single( [X_u2(II,ii); x_u2_demod(ii)] , X_u2(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
Ltmp = length(colIdx);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = [ X_u1(i,colIdx).'; X_u2(i,colIdx).' ];
hIN = [ h1( hIdx ); h2( hIdx )];
Xout = factor_detect_approx_gmm( r(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u1(i,colIdx) = Xout(1:Ltmp).';
X_u2(i,colIdx) = Xout(Ltmp+1:2*Ltmp).';
end
end
% Update messages to demod
for k=1:sys.numSymbols
x_u1_demod(k) = variable_detect_single( X_u1(k:k+sys.L-1,k) , x_u1_demod(k) );
x_u2_demod(k) = variable_detect_single( X_u2(k:k+sys.L-1,k) , x_u2_demod(k) );
end
% Check for NaN
if sum(sum(isnan( [[x_u1_demod.n] [x_u2_demod.n]] )))>0
fprintf('NaN found in iteration %i\n',w);
sig_nan = w;
% If at iteration 1, FG has no input...
for ww=w:sys.numIter
fg1_ind.Solver.iterate(sys.numDecodeIter);
fg2_ind.Solver.iterate(sys.numDecodeIter);
b1_est(:,ww) = b1_fg_ind.Value;
b2_est(:,ww) = b2_fg_ind.Value;
end
return;
end
% Demod / Decode User 1
x1_fg_ind.Input = [x_u1_demod.n].';
fg1_ind.Solver.iterate(sys.numDecodeIter);
% Demod / Decode User 2
x2_fg_ind.Input = [x_u2_demod.n].';
fg2_ind.Solver.iterate(sys.numDecodeIter);
% Store error counts
b1_est(:,w) = b1_fg_ind.Value;
b2_est(:,w) = b2_fg_ind.Value;
% Extrinsic information from dimple factor graphs to detector
tmp = x1_fg_ind.Belief./x1_fg_ind.Input;
EXTx1 = tmp./repmat(sum(tmp,2),1,user(1).M);
x1_priors_cell = mat2cell( EXTx1.' , user(1).M , ones(sys.numSymbols,1) );
[x_u1_demod.m] = deal(x1_priors_cell{:});
tmp = x2_fg_ind.Belief./x2_fg_ind.Input;
EXTx2 = tmp./repmat(sum(tmp,2),1,user(2).M);
x2_priors_cell = mat2cell( EXTx2.' , user(2).M , ones(sys.numSymbols,1) );
[x_u2_demod.m] = deal(x2_priors_cell{:});
% Discontinue processing a signal if decoder is confident
if w==sys.numIter, break; end
if min(max(x1_fg_ind.Belief,[],2))>0.999
if sys.v>0, fprintf('Stopping signal 1 after %i iterations\n',w); end
sig_stop(1) = w;
b1_est(:,w+1:end) = repmat(b1_est(:,w), 1, sys.numIter-w);
u1_flag = 1;
end
if min(max(x2_fg_ind.Belief,[],2))>0.999
if sys.v>0, fprintf('Stopping signal 2 after %i iterations\n',w); end
sig_stop(2) = w;
b2_est(:,w+1:end) = repmat(b2_est(:,w), 1, sys.numIter-w);
u2_flag = 1;
end
if u1_flag || u2_flag
break;
end
end
% -------------------------------------------------------------------------
% Verify both signals have completed or max iterations reached
% Otherwise continue
% -------------------------------------------------------------------------
if ((w<sys.numIter) && ((u1_flag==0) || (u2_flag==0)))
% -------------------------------------------------------------------------
% Continue processing signal 1
% -------------------------------------------------------------------------
if u1_flag==0
% Interference cancellation of user 2
x2_est = user(2).constellation(x2_fg_ind.Value+1);
rr = r - conv(h2,x2_est);
for ww=w+1:sys.numIter
% Detector iterations
for z=1:sys.numDetectIter
% Forward pass
for i=1:sys.frameLen
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u1(i,ii) = variable_detect_single( [X_u1(II,ii); x_u1_demod(ii)], X_u1(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = X_u1(i,colIdx).';
hIN = h1( hIdx );
Xout = factor_detect_approx_gmm( rr(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u1(i,colIdx) = Xout.';
end
% Backward pass
for i=sys.frameLen:-1:1
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u1(i,ii) = variable_detect_single( [X_u1(II,ii); x_u1_demod(ii)] , X_u1(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = X_u1(i,colIdx).';
hIN = h1( hIdx );
Xout = factor_detect_approx_gmm( rr(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u1(i,colIdx) = Xout.';
end
end
% Update messages to demod
for k=1:sys.numSymbols
x_u1_demod(k) = variable_detect_single( X_u1(k:k+sys.L-1,k) , x_u1_demod(k) );
end
% Check for NaN
if sum(sum(isnan( [x_u1_demod.n] )))>0
fprintf('NaN found in iteration %i\n',ww);
sig_nan = ww;
% If at iteration 1, FG has no input...
for www=ww:sys.numIter
fg1_ind.Solver.iterate(sys.numDecodeIter);
b1_est(:,www) = b1_fg_ind.Value;
end
return;
end
% Demod / Decode User 1
x1_fg_ind.Input = [x_u1_demod.n].';
fg1_ind.Solver.iterate(sys.numDecodeIter);
% Store error counts
b1_est(:,ww) = b1_fg_ind.Value;
% Discontinue processing a signal if decoder is confident
if min(max(x1_fg_ind.Belief,[],2))>0.999
if sys.v>0, fprintf('Stopping signal 1 after %i iterations\n',ww); end
sig_stop(1) = ww;
b1_est(:,ww+1:end) = repmat(b1_est(:,ww), 1, sys.numIter-ww);
break;
end
% Extrinsic information from dimple factor graphs to detector
tmp = x1_fg_ind.Belief./x1_fg_ind.Input;
EXTx1 = tmp./repmat(sum(tmp,2),1,user(1).M);
x1_priors_cell = mat2cell( EXTx1.' , user(1).M , ones(sys.numSymbols,1) );
[x_u1_demod.m] = deal(x1_priors_cell{:});
end
% -------------------------------------------------------------------------
% Continue processing signal 2
% -------------------------------------------------------------------------
elseif u2_flag==0
% Interference cancellation of user 1
x1_est = user(1).constellation(x1_fg_ind.Value+1);
rr = r - conv(h1,x1_est);
for ww=w+1:sys.numIter
% Detector iterations
for z=1:sys.numDetectIter
% Forward pass
for i=1:sys.frameLen
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u2(i,ii) = variable_detect_single( [X_u2(II,ii); x_u2_demod(ii)], X_u2(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = X_u2(i,colIdx).';
hIN = h2( hIdx );
Xout = factor_detect_approx_gmm( rr(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u2(i,colIdx) = Xout.';
end
% Backward pass
for i=sys.frameLen:-1:1
for l=0:sys.L-1
ii = i-l;
if ii<1 || ii>sys.numSymbols, continue; end
II = [ii:i-1, i+1:ii+sys.L-1];
X_u2(i,ii) = variable_detect_single( [X_u2(II,ii); x_u2_demod(ii)], X_u2(i,ii) );
end
colIdx = max(1,i-sys.L+1):min(sys.numSymbols,i);
hIdx = fliplr(max(1,i-sys.numSymbols+1):min(sys.L,i));
Xin = X_u2(i,colIdx).';
hIN = h2( hIdx );
Xout = factor_detect_approx_gmm( rr(i) , Xin , hIN , gmm , sys.C , Xconst_fctr , sys.eta );
X_u2(i,colIdx) = Xout.';
end
end
% Update messages to demod
for k=1:sys.numSymbols
x_u2_demod(k) = variable_detect_single( X_u2(k:k+sys.L-1,k) , x_u2_demod(k) );
end
% Check for NaN
if sum(sum(isnan( [x_u2_demod.n] )))>0
fprintf('NaN found in iteration %i\n',ww);
sig_nan = ww;
% If at iteration 1, FG has no input...
for www=ww:sys.numIter
fg2_ind.Solver.iterate(sys.numDecodeIter);
b2_est(:,www) = b2_fg_ind.Value;
end
return;
end
% Demod / Decode User 2
x2_fg_ind.Input = [x_u2_demod.n].';
fg2_ind.Solver.iterate(sys.numDecodeIter);
% Store error counts
b2_est(:,ww) = b2_fg_ind.Value;
% Discontinue processing a signal if decoder is confident
if min(max(x2_fg_ind.Belief,[],2))>0.999
if sys.v>0, fprintf('Stopping signal 2 after %i iterations\n',ww); end
sig_stop(2) = ww;
b2_est(:,ww+1:end) = repmat(b2_est(:,ww), 1, sys.numIter-ww);
break;
end
% Extrinsic information from dimple factor graphs to detector
tmp = x2_fg_ind.Belief./x2_fg_ind.Input;
EXTx2 = tmp./repmat(sum(tmp,2),1,user(2).M);
x2_priors_cell = mat2cell( EXTx2.' , user(2).M , ones(sys.numSymbols,1) );
[x_u2_demod.m] = deal(x2_priors_cell{:});
end
end
end
end