-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrunSimulationNumber.m
2774 lines (2482 loc) · 153 KB
/
runSimulationNumber.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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function runSimulationNumber(dataEP,scenario,simulationNumber)
%
% Function: runSimulationNumber(dataEP,scenario,simulationNumber)
%
%
% Author: Irene Santos, Juan Jose Murillo-Fuentes
%
% Contact: [email protected], [email protected]
%
% Created 20/12/2018
%
% Description: This function runs different equalizers (MMSE, EP,
% Optimal) and outputs the results into a text file.
%
% Inputs:
% dataEP: is a struct with many parameters defining the simulation,
% please, see the configuration files. Some fields are:
% dataEP.numberFrames is the number of words transmitted per simulation
% dataEP.bits is the size of information dataEP.bits
% dataEP.numberTaps is the number of taps of the channel in equalization
% dataEP.numberAntennas is the number of transmitted and receive antennas in MIMO
% dataEP.numberChannels is the number of simulated channels
% dataEP.M is the constellation size
% dataEP.flagPSK is 1 if the complex constellation is a PSK and 0 if it is a QAM
% dataEP.flagIterDec is 1 if the figures of number of iterations of the channel
% decoder is plotted
% scenario: determines if MIMO or equalization is run, the range of
% dB to simulate, please, see the configuration files
% simulationNumber: allows for several simulations run in paralel,
% indicating the number of the simulation.
dataEP.simulationNumber=simulationNumber;
%% NAME OF OUTPUT FILE to save detailed results
%To write and later read results
DELIMITER=' ';
HEADERLINES=4;
%JJMF meti un folder
if ~isfield(dataEP,'folderSave'), dataEP.folderSave='Results'; end
[status, msg, msgID] = mkdir(dataEP.folderSave);
%JJMF No entiendo lo que sale por pantalla. ?Por que cuando termina con el
%canal 10/10 vuelve a empezar? ?Cuantas veces lo repite?
%JJMF Puse un smart indent
%JJMF Me pregunto si hay posibilidad de seleccionar qu? m?todos se simulan
if dataEP.scenario==1 % equalization
nameO=([dataEP.folderSave,'/','resultsEPeq', '_b' num2str(dataEP.bits) '_M' num2str(dataEP.M) '_L' num2str(dataEP.numberTaps) '_n' num2str(dataEP.channelBlockLength) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
nameMSE=([dataEP.folderSave,'/','MSEresultsEPeq', '_b' num2str(dataEP.bits) '_M' num2str(dataEP.M) '_L' num2str(dataEP.numberTaps) '_n' num2str(dataEP.channelBlockLength) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
else
nameO=([dataEP.folderSave,'/','resultsEPmm', '_b' num2str(dataEP.bits) '_M' num2str(dataEP.M) '_NtxNr' num2str(dataEP.numberAntennas(1)) 'x' num2str(dataEP.numberAntennas(2)) '_n' num2str(dataEP.channelBlockLength) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
nameMSE=([dataEP.folderSave,'/','MSEresultsEPmm', '_b' num2str(dataEP.bits) '_M' num2str(dataEP.M) '_NtxNr' num2str(dataEP.numberAntennas(1)) 'x' num2str(dataEP.numberAntennas(2)) '_n' num2str(dataEP.channelBlockLength) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
end
%% Including the subfolder with the code of the algorihtms to the path
algstuffroot=[pwd '/algorithmsCode/'];
addpath(genpath(algstuffroot))
%% INITIALIZATION WITH INPUT PARAMETERS
verbose=1; % To display some text when simulating
if dataEP.scenario==1 % equalization
nameLog=([dataEP.folderSave,'/','LogEPeq', '_b' num2str(dataEP.bits) '_L' num2str(dataEP.numberTaps) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
else
nameLog=([dataEP.folderSave,'/','LogEPmm', '_b' num2str(dataEP.bits) '_M' num2str(dataEP.M) '_NtxNr' num2str(dataEP.numberAntennas(1)) 'x' num2str(dataEP.numberAntennas(2)) '_numCh' num2str(dataEP.numberChannels) '_' num2str(dataEP.simulationNumber) '.txt']);
end
%
if verbose
fidLog=fopen(nameLog,'w');
end
%dataEP.numberFrames
% Parameter dataEP.numberFrames
% We send dataEP.numberFrames frames
if verbose, disp('Setting numberFrames');
count=fwrite(fidLog,'Setting numberFrames','char');
count=fwrite(fidLog,10,'uint8');
end
%bits
%parameter dataEP.bits, to choose the parity matrix, it is the number of bits of
%the transmitted word. Rate 1/2 is used, with LDPC codes
if isfield(dataEP,'long')
H = dvbs2ldpc(dataEP.rate);
%H=full(H);
rate=dataEP.rate;
else
H=loadParityCheckMatrix(2^dataEP.bits);
rate=1/2;
if verbose, disp('Parity check matrix file loaded');
count=fwrite(fidLog,'Parity check matrix file loaded','char');
count=fwrite(fidLog,10,'uint8');
end
end
encoderOutputLenght=size(H,2);
encoderInputLenght=encoderOutputLenght*rate;
%dataEP.M
%Parameter dataEP.M is the size of the constellation. Must be a multiple of 2
Mnew=2^ceil(log2(dataEP.M));
if Mnew~=dataEP.M
if verbose, disp('M rounded to upper multiple of 2');
count=fwrite(fidLog,'M rounded to upper multiple of 2','char');
count=fwrite(fidLog,10,'uint8');
end
dataEP.M=Mnew;
end
%With dataEP.M we initializate the following
%Modulation and coding -> size of frames(=words)
modulatorOutputLength=encoderOutputLenght/log2(dataEP.M);
modulatorOutputLengthNew=log2(dataEP.M)*ceil(modulatorOutputLength/log2(dataEP.M)); % we round modulatorOutputLength to the nearest integer
encoderOutputLenght_new=modulatorOutputLengthNew*log2(dataEP.M);
% Parameter channelBlockLength is the size of channel in equalization (we divide the whole word in words of size channelBlockLength)
% We do not use it in MIMO
if dataEP.channelBlockLength>modulatorOutputLengthNew
dataEP.channelBlockLength=modulatorOutputLengthNew;
end
if mod(modulatorOutputLengthNew,dataEP.channelBlockLength)~=0
dataEP.channelBlockLength=modulatorOutputLengthNew/round(modulatorOutputLengthNew/dataEP.channelBlockLength);
if verbose
disp('dimCh rounded to the nearest multiple of modulatorOutputLengthNew'),
count=fwrite(fidLog,'dimCh rounded to be multiple of modulatorOutputLengthNew','char');
count=fwrite(fidLog,10,'uint8');
end
end
%dataEP.numberTaps or numberAntennas
%Parameter numberTaps is the length of the channel (in
%equalization). dataEP.numberTaps=1 if no
%memory or SISO system.
% numberAntennas is the number of antennas (in MIMO).
if dataEP.numberTaps<0 || dataEP.numberAntennas(1)<0 || dataEP.numberAntennas(2)<0
if verbose, disp('L set to two'),
count=fwrite(fidLog,'L set to two','char');
count=fwrite(fidLog,10,'uint8');
end
dataEP.numberTaps=2;
dataEP.numberAntennas=[2 2];
end
% SNRdBIni, SNRdBStep, SNRdBEnd
% To define the snr range to simulate
SNRdB=dataEP.SNRdBIni:dataEP.SNRdBStep:dataEP.SNRdBEnd;
%Scenario.
if dataEP.scenario==1 % equalization case
flagMIMO=0; % For equalization this flag is zero
else % MIMO case
flagMIMO=1;
end
% Parameter numberAntennas(1) is the size of each sent word in MIMO
% (we divide the whole word in words of size numberAntennas(1))
if flagMIMO
modulatorOutputLengthNew=lcm(log2(dataEP.M),dataEP.numberAntennas(1))*ceil(modulatorOutputLength/lcm(log2(dataEP.M),dataEP.numberAntennas(1)));
encoderOutputLenght_new=modulatorOutputLengthNew*log2(dataEP.M);
end
% dataEP.channel_h
% If channel_h=[] we average over numberChannels different channels. If a
% value is given to channel_h, the number of rows is the number of different
% channels and the number of columns is the number of taps.
if ~isempty(dataEP.channel_h) && ~flagMIMO
[dataEP.numberChannels,numberTaps]=size(dataEP.channel_h);
if verbose
disp('No random channels'),
count=fwrite(fidLog,'No random channels','char');
count=fwrite(fidLog,10,'uint8');
end
end
% numberChannel
% numerChannel is the number of the random channels simulated. It is used
% for the seed of the random number generator
idxChannels=1:dataEP.numberChannels;
%dataEP.numberTurbo
% If numberTurbo<0, we rounded it to zero.
if dataEP.numberTurbo<0
dataEP.numberTurbo=0;
end
%% OTHER INITIALIZATION
if ~isfield(dataEP,'LLRlim'), limLDPC=3;else
limLDPC=dataEP.LLRlim; end
% We limit the LLR given to the LDPC
% LDPC encoder
hEnc = comm.LDPCEncoder('ParityCheckMatrix',sparse(H));
% Modulator
if dataEP.complexFlag==0
hMod = comm.PAMModulator(dataEP.M, 'BitInput',true,'SymbolMapping','Gray');
hDemod = comm.PAMDemodulator(dataEP.M, 'BitOutput',true,'SymbolMapping','Gray');
else
if dataEP.flagPSK
hMod = comm.PSKModulator('ModulationOrder',dataEP.M,'BitInput',true,'SymbolMapping','Gray');
hDemod = comm.PSKDemodulator('ModulationOrder',dataEP.M,'BitOutput',true,'SymbolMapping','Gray');
else
hMod = comm.RectangularQAMModulator('ModulationOrder',dataEP.M,'BitInput',true,'SymbolMapping','Gray');
hDemod = comm.RectangularQAMDemodulator('ModulationOrder',dataEP.M,'BitOutput',true,'SymbolMapping','Gray');
end
end
% Interleaving/deinterleaving
seed_inter=4831; % random stream that determines the specific permutation
% LDPC decoder
hDec = comm.LDPCDecoder('ParityCheckMatrix',hEnc.ParityCheckMatrix,'DecisionMethod','Soft decision','OutputValue','Whole codeword','MaximumIterationCount',dataEP.maxIterLDPC,'IterationTerminationCondition','Parity check satisfied','NumIterationsOutputPort',true);
%% Generation of the constellation
% We use the comm toolbox, where the points of the constellation are
% separated by two
A=transpose(hMod.constellation);
energy=sum(abs(A).^2)/dataEP.M; %Average Symbol Energy
%dd=1;Acons=dd^2*(2*dataEP.M-2)/3
symbolmap=reshape(step(hDemod,A.'),log2(dataEP.M),dataEP.M); % Column i is the gray representation of symbol A(i)
%% Computing the variance of the noise from the SNRdB (abcisa axis)
if flagMIMO % MIMO, SNRdB is treated as EsNo
esno=10.^(SNRdB/10);%*log2(dataEP.M); %ebno in the MIMO case is snr
% Sigma is different for hard and soft. We simulate with sigma without
% rate, i.e., sigma for hard estimations. After simulation, we should
% move the soft curve 3dB to the right.
sigma=sqrt(dataEP.numberAntennas(1)*energy./(esno*2));
else % Equalization
ebno=10.^(SNRdB/10);
esno=log2(dataEP.M)*ebno;
EsNo=10*log10(esno);
sigma=10.^(-EsNo/20)*sqrt(energy/2);
end
% If error in the channel matrix we use a modified noise variance
sigma_novarCH=sigma;
sigma=sqrt(sigma.^2+dataEP.numberAntennas(1)*dataEP.varnoiseCH*energy);
%%%
%% Creating new file
% and writting data of the scenario
fidauxMSE=fopen(nameMSE,'w');
count=fwrite(fidauxMSE,'numberFrames=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberFrames),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'b=','char');
count=fwrite(fidauxMSE,num2str(dataEP.bits),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'numerChannels=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberChannels),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'M=','char');
count=fwrite(fidauxMSE,num2str(dataEP.M),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'complexFlag=','char');
count=fwrite(fidauxMSE,num2str(dataEP.complexFlag),'char');
count=fwrite(fidauxMSE,' ','char');
if dataEP.scenario==1
count=fwrite(fidauxMSE,'L=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberTaps),'char');
else
count=fwrite(fidauxMSE,'Nt=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberAntennas(1)),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'Nr=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberAntennas(2)),'char');
end
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'scenario=','char');
count=fwrite(fidauxMSE,num2str(dataEP.scenario),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'SNRdB=','char');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBIni),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBStep),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBEnd),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'numberTurbo=','char');
count=fwrite(fidauxMSE,num2str(dataEP.numberTurbo),'char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,10,'uint8');
count=fwrite(fidauxMSE,'SNRdB=SNRdBIni:step:SNRdBEnd','char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'numberTurbo','char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'numberChannels','char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'numberTaps','char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,10,'uint8');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBIni),'char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBStep),'char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,num2str(dataEP.SNRdBEnd),'char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,num2str(dataEP.numberTurbo),'char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,num2str(dataEP.numberChannels),'char');
count=fwrite(fidauxMSE,' ','uint8');
if dataEP.scenario==1
count=fwrite(fidauxMSE,num2str(dataEP.numberTaps),'char');
else
count=fwrite(fidauxMSE,num2str(dataEP.numberAntennas(1)),'char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,num2str(dataEP.numberAntennas(2)),'char');
end
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,10,'uint8');
count=fwrite(fidauxMSE,'n_h','char');
count=fwrite(fidauxMSE,' ','char');
count=fwrite(fidauxMSE,'hDBEPC','char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,'hDBEPD','char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,'hDBEPL','char');
count=fwrite(fidauxMSE,' ','uint8');
count=fwrite(fidauxMSE,10,'uint8');
fclose(fidauxMSE);
%%%
%% Creating new file
% and writting data of the scenario
fidaux=fopen(nameO,'w');
count=fwrite(fidaux,'numberFrames=','char');
count=fwrite(fidaux,num2str(dataEP.numberFrames),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'b=','char');
count=fwrite(fidaux,num2str(dataEP.bits),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'numerChannels=','char');
count=fwrite(fidaux,num2str(dataEP.numberChannels),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'M=','char');
count=fwrite(fidaux,num2str(dataEP.M),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'complexFlag=','char');
count=fwrite(fidaux,num2str(dataEP.complexFlag),'char');
count=fwrite(fidaux,' ','char');
if dataEP.scenario==1
count=fwrite(fidaux,'L=','char');
count=fwrite(fidaux,num2str(dataEP.numberTaps),'char');
else
count=fwrite(fidaux,'Nt=','char');
count=fwrite(fidaux,num2str(dataEP.numberAntennas(1)),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'Nr=','char');
count=fwrite(fidaux,num2str(dataEP.numberAntennas(2)),'char');
end
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'scenario=','char');
count=fwrite(fidaux,num2str(dataEP.scenario),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'SNRdB=','char');
count=fwrite(fidaux,num2str(dataEP.SNRdBIni),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,num2str(dataEP.SNRdBStep),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,num2str(dataEP.SNRdBEnd),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'numberTurbo=','char');
count=fwrite(fidaux,num2str(dataEP.numberTurbo),'char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,10,'uint8');
count=fwrite(fidaux,'SNRdB=SNRdBIni:step:SNRdBEnd','char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'numberTurbo','char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'numberChannels','char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'numberTaps','char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,10,'uint8');
count=fwrite(fidaux,num2str(dataEP.SNRdBIni),'char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,num2str(dataEP.SNRdBStep),'char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,num2str(dataEP.SNRdBEnd),'char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,num2str(dataEP.numberTurbo),'char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,num2str(dataEP.numberChannels),'char');
count=fwrite(fidaux,' ','uint8');
if dataEP.scenario==1
count=fwrite(fidaux,num2str(dataEP.numberTaps),'char');
else
count=fwrite(fidaux,num2str(dataEP.numberAntennas(1)),'char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,num2str(dataEP.numberAntennas(2)),'char');
end
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,10,'uint8');
count=fwrite(fidaux,'n_h','char');
count=fwrite(fidaux,' ','char');
count=fwrite(fidaux,'hMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxGS','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxGSturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxNeuman','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxNeumanturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxPCG','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hMMSEAproxPCGturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hFMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hFMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDBEPAprox','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDBEPAproxturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPFEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPFEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDFEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hDFEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hSEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hSEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPKSEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hPKSEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hEPICLMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hEPICLMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hOptimal','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'hOptimalturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxGS','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxGSturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxNeuman','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxNeumanturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxPCG','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sMMSEAproxPCGturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sFMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sFMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDBEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDBEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDBEPAprox','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDBEPAproxturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPFEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPFEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDFEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDFEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sSEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sSEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPKSEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sPKSEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sDKSEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sKDSEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sEPICLMMSE','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sEPICLMMSEturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sBPEP','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sBPEPturbo','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sOptimal','char');
count=fwrite(fidaux,' ','uint8');
count=fwrite(fidaux,'sOptimalturbo','char');
count=fwrite(fidaux,10,'uint8');
fclose(fidaux);
%% RUNNING MONTECARLO
tStart=tic;
for n_h=idxChannels
%JJMF
if verbose, disp(['SimulationNumber =',num2str(dataEP.simulationNumber)])%),...
% ', n_h=',num2str(n_h),'/',num2str(dataEP.numberChannels)])
end
%%Computing a sample of the channel
if flagMIMO % MIMO
% Seed
% randn('seed',n_h);
% rand('seed',n_h);
rng(n_h,'twister')
if dataEP.complexFlag==0 % real
% Gaussian channels
Hmat_novarCH=randn(dataEP.numberAntennas(2),dataEP.numberAntennas(1));
Hmat=Hmat_novarCH+randn(size(Hmat_novarCH))*sqrt(dataEP.varnoiseCH);
else
Hmat_novarCH=randn(dataEP.numberAntennas(2),dataEP.numberAntennas(1))+1i*randn(dataEP.numberAntennas(2),dataEP.numberAntennas(1));
Hmat_novarCH=Hmat_novarCH/sqrt(2);
Hmat=Hmat_novarCH+randn(size(Hmat_novarCH))*sqrt(dataEP.varnoiseCH)+1i*randn(size(Hmat_novarCH))*sqrt(dataEP.varnoiseCH);
end
% delta=0.2;Hmat=[ones(1,4);zeros(3,4)];Hmat(:,2)=Hmat(:,2)+delta;Hmat(:,3)=Hmat(:,3)+2*delta;Hmat(:,4)=Hmat(:,4)+4*delta;
% Hmat_novarCH=Hmat;
%Hmat_novarCH=[1;1];
% Hmat_novarCH=ones(32,32)*0.5+.5*eye(32);
% Hmat=Hmat_novarCH;
% Hmat
else %EQUALIZATION
% Channel
if isempty(dataEP.channel_h)
% Seed
%randn('state',100*n_h*7);
%rand('state',100*n_h*7);
rng(100*n_h*7,'twister')
if dataEP.complexFlag==0 % real
% Gaussian channels
h_novarCH=randn(1,dataEP.numberTaps)/sqrt(dataEP.numberTaps);
if scenario.flagNorm %Normalized if set in the scenario
h_novarCH=h_novarCH./norm(h_novarCH);
end
h=h_novarCH+randn(size(h_novarCH))*sqrt(dataEP.varnoiseCH);
else
% Gaussian channels
h_novarCH=randn(1,dataEP.numberTaps)+1i*randn(1,dataEP.numberTaps);
h_novarCH=h_novarCH/sqrt(2*dataEP.numberTaps);
if scenario.flagNorm %Normalized if set in the scenario
h_novarCH=h_novarCH./norm(h_novarCH);
end
h=h_novarCH+randn(size(h_novarCH))*sqrt(dataEP.varnoiseCH)+1i*randn(size(h_novarCH))*sqrt(dataEP.varnoiseCH);
end
else
h_novarCH=dataEP.channel_h(n_h,:);
h=h_novarCH+randn(size(h_novarCH))*sqrt(dataEP.varnoiseCH);
end
% Computing matrix channel
Hmat=obth(h,dataEP.channelBlockLength+dataEP.numberTaps-1);
Hmat=Hmat(:,1:end-dataEP.numberTaps+1);
Hmat_novarCH=obth(h_novarCH,dataEP.channelBlockLength+dataEP.numberTaps-1);
Hmat_novarCH=Hmat_novarCH(:,1:end-dataEP.numberTaps+1);
end
%% Initializating BCJR if scenario.flagOptimal
if scenario.flagOptimal && ~flagMIMO
[convmat_trans,convmat_salidas,transp_llegan_a_q,...
transq_llegan_a_p]=var_trellis(A,dataEP.numberTaps,h.');
end
% Initialize BER for the channel
% Hard errors
n_errors_hard_MMSE=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_MMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseC_MMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseD_MMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseL_MMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_MMSEAproxGS=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_MMSEAproxGS_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_MMSEAproxNeuman=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_MMSEAproxNeuman_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_MMSEAproxPCG=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_MMSEAproxPCG_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_FMMSE=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_FMMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_BEP=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_BEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_PBEP=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_PBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
%%
n_mseC_PBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseD_PBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseL_PBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_DBEP=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_DBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
%%
n_mseC_DBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseD_DBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseL_DBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_DBEPAproxGS=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_DBEPAproxGS_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_DBEPAproxNeuman=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_DBEPAproxNeuman_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_DBEPAproxPCG=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_DBEPAproxPCG_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_PFEP=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_PFEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_SEP=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_SEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_EPICLMMSE=zeros(length(SNRdB),1); % number of errors for each SNR
n_errors_hard_EPICLMMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseC_EPIC_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseD_EPIC_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_mseL_EPIC_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_hard_optimal=zeros(length(SNRdB),1);
n_errors_hard_optimal_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
% Soft errors
n_errors_soft_MMSEAproxGS=zeros(length(SNRdB),1);
n_errors_soft_MMSEAproxGS_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_MMSEAproxNeuman=zeros(length(SNRdB),1);
n_errors_soft_MMSEAproxNeuman_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_MMSEAproxPCG=zeros(length(SNRdB),1);
n_errors_soft_MMSEAproxPCG_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_MMSE=zeros(length(SNRdB),1);
n_errors_soft_MMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_FMMSE=zeros(length(SNRdB),1);
n_errors_soft_FMMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_BEP=zeros(length(SNRdB),1);
n_errors_soft_BEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_PBEP=zeros(length(SNRdB),1);
n_errors_soft_PBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DBEP=zeros(length(SNRdB),1);
n_errors_soft_DBEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DBEPAproxGS=zeros(length(SNRdB),1);
n_errors_soft_DBEPAproxGS_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DBEPAproxNeuman=zeros(length(SNRdB),1);
n_errors_soft_DBEPAproxNeuman_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DBEPAproxPCG=zeros(length(SNRdB),1);
n_errors_soft_DBEPAproxPCG_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_PFEP=zeros(length(SNRdB),1);
n_errors_soft_PFEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DFEP=zeros(length(SNRdB),1);
n_errors_soft_DFEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_SEP=zeros(length(SNRdB),1);
n_errors_soft_SEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_PKSEP=zeros(length(SNRdB),1);
n_errors_soft_PKSEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_DKSEP=zeros(length(SNRdB),1);
n_errors_soft_DKSEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_EPICLMMSE=zeros(length(SNRdB),1);
n_errors_soft_EPICLMMSE_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_BPEP=zeros(length(SNRdB),1);
n_errors_soft_BPEP_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
n_errors_soft_optimal=zeros(length(SNRdB),1);
n_errors_soft_optimal_turbo=zeros(length(SNRdB),dataEP.numberTurbo);
if dataEP.flagIterDec
% Number of iterations of the channel decoder
niterdec_MMSEAproxGS=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_MMSEAproxNeuman=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_MMSEAproxPCG=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_MMSE=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_FMMSE=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_BEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_PBEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DBEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DBEPAproxGS=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DBEPAproxNeuman=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DBEPAproxPCG=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_PFEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DFEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_SEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_PKSEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_DKSEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_EPICLMMSE=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_BPEP=zeros(length(SNRdB),dataEP.numberTurbo+1);
niterdec_Optimal=zeros(length(SNRdB),dataEP.numberTurbo+1);
end
%% Running Montecarlo for the channel and the Eb/N0s
for snr=1:length(SNRdB)
% Hard errors
err_hard_MMSE=0;
err_hard_MMSEturbo=zeros(1,dataEP.numberTurbo);
err_hard_MMSEAproxGS=0;
err_hard_MMSEAproxGSturbo=zeros(1,dataEP.numberTurbo);
err_hard_MMSEAproxNeuman=0;
err_hard_MMSEAproxNeumanturbo=zeros(1,dataEP.numberTurbo);
err_hard_MMSEAproxPCG=0;
err_hard_MMSEAproxPCGturbo=zeros(1,dataEP.numberTurbo);
err_hard_FMMSE=0;
err_hard_FMMSEturbo=zeros(1,dataEP.numberTurbo);
err_hard_BEP=0;
err_hard_BEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_PBEP=0;
err_hard_PBEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_DBEP=0;
err_hard_DBEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_DBEPAproxGS=0;
err_hard_DBEPAproxGSturbo=zeros(1,dataEP.numberTurbo);
err_hard_DBEPAproxNeuman=0;
err_hard_DBEPAproxNeumanturbo=zeros(1,dataEP.numberTurbo);
err_hard_DBEPAproxPCG=0;
err_hard_DBEPAproxPCGturbo=zeros(1,dataEP.numberTurbo);
err_hard_PFEP=0;
err_hard_PFEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_DFEP=0;
err_hard_DFEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_SEP=0;
err_hard_SEPturbo=zeros(1,dataEP.numberTurbo);
err_hard_EPICLMMSE=0;
err_hard_EPICLMMSEturbo=zeros(1,dataEP.numberTurbo);
err_hard_Optimal=0;
err_hard_Optimalturbo=zeros(1,dataEP.numberTurbo);
% Soft errors
err_soft_MMSE=0;
err_soft_MMSE_turbo=zeros(1,dataEP.numberTurbo);
mseCit_MMSE_turbo=zeros(1,dataEP.numberTurbo);
mseDit_MMSE_turbo=zeros(1,dataEP.numberTurbo);
mseLit_MMSE_turbo=zeros(1,dataEP.numberTurbo);
err_soft_MMSEAproxGS=0;
err_soft_MMSEAproxGS_turbo=zeros(1,dataEP.numberTurbo);
err_soft_MMSEAproxNeuman=0;
err_soft_MMSEAproxNeuman_turbo=zeros(1,dataEP.numberTurbo);
err_soft_MMSEAproxPCG=0;
err_soft_MMSEAproxPCG_turbo=zeros(1,dataEP.numberTurbo);
err_soft_FMMSE=0;
err_soft_FMMSE_turbo=zeros(1,dataEP.numberTurbo);
err_soft_BEP=0;
err_soft_BEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_PBEP=0;
err_soft_PBEP_turbo=zeros(1,dataEP.numberTurbo);
mseCit_PBEP_turbo=zeros(1,dataEP.numberTurbo);
mseDit_PBEP_turbo=zeros(1,dataEP.numberTurbo);
mseLit_PBEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DBEP=0;
err_soft_DBEP_turbo=zeros(1,dataEP.numberTurbo);
mseCit_DBEP_turbo=zeros(1,dataEP.numberTurbo);
mseDit_DBEP_turbo=zeros(1,dataEP.numberTurbo);
mseLit_DBEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DBEPAproxGS=0;
err_soft_DBEPAproxGS_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DBEPAproxNeuman=0;
err_soft_DBEPAproxNeuman_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DBEPAproxPCG=0;
err_soft_DBEPAproxPCG_turbo=zeros(1,dataEP.numberTurbo);
err_soft_PFEP=0;
err_soft_PFEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DFEP=0;
err_soft_DFEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_SEP=0;
err_soft_SEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_PKSEP=0;
err_soft_PKSEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_DKSEP=0;
err_soft_DKSEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_BPEP=0;
err_soft_BPEP_turbo=zeros(1,dataEP.numberTurbo);
err_soft_EPICLMMSE=0;
err_soft_EPICLMMSE_turbo=zeros(1,dataEP.numberTurbo);
mseCit_EPIC_turbo=zeros(1,dataEP.numberTurbo);
mseDit_EPIC_turbo=zeros(1,dataEP.numberTurbo);
mseLit_EPIC_turbo=zeros(1,dataEP.numberTurbo);
err_soft_Optimal=0;
err_soft_Optimal_turbo=zeros(1,dataEP.numberTurbo);
if verbose
disp(['n_h=',num2str(n_h),'/',num2str(dataEP.numberChannels),' SNRdB=',num2str(SNRdB(snr)),'/',num2str(SNRdB(end))])
%disp(['SNRdB=',num2str(SNRdB(snr)),'/',num2str(SNRdB(end))])
%fprintf('SNRdB= %f, Clock: ',SNRdB(snr), num2str(toc(tStart)))
% disp(['Clock: ',num2str(toc(tStart))])
count=fwrite(fidLog,'n_h=','char');
count=fwrite(fidLog,num2str(n_h),'char');
count=fwrite(fidLog,' ','char');
count=fwrite(fidLog,'Clock=','char');
count=fwrite(fidLog,num2str(toc(tStart)),'char');
count=fwrite(fidLog,10,'uint8');
end
for k=1:dataEP.numberFrames
%% Sample of transmitted data
%rand('state',sum(100*clock));
%randn('state',sum(100*clock));
%rng(simulationNumber*1e6+k,'twister');
rng(n_h+(dataEP.numberChannels*(k-1))+(dataEP.numberChannels*dataEP.numberFrames)*(simulationNumber-1),'twister');
%rng(100*k*simulationNumber,'twister')
% rand('state',sum(100*k*n_h*dataEP.simulationNumber*snr));
% randn('state',sum(100*k*n_h*dataEP.simulationNumber*snr));
x_sincod = randi([0 1],encoderInputLenght,1);
% Channel Encoding
x = step(hEnc, x_sincod);
%x=[x;randi(2,[encoderOutputLenght_new-encoderOutputLenght 1])-1];
x=[x;zeros(encoderOutputLenght_new-encoderOutputLenght,1)];
% Interlaving
if dataEP.flagInterleaving
x = randintrlv(x,seed_inter);
end
%% Modulation
x=step(hMod, x);
if flagMIMO
Limk1=modulatorOutputLengthNew/dataEP.numberAntennas(1);
xmat=reshape(x,dataEP.numberAntennas(1),Limk1);
else
Limk1=modulatorOutputLengthNew/dataEP.channelBlockLength;
xmat=reshape(x,dataEP.channelBlockLength,Limk1);
end
% We keep the vector of noise and received vector to use the
% same ones when turbo is computed
noiseALL=zeros(size(Hmat,1),Limk1);
rALLC=zeros(size(Hmat,1),Limk1);
% For double proposals (it is needed if the frame is divided
% into different blocks)
meanE_DBEP=zeros(size(xmat));
varE_DBEP=zeros(size(xmat));
meanE_DBEPAproxGS=zeros(size(xmat));
varE_DBEPAproxGS=zeros(size(xmat));
meanE_DBEPAproxNeuman=zeros(size(xmat));
varE_DBEPAproxNeuman=zeros(size(xmat));
meanE_DBEPAproxPCG=zeros(size(xmat));
varE_DBEPAproxPCG=zeros(size(xmat));
meanE_DFEP=zeros(size(xmat));
varE_DFEP=zeros(size(xmat));
meanE_DKSEP=zeros(size(xmat));
varE_DKSEP=zeros(size(xmat));
meanE_BPEP=zeros(size(xmat));
varE_BPEP=zeros(size(xmat));
for idxTurbo=0:dataEP.numberTurbo
LLR_MMSE=[];
LLR_MMSEAproxGS=[];
LLR_MMSEAproxNeuman=[];
LLR_MMSEAproxPCG=[];
LLR_FMMSE=[];
LLR_BEP=[];
LLR_EPICLMMSE=[];
LLR_SEP=[];
LLR_PBEP=[];
LLR_DBEP=[];
LLR_DBEPAproxGS=[];
LLR_DBEPAproxNeuman=[];
LLR_DBEPAproxPCG=[];
LLR_PFEP=[];
LLR_DFEP=[];
LLR_PKSEP=[];
LLR_DKSEP=[];
LLR_BPEP=[];
LLR_Optimal=[];
for k1=1:Limk1
x=xmat(:,k1); %each column of xmat is a vector transmitted by the Tx antennas
xinitial=x;
if idxTurbo==0
% AWGN noise
noise=sigma_novarCH(snr)*randn(size(Hmat_novarCH,1),1);
if dataEP.complexFlag
noise=noise+1i*sigma_novarCH(snr)*randn(size(Hmat_novarCH,1),1);
end
noiseALL(:,k1)=noise;
% Salida del canal
Hx=Hmat_novarCH*xinitial; %JJMF
rcomplex=Hmat_novarCH*xinitial+noise;
rALLC(:,k1)=rcomplex;
else
noise=noiseALL(:,k1);
rcomplex=rALLC(:,k1);
end
%%%%%%%%%%%%%
%% DETECTION
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% MMSE [Muranov10] %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if scenario.flagMMSE
if scenario.SNRdBMMSE(1)<=SNRdB(snr) && scenario.SNRdBMMSE(2)>=SNRdB(snr)
if idxTurbo==0
[x_decod_hard_MMSE,prob_b_MMSE]=MMSEalg(A,dataEP.complexFlag,sigma(snr),rcomplex,Hmat,[]);
% Hard detection
err_hard_MMSE=err_hard_MMSE+sum(xinitial~=x_decod_hard_MMSE);
% Demodulation
prob_b_after_demap=demap(prob_b_MMSE,symbolmap,dataEP.flagInterleaving,seed_inter);
LLR_MMSE=[LLR_MMSE real(log(prob_b_after_demap(1,:)./prob_b_after_demap(2,:)))];
else
[x_decod_hard_MMSE,prob_b_MMSE]=MMSEalg(A,dataEP.complexFlag,sigma(snr),rcomplex,Hmat,pui_ldpc_MMSE(:,:,k1).');
% Hard detection
err_hard_MMSEturbo(idxTurbo)=err_hard_MMSEturbo(idxTurbo)+sum(xinitial~=x_decod_hard_MMSE);
% Demodulation
prob_b_after_demap=demap(prob_b_MMSE,symbolmap,dataEP.flagInterleaving,seed_inter);
LLR_MMSE=[LLR_MMSE real(log(prob_b_after_demap(1,:)./prob_b_after_demap(2,:)))];
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% approximated MMSE with GS %%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if scenario.flagMMSEAproxGS
if scenario.SNRdBMMSE(1)<=SNRdB(snr) && scenario.SNRdBMMSE(2)>=SNRdB(snr)
if idxTurbo==0
[x_decod_hard_MMSEAproxGS,prob_b_MMSEAproxGS]=MMSEalgAproxGS(A,dataEP.complexFlag,sigma(snr),rcomplex,Hmat,[]);
% Hard detection
err_hard_MMSEAproxGS=err_hard_MMSEAproxGS+sum(xinitial~=x_decod_hard_MMSEAproxGS);
% Demodulation
prob_b_after_demap=demap(prob_b_MMSEAproxGS,symbolmap,dataEP.flagInterleaving,seed_inter);
LLR_MMSEAproxGS=[LLR_MMSEAproxGS real(log(prob_b_after_demap(1,:)./prob_b_after_demap(2,:)))];