-
Notifications
You must be signed in to change notification settings - Fork 5
/
go.m
808 lines (683 loc) · 31.3 KB
/
go.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
function vM = go(vSet, LOG, VERBOSE, MODE)
% Fiber-optics with DSP
%
% datestr(datenum(now))
%
% Birth: 04-Sep-2015 14:10:02
% Rebuilt: 13-Mar-2016 06:43:24
% Rebuilt: 12 Nov-2016 15:52:00
% Rebuilt: 18-Feb-2017 17:19:42
%
% Data Streaming
%
% DSP mode: 0-Offline; 1-Real-time
%
% Refined: 18-Feb-2017 17:19:42
if nargin < 4
MODE = 0; % 0 back-to-back
% 1
% 2
% 3
end
if nargin < 3, VERBOSE = 1; end
if nargin < 2, LOG = 0; end
% Log file
if LOG
log_file = fopen('log','a');
fprintf(log_file, '-------------------------------------');
fprintf(log_file, '\n');
fprintf(log_file, 'Time now is %s\n', datestr(now));
if exist('vSet', 'var')
fprintf(log_file, 'Caller is %s\n', vSet.caller);
end
else
log_file = 1;
end
switch MODE
case 0
ctrlParam.doPilot = 0;
ctrlParam.doNFC = 0;
ctrlParam.doRZ = 0;
ctrlParam.doNyquist = 1;
ctrlParam.doRndPMD = 0;
ctrlParam.doMzmComp = 1;
% ctrlParam.doCoherent = 1;
ctrlParam.doBalanced = 1;
ctrlParam.doDSP = 1;
ctrlParam.doPlot = 0;
% Controller
ctrlParam.addASE = 1;
ctrlParam.addCD = 0;
ctrlParam.addPMD = 0;
ctrlParam.addLaserRIN = 0;
ctrlParam.addLaserPN = 0;
ctrlParam.addPolarRot = 0;
ctrlParam.addThermNoise = 0;
ctrlParam.addShotNoise = 0;
ctrlParam.addRIN = 0;
ctrlParam.addAdcClockJitter = 0;
ctrlParam.addFreqOffset = 0;
case 1
case 2
case 3
otherwise
keyboard;
end
% Constants
LIGHT_SPEED = 299792458;
BOLTZMAN = 1.381e-23;
ELECTRON = 1.602e-19;
EID = 'goErr';
FRAME_WINDOW = 3;
TEMPERATURE = 300;
PD_LOAD_RESISTANCE = 5000; % TIA in PD
NOISE_REFERENCE_BAND = 12.5e9; % for OSNR definition
DETECTION_MODE = 'HOM'; % HOM or HET
CENTER_FREQUENCY = 193.41e12;
CENTER_WAVELENGTH = LIGHT_SPEED / CENTER_FREQUENCY;
FIG_TXPN = 1;
FIG_TXLASER = 2;
FIG_DRVEYE = 3;
FIG_RECEIVED = 4;
FIG_AFTERADC = 5;
if nargin < 1
MAX_RUN_NUMBER = 1000;
HYBRID_90_PHASESHIFT = 90; % degree
ADC_SAMPLING_RATE = 2; % samples per symbol
DSP_MODE = 0; % 0 - offline;
DSO_MEMORY_LENGTH = 200; % number of frames
LASER_LINEWIDTH = 500e3;
OSNR = 140; % SNR of one symbol
baudrate = 30e9;
bitpersym = 2;
modFormat = 'QPSK';
freqOffset = 1.0e9;
psFiltType = 'Nyquist'; % Nyquist Bessel Gaussian
else
MAX_RUN_NUMBER = vSet.nFrm;
HYBRID_90_PHASESHIFT = vSet.Hyd90;
ADC_SAMPLING_RATE = vSet.ADCfs;
DSP_MODE = vSet.DSPmode;
DSO_MEMORY_LENGTH = vSet.DSPmemLen;
LASER_LINEWIDTH = vSet.linewidth;
OSNR = vSet.osnr;
baudrate = vSet.baudrate;
bitpersym = vSet.bitpersym;
modFormat = vSet.modFormat;
freqOffset = vSet.freqOffset;
psFiltType = vSet.psFiltType;
end
if VERBOSE
fprintf(log_file, '* modulation format is %s \n', modFormat);
fprintf(log_file, '* pulse-shaping filter type is %s \n', psFiltType);
fprintf(log_file, '* detection mode is %s \n', DETECTION_MODE);
end
% Global parameters
sampling_freq = 8 * baudrate;
timewindow = 512 / baudrate;
symperframe = timewindow * baudrate;
samplePerSymbol = sampling_freq / baudrate;
samplesPerFrame = symperframe * samplePerSymbol;
vctFreqPerFrm = getFFTGrid(samplesPerFrame, sampling_freq);
nsamples = FRAME_WINDOW * samplesPerFrame;
timeVector = (0 : nsamples-1)' / sampling_freq;
freqVector = getFFTGrid(nsamples, sampling_freq);
ALPHABET_SIZE = 2 ^ bitpersym;
vM.StartTime = datestr(now);
% initialize absolute time
timeVectorAbs = timeVector;
% Components
txLaser.centerFreq = CENTER_FREQUENCY;
txLaser.centerLambda = LIGHT_SPEED / txLaser.centerFreq;
txLaser.linewidth = LASER_LINEWIDTH;
txLaser.phaseNoiseVar = 2 * pi * txLaser.linewidth / sampling_freq;
txLaser.azimuth = 0;
txLaser.ellipticity = 0;
txLaser.power = 1e-3;
txLaser.RIN = -130; % dBc/Hz
modulator.Vpi = 3; % [V]
modulator.extRatio = 100; % [dB]
modulator.efficiency = 0.15;
transmtter.lpfOrder = 4;
transmtter.bandwidth = 0.75 * baudrate;
transmtter.pilotX = [];
transmtter.pilotY = [];
fiber.n2 = 2.6e-20;
fiber.coreArea = 80e-12; % [m^2]
fiber.initPolAngle = 0; % degree
fiber.rotSpeed = 30e3; % rad/s
fiber.lossFast = 0.2;
fiber.lossSlow = 0.2; % [dB/km]
fiber.spanLength = 80e3;
fiber.spanNum = 2;
fiber.stepLength = 1e3;
fiber.corrLength = 100;
fiber.dispParamD = 17e-6; % [s/m]
fiber.dispParamS = 0.08e3; % [s/m^2]
fiber.doFullPMD = 0;
fiber.pmdParam = 0.5e-12 / 31.623;
fiber.noiseSeed = 0; % random number seed
% accumulated dispersion ps/nm
fiber.DL = fiber.dispParamD * fiber.spanLength * fiber.spanNum;
% accumulated dispersion slop
fiber.SL = fiber.dispParamS * fiber.spanLength * fiber.spanNum;
optFilterOrder = 4;
optFilterBw = 40e9;
receiver.centerFreq = CENTER_FREQUENCY;
receiver.lpfOrder = 5;
receiver.bandwidth = 0.75 * baudrate;
rxLaser.centerLambda = LIGHT_SPEED / receiver.centerFreq;
rxLaser.noiseSeed = 0;
rxLaser.linewidth = LASER_LINEWIDTH;
rxLaser.phaseNoiseVar = 2 * pi * rxLaser.linewidth / sampling_freq;
rxLaser.azimuth = 45;
rxLaser.ellipticity = 0;
rxLaser.power = 10e-3;
rxLaser.psdRIN = -135; % dBc/Hz, one-sided
% power split ratio of PBC
receiver.pbcPowerSplitRatio = 0.5;
receiver.pbcPhaseRetard = 0;
receiver.detectorResponsivity = 1.0;
receiver.detectorDarkCurrent = 0.0E-9;
receiver.CMRR = 30;
% electrical noises are defined as one-sided PSD in current
receiver.psdThermal = 4 * BOLTZMAN * TEMPERATURE / PD_LOAD_RESISTANCE * (0.5 * sampling_freq);
receiver.psdShot = 2 * ELECTRON * receiver.detectorResponsivity * (rxLaser.power / 2) * (0.5 * sampling_freq);
receiver.psdRIN = (receiver.detectorResponsivity).^2 * (10.^(-receiver.CMRR/20)).^2 * idbw(rxLaser.psdRIN) * (rxLaser.power).^2 * (0.5 * sampling_freq) / 4;
%% Preparing filter responses
txPulseShapeFilter.RollOffFactor = 0.35;
txPulseShapeFilter.freqRespRC = frequency_response(nsamples, sampling_freq, txPulseShapeFilter.RollOffFactor, baudrate, 'rc');
txPulseShapeFilter.freqRespRRC = frequency_response(nsamples, sampling_freq, txPulseShapeFilter.RollOffFactor, baudrate, 'rrc');
txPulseShapeFilter.freqRespBessel = frequency_response(nsamples, sampling_freq, transmtter.lpfOrder, transmtter.bandwidth, 'bessel');
txPulseShapeFilter.freqRespNyquist = frequency_response(nsamples, sampling_freq, 0.1, baudrate, 'nyquist');
txPulseShapeFilter.freqRespGaussian = frequency_response(nsamples, sampling_freq, transmtter.lpfOrder, transmtter.bandwidth, 'gaussian');
rxPulseShapeFilter.RollOffFactor = 0.35;
rxPulseShapeFilter.freqRespRC = frequency_response(nsamples, sampling_freq, rxPulseShapeFilter.RollOffFactor, baudrate, 'rc');
rxPulseShapeFilter.freqRespRRC = frequency_response(nsamples, sampling_freq, rxPulseShapeFilter.RollOffFactor, baudrate, 'rrc');
rxPulseShapeFilter.freqRespBessel = frequency_response(nsamples, sampling_freq, receiver.lpfOrder, receiver.bandwidth, 'bessel');
rxPulseShapeFilter.freqRespNyquist = frequency_response(nsamples, sampling_freq, 0.1, baudrate, 'nyquist');
rxPulseShapeFilter.freqRespGaussian = frequency_response(nsamples, sampling_freq, receiver.lpfOrder, receiver.bandwidth, 'gaussian');
optGaussianFilter = frequency_response(nsamples, sampling_freq, optFilterOrder, optFilterBw, 'gaussian');
% Initialize buffer
buffer.txBitsX = randi([0 1], bitpersym, FRAME_WINDOW*symperframe);
buffer.txBitsY = randi([0 1], bitpersym, FRAME_WINDOW*symperframe);
buffer.rxBitsX = randi([0 1], bitpersym, FRAME_WINDOW*symperframe);
buffer.rxBitsY = randi([0 1], bitpersym, FRAME_WINDOW*symperframe);
buffer.txPhaseNoise = phase_noise(nsamples, txLaser.phaseNoiseVar, 0);
buffer.rxPhaseNoise = phase_noise(nsamples, rxLaser.phaseNoiseVar, 0);
buffer.txLaserRIN = zeros(1,nsamples);
buffer.rxLaserRIN = zeros(1,nsamples);
buffer.channelNoiseX = zeros(1,nsamples);
buffer.channelNoiseY = zeros(1,nsamples);
buffer.thermNsIx = zeros(1,nsamples);
buffer.thermNsQx = zeros(1,nsamples);
buffer.thermNsIy = zeros(1,nsamples);
buffer.thermNsQy = zeros(1,nsamples);
buffer.shotNsIx = zeros(1,nsamples);
buffer.shotNsQx = zeros(1,nsamples);
buffer.shotNsIy = zeros(1,nsamples);
buffer.shotNsQy = zeros(1,nsamples);
% Clear memory
memory1 = [];
memory2 = [];
memory3 = [];
memory4 = [];
dspMemCount = 0;
% DSP
dspParam.Rs = 28e9;
dspParam.mn = 4;
dspParam.adcFs = 56e9;
dspParam.showEye = 0;
dspParam.doFrontEndComp = 0;
dspParam.doDigitalLPF = 0;
dspParam.doCDC = 0;
dspParam.doCDE = 0;
dspParam.doFramer = 0;
dspParam.doTraining = 0;
dspParam.doMIMO = 0;
dspParam.doTPE = 0;
dspParam.doCPE = 0;
dspParam.doLmsAfterCPE = 0;
dspParam.doFOE = 0;
dspParam.doFEC = 0;
dspParam.doDownSampling = 1;
dspParam.DL = fiber.DL;
dspParam.SL = fiber.SL;
dspParam.lambda = CENTER_WAVELENGTH;
dspParam.lambda0 = CENTER_WAVELENGTH;
dspParam.lpfBW = 0;
dspParam.mimoStep = 1e-3;
dspParam.mimoTapNum = 7; %7 or 13
dspParam.mimoErrId = 0;
dspParam.mimoIteration = 10;
dspParam.lmsGainAfterCPE = 1e-3;
dspParam.lmsTapsAfterCPE = 125;
dspParam.lmsIterAfterCPE = 4;
dspParam.cpeBlockSize = 16;
dspParam.cpePLLmu = [1e-3, 1e-6];
dspParam.doMLCPE = 2;
dspParam.cpeMLavgLeng = 32;
dspParam.cpeMlIter = 1;
dspParam.vvpeAvgMode = 1; % 0 for blockwise 1 for sliding window
dspParam.cpeBPSnTestPhase = 10;
dspParam.cpeAlgSelect = 'VVPE';
refBitsOfflineX = [];
refBitsOfflineY = [];
% Start main loop
for RUN = 1 : MAX_RUN_NUMBER
% Binary source for a new frame
bitsX = randi([0 1],bitpersym,symperframe);
bitsY = randi([0 1],bitpersym,symperframe);
% fifo
[buffer.txBitsX] = fifo_buffer(buffer.txBitsX,bitsX);
[buffer.txBitsY] = fifo_buffer(buffer.txBitsY,bitsY);
% offline mode; take the center frame as the reference
if DSP_MODE == 0
refBitsOfflineX = [refBitsOfflineX buffer.txBitsX(:,(1 : symperframe) + symperframe)];
refBitsOfflineY = [refBitsOfflineY buffer.txBitsY(:,(1 : symperframe) + symperframe)];
elseif DSP_MODE == 1
refBitsX = buffer.txBitsX(:,1 : symperframe);
refBitsY = buffer.txBitsY(:,1 : symperframe);
end
% Bit mapping
% convert bits to syms
txBaudX = symbolizer_mqam(buffer.txBitsX);
txBaudY = symbolizer_mqam(buffer.txBitsY);
% polarizationAnalyzer(txBaudX.',txBaudY.','o-');
% TX laser
% generate new phase noise for the new frame
tmpPN = phase_noise(samplesPerFrame, txLaser.phaseNoiseVar, buffer.txPhaseNoise(end));
% fifo
buffer.txPhaseNoise = fifo_buffer(buffer.txPhaseNoise, tmpPN);
% buffer laser RIN is really defined as one-sided power variance
% generate new rin for new frame
tmpRIN = gaussian_noise(1, samplesPerFrame, idbw(txLaser.RIN) * (txLaser.power.^2) * (0.5 * sampling_freq), 'linear', 'real');
% fifo
buffer.txLaserRIN = fifo_buffer(buffer.txLaserRIN, tmpRIN);
if ctrlParam.doPlot
pltIndex = 1:500;
figure(FIG_TXPN); plot(tmpPN(pltIndex)); grid on; title('Tx Phase Noise');
end
% laser on
if ctrlParam.addLaserRIN
if ctrlParam.addLaserPN
txLaser.wfm = sqrt(txLaser.power + buffer.txLaserRIN) .* exp(1j * buffer.txPhaseNoise);
else
txLaser.wfm = sqrt(txLaser.power + buffer.txLaserRIN);
end
else
if ctrlParam.addLaserPN
txLaser.wfm = sqrt(txLaser.power) .* exp(1j * buffer.txPhaseNoise);
else
txLaser.wfm = sqrt(txLaser.power) * ones(1,nsamples);
end
end
% if ctrlParam.doPlot
% figure(FIG_TXLASER); plot(abs(txLaser(pltIndex).^2)); grid on; title('Tx laser power waveform');
% end
% Driver
% normalize
txBaudRealX = real(txBaudX) / (sqrt(ALPHABET_SIZE)-1);
txBaudImagX = imag(txBaudX) / (sqrt(ALPHABET_SIZE)-1);
txBaudRealY = real(txBaudY) / (sqrt(ALPHABET_SIZE)-1);
txBaudImagY = imag(txBaudY) / (sqrt(ALPHABET_SIZE)-1);
% Pulse shaping
% DAC - simple oversampling by inserting zeros
txDrvIxUps = upsampling(txBaudRealX, samplePerSymbol, 1);
txDrvQxUps = upsampling(txBaudImagX, samplePerSymbol, 1);
txDrvIyUps = upsampling(txBaudRealY, samplePerSymbol, 1);
txDrvQyUps = upsampling(txBaudImagY, samplePerSymbol, 1);
% filtering
txDrvIxWfm = real(ifft(fft(txDrvIxUps) .* txPulseShapeFilter.freqRespRRC));
txDrvQxwfm = real(ifft(fft(txDrvQxUps) .* txPulseShapeFilter.freqRespRRC));
txDrvIyWfm = real(ifft(fft(txDrvIyUps) .* txPulseShapeFilter.freqRespRRC));
txDrvQyWfm = real(ifft(fft(txDrvQyUps) .* txPulseShapeFilter.freqRespRRC));
% plotEyeDiagram(txDrvIxWfm, 2*sampling_freq/baudrate, 'e');
% pre-distortion
if ctrlParam.doMzmComp
txDrvIxWfm = asin(txDrvIxWfm) * modulator.Vpi /pi;
txDrvQxwfm = asin(txDrvQxwfm) * modulator.Vpi /pi;
txDrvIyWfm = asin(txDrvIyWfm) * modulator.Vpi /pi;
txDrvQyWfm = asin(txDrvQyWfm) * modulator.Vpi /pi;
else
txDrvIxWfm = (txDrvIxWfm * modulator.efficiency) * modulator.Vpi /pi;
txDrvQxwfm = (txDrvQxwfm * modulator.efficiency) * modulator.Vpi /pi;
txDrvIyWfm = (txDrvIyWfm * modulator.efficiency) * modulator.Vpi /pi;
txDrvQyWfm = (txDrvQyWfm * modulator.efficiency) * modulator.Vpi /pi;
end
% MZM non-linear pre-comp
% *add MZM nonlinearity pre-comp. here...*
% MZM
V1 = - modulator.Vpi / 2;
V2 = - modulator.Vpi / 2;
V3 = + modulator.Vpi / 2;
% the nonlinear transfer function of MZM will degradate the matched
% filtering
txOptSigX = oeModIqNested(txLaser.wfm, txDrvIxWfm, txDrvQxwfm, modulator.extRatio, modulator.Vpi, V1, V2, V3);
txOptSigY = oeModIqNested(txLaser.wfm, txDrvIyWfm, txDrvQyWfm, modulator.extRatio, modulator.Vpi, V1, V2, V3);
% plotEyeDiagram(txOptSigX, 2*sampling_freq/baudrate, 'o');
% OSNR
% here goes an OSNR emulator
% Fiber channel
if ~ ctrlParam.doRndPMD % if random birefrigence is switched off, use simple model
% convert osnr to snr per sample (oversampling)
SNR = osnr2snr(OSNR, baudrate, samplePerSymbol, 'complex');
% snr per symbol is much higher than snr oversampling
vM.SNR = SNR + dbw(samplePerSymbol);
vM.OSNR = OSNR;
% calc noise power, pulse-shaping is power perserving
sigPowXdb = dbw(calcrms(txOptSigX).^2);
sigPowYdb = dbw(calcrms(txOptSigY).^2);
noisePowerx = idbw(sigPowXdb - SNR);
noisePowery = idbw(sigPowYdb - SNR);
% generate new noise for new frame
channelNoiseX = gaussian_noise(1, samplesPerFrame, noisePowerx, 'linear', 'complex');
channelNoiseY = gaussian_noise(1, samplesPerFrame, noisePowery, 'linear', 'complex');
% fifo
buffer.channelNoiseX = fifo_buffer(buffer.channelNoiseX, channelNoiseX);
buffer.channelNoiseY = fifo_buffer(buffer.channelNoiseY, channelNoiseY);
% add noise
if ctrlParam.addASE
txOptSigX = txOptSigX + buffer.channelNoiseX(:);
txOptSigY = txOptSigY + buffer.channelNoiseY(:);
end
% fiber
lk_rotjump = mod(fiber.rotSpeed * timeVectorAbs, 2*pi);
lk_theta = fiber.initPolAngle + lk_rotjump;
% fiber.initPolAngle = lk_theta(nsamples);
if ctrlParam.addPolarRot % rotate device only if polarization rotation is on
tmpOptSigX = txOptSigX .* cos(lk_theta) - txOptSigY .* sin(lk_theta);
tmpOptSigY = txOptSigX .* sin(lk_theta) + txOptSigY .* cos(lk_theta);
else
tmpOptSigX = txOptSigX;
tmpOptSigY = txOptSigY;
end
if ctrlParam.addCD
[HCD] = calcDispResponse(nsamples, sampling_freq, centerWave, centerWave, fiber.DL, fiber.SL);
tmpOptSigX = ifft(fft(tmpOptSigX) .* HCD);
tmpOptSigY = ifft(fft(tmpOptSigY) .* HCD);
end
if ctrlParam.addPMD
tmpOptSigX = ifft(fft(tmpOptSigX) .* exp(-1i * 2 * pi * freqVector * (+ lk_DGD / 2)) .* exp(-1i * 2 * pi * uv_fc * (+ lk_DGD / 2)));
tmpOptSigY = ifft(fft(tmpOptSigY) .* exp(-1i * 2 * pi * freqVector * (- lk_DGD / 2)) .* exp(-1i * 2 * pi * uv_fc * (- lk_DGD / 2)));
end
if ctrlParam.addPolarRot % rotate back only if polarization rotation is on
tmpOptSigX = tmpOptSigX.*cos(-lk_theta) - tmpOptSigY.*sin(-lk_theta);
tmpOptSigY = tmpOptSigX.*sin(-lk_theta) + tmpOptSigY.*cos(-lk_theta);
end
if ctrlParam.addPolarRot % add endless rotation
tmpOptSigX = tmpOptSigX .* cos(lk_theta) - tmpOptSigY .* sin(lk_theta);
tmpOptSigY = tmpOptSigX .* sin(lk_theta) + tmpOptSigY .* cos(lk_theta);
% update absolute time
timeVectorAbs = ((0 : nsamples-1)' + samplesPerFrame) / sampling_freq;
lk_rotjump = mod(fiber.rotSpeed * timeVectorAbs, 2*pi);
end
else % if random birefrigence is on, use SSF model
% set initial OSNR
tmpOptSigX = txOptSigX;
tmpOptSigY = txOptSigY;
% fiber input power control
end
rxOptSigX = tmpOptSigX;
rxOptSigY = tmpOptSigY;
if ctrlParam.doPlot
% plot spectrum before and after fiber
spectrum_analyzer(txOptSigX, freqVector);
spectrum_analyzer(rxOptSigX, freqVector);
end
% RX laser
% polarization control
loJonesVector = jones_vector(rxLaser.azimuth, rxLaser.ellipticity);
% generate new phase noise for new frame
tmpPN = phase_noise(samplesPerFrame, rxLaser.phaseNoiseVar, buffer.rxPhaseNoise(end));
% fifo
buffer.rxPhaseNoise = fifo_buffer(buffer.rxPhaseNoise, tmpPN);
% buffer laser rin
tmpRIN = gaussian_noise(1, samplesPerFrame, idbw(rxLaser.psdRIN) * (rxLaser.power.^2) * (sampling_freq / 2), 'linear', 'real');
buffer.rxLaserRIN = fifo_buffer(buffer.rxLaserRIN, tmpRIN);
% laser on
if ctrlParam.addLaserRIN
if ctrlParam.addLaserPN
rxLaser.wfm = sqrt(rxLaser.power + buffer.rxLaserRIN) .* exp(1i * buffer.rxPhaseNoise);
else
rxLaser.wfm = sqrt(rxLaser.power + buffer.rxLaserRIN);
end
else
if ctrlParam.addLaserPN
rxLaser.wfm = sqrt(rxLaser.power) .* exp(1i * buffer.rxPhaseNoise);
else
rxLaser.wfm = sqrt(rxLaser.power) * ones(1, length(buffer.rxLaserRIN));
end
end
% control the polarization
rxLaser.wfm = loJonesVector * sqrt(abs(rxLaser.wfm).^2) .* [sign(rxLaser.wfm); sign(rxLaser.wfm)];
% PBS / PBC
loLaserPx = sqrt(receiver.pbcPowerSplitRatio) * exp(-1i * receiver.pbcPhaseRetard) * rxLaser.wfm(1,:).';
loLaserPy = sqrt(1 - receiver.pbcPowerSplitRatio) * rxLaser.wfm(2,:).';
% Hybrid
hybrid90 = deg2rad(HYBRID_90_PHASESHIFT);
switch DETECTION_MODE
case 'HOM'
if ctrlParam.addFreqOffset
xRealP = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* loLaserPx;
xRealN = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* -loLaserPx;
xImagP = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* exp(1i * hybrid90) .* loLaserPx;
xImagN = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* -exp(1i * hybrid90) .* loLaserPx;
yRealP = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* loLaserPy;
yRealN = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* -loLaserPy;
yImagP = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* exp(1i * hybrid90) .* loLaserPy;
yImagN = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* -exp(1i * hybrid90) .* loLaserPy;
else
xRealP = rxOptSigX + loLaserPx;
xRealN = rxOptSigX - loLaserPx;
xImagP = rxOptSigX + exp(1i * hybrid90) .* loLaserPx;
xImagN = rxOptSigX - exp(1i * hybrid90) .* loLaserPx;
yRealP = rxOptSigY + loLaserPy;
yRealN = rxOptSigY - loLaserPy;
yImagP = rxOptSigY + exp(1i * hybrid90) .* loLaserPy;
yImagN = rxOptSigY - exp(1i * hybrid90) .* loLaserPy;
end
case 'HET'
if ctrlParam.addFreqOffset
xHetP = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* loLaserPx;
xHetN = rxOptSigX + exp(1i * 2*pi * freqOffset * timeVector) .* -loLaserPx;
yHetP = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* loLaserPy;
yHetN = rxOptSigY + exp(1i * 2*pi * freqOffset * timeVector) .* -loLaserPy;
else
xHetP = rxOptSigX + loLaserPx;
xHetN = rxOptSigX - loLaserPx;
yHetP = rxOptSigY + loLaserPy;
yHetN = rxOptSigY - loLaserPy;
end
otherwise
warning('detection mode not supported'); keyboard;
end
% Photo detector
% dark current
IpdDark = receiver.detectorDarkCurrent;
switch DETECTION_MODE
case 'HOM'
% square law detection
V1 = receiver.detectorResponsivity .* abs(xRealP).^2;
V2 = receiver.detectorResponsivity .* abs(xRealN).^2;
V3 = receiver.detectorResponsivity .* abs(xImagP).^2;
V4 = receiver.detectorResponsivity .* abs(xImagN).^2;
V5 = receiver.detectorResponsivity .* abs(yRealP).^2;
V6 = receiver.detectorResponsivity .* abs(yRealN).^2;
V7 = receiver.detectorResponsivity .* abs(yImagP).^2;
V8 = receiver.detectorResponsivity .* abs(yImagN).^2;
if ctrlParam.addThermNoise
IpdThermal1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
IpdThermal2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
IpdThermal3 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
IpdThermal4 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
else
IpdThermal1 = 0;
IpdThermal2 = 0;
IpdThermal3 = 0;
IpdThermal4 = 0;
end
if ctrlParam.addShotNoise
IpdShot1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
IpdShot2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
IpdShot3 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
IpdShot4 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
else
IpdShot1 = 0;
IpdShot2 = 0;
IpdShot3 = 0;
IpdShot4 = 0;
end
if ctrlParam.addRIN
IpdRIN1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
IpdRIN2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
IpdRIN3 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
IpdRIN4 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
else
IpdRIN1 = 0;
IpdRIN2 = 0;
IpdRIN3 = 0;
IpdRIN4 = 0;
end
if ctrlParam.doBalanced
pd_xi = V1 - V2 + IpdThermal1 + IpdShot1 + IpdDark + IpdRIN1;
pd_xq = V3 - V4 + IpdThermal2 + IpdShot2 + IpdDark + IpdRIN2;
pd_yi = V5 - V6 + IpdThermal3 + IpdShot3 + IpdDark + IpdRIN3;
pd_yq = V7 - V8 + IpdThermal4 + IpdShot4 + IpdDark + IpdRIN4;
else
pd_xi = V1 + IpdThermal1 + IpdShot1 + IpdDark;
pd_xq = V3 + IpdThermal2 + IpdShot2 + IpdDark;
pd_yi = V5 + IpdThermal3 + IpdShot3 + IpdDark;
pd_yq = V7 + IpdThermal4 + IpdShot4 + IpdDark;
end
% match filtering
pd_xi = real(ifft(fft(pd_xi) .* rxPulseShapeFilter.freqRespRRC));
pd_xq = real(ifft(fft(pd_xq) .* rxPulseShapeFilter.freqRespRRC));
pd_yi = real(ifft(fft(pd_yi) .* rxPulseShapeFilter.freqRespRRC));
pd_yq = real(ifft(fft(pd_yq) .* rxPulseShapeFilter.freqRespRRC));
case 'HET'
% square law detection
V1 = receiver.detectorResponsivity .* abs(xHetP).^2;
V2 = receiver.detectorResponsivity .* abs(xHetN).^2;
V5 = receiver.detectorResponsivity .* abs(yHetP).^2;
V6 = receiver.detectorResponsivity .* abs(yHetN).^2;
if ctrlParam.addThermNoise
IpdThermal1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
IpdThermal2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdThermal, 'linear', 'real');
else
IpdThermal1 = 0;
IpdThermal2 = 0;
end
if ctrlParam.addShotNoise
IpdShot1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
IpdShot2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdShot, 'linear', 'real');
else
IpdShot1 = 0;
IpdShot2 = 0;
end
if ctrlParam.addRIN
IpdRIN1 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
IpdRIN2 = gaussian_noise(size(V1,1), size(V1,2), receiver.psdRIN, 'linear', 'real');
else
IpdRIN1 = 0;
IpdRIN2 = 0;
end
if ctrlParam.doBalanced % balanced detection
pd_xi = V1 - V2 + IpdDark + IpdThermal1 + IpdShot1 + IpdRIN1;
pd_yi = V3 - V4 + IpdDark + IpdThermal2 + IpdShot2 + IpdRIN2;
else
pd_xi = V1 + IpdDark + IpdThermal1 + IpdShot1;
pd_yi = V3 + IpdDark + IpdThermal2 + IpdShot2;
end
% low-pass filtering
pd_xi = real(ifft(fft(pd_xi) .* rxPulseShapeFilter.freqRespBessel));
pd_yi = real(ifft(fft(pd_yi) .* rxPulseShapeFilter.freqRespBessel));
otherwise
warning('detection mode not supported'); keyboard;
end
if ctrlParam.doPlot
plotEyeDiagram(pd_xi, sampling_freq / baudrate, 'e');
title('Real part of signal after photodetector');
end
% add electrical spectrum
% keyboard;
% ADC
% ad_head = round(samplePerSymbol/2);
ad_head = 1;
ad_sps_sim = samplePerSymbol;
% need a realistic sampling rate
switch DETECTION_MODE
case 'HOM'
adc1 = pd_xi(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
adc2 = pd_xq(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
adc3 = pd_yi(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
adc4 = pd_yq(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
case 'HET'
adc1 = pd_xi(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
adc2 = pd_yi(ad_head : ad_sps_sim/ADC_SAMPLING_RATE : end);
otherwise
warning('detection mode not supported'); keyboard;
end
% also need a ENOB
% add timing jitter here
% dsp
if DSP_MODE == 0
%
% go offline
%
adc_out_len = length(adc1);
% push only the center frame to the memory
memory1 = [memory1; adc1(adc_out_len / FRAME_WINDOW + 1 : end - adc_out_len / FRAME_WINDOW, 1)];
memory2 = [memory2; adc2(adc_out_len / FRAME_WINDOW + 1 : end - adc_out_len / FRAME_WINDOW, 1)];
memory3 = [memory3; adc3(adc_out_len / FRAME_WINDOW + 1 : end - adc_out_len / FRAME_WINDOW, 1)];
memory4 = [memory4; adc4(adc_out_len / FRAME_WINDOW + 1 : end - adc_out_len / FRAME_WINDOW, 1)];
dspMemCount = dspMemCount + 1;
if dspMemCount == DSO_MEMORY_LENGTH
fprintf('In total %d frames are captured in the memory\n', dspMemCount);
break;
end
elseif DSP_MODE == 1
%
% go real-time
%
dspout1 = adc1 + 1i * adc2;
dspout2 = adc3 + 1i * adc4;
dspout1 = dspout1(1 : 2 : end);
dspout2 = dspout2(1 : 2 : end);
end
% Decision
if DSP_MODE == 1
de_x = normalization(dspout1, ALPHABET_SIZE);
de_y = normalization(dspout2, ALPHABET_SIZE);
bit1 = slicer_mqam(de_x, ALPHABET_SIZE);
bit2 = slicer_mqam(de_y, ALPHABET_SIZE);
biterr = nnz(bit1(:, 1 : symperframe) - refBitsX) ...
+ nnz(bit2(:, 1 : symperframe) - refBitsY);
fprintf('run # %d\t error count # %d\n', RUN, biterr);
end
end %% End of main loop
% this is the end of main loop <--------------
% this is the end of main loop <--------------
% this is the end of main loop <--------------
% Offline DSP
if VERBOSE
fprintf('Starting DSP...\n');
end
[dspout1, dspout2] = dsp_main(memory1, memory2, memory3, memory4, dspParam);
h1 = figure(34); plot(dspout1,'.'); grid on;
h2 = figure(35); plot(dspout2,'.'); grid on;
mngFigureWindow(h1, h2);
bit1 = slicer_mqam(dspout1, ALPHABET_SIZE);
bit2 = slicer_mqam(dspout2, ALPHABET_SIZE);
berx = sum(sum(abs(bit1 - refBitsOfflineX))) / numel(bit1);
bery = sum(sum(abs(bit2 - refBitsOfflineY))) / numel(bit2);
if VERBOSE
fprintf('BER x = %.2e \n', berx);
fprintf('BER y = %.2e \n', bery);
end
vM.BER = 0.5 * (berx + bery);
vM.BER_Theo = snr2ber(vM.SNR, bitpersym, 'dB');
if vM.BER < vM.BER_Theo
warning('SANITY CHECK: Break BER limit, %.2E (%.2E in theory)', vM.BER, vM.BER_Theo);
end
return