00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef _OCS_ELEC_SIGNAL_STAT_HH_
00015 #define _OCS_ELEC_SIGNAL_STAT_HH_
00016
00017 #include "ocsBitString.hh"
00018 #include "ocsOptSignal.hh"
00019 #include "ocsPhotodetector.hh"
00020 #include "ocsOptFilter.hh"
00021 #include "ocsElecFilter.hh"
00022 #include "ocsTools.hh"
00023
00024
00043 enum typeClockRecovery { USER_SET = 0,
00044 FREQ_DOUBLING = 1,
00045 RZ_SIGNAL_FREQ = 2,
00046 NRZ_HALF_SIGNAL_FREQ = 3,
00047 BEST_Q_FACTOR = 4,
00048 DIFFERENTIATE_SIGNAL = 5,
00049 CONTINUOUS_EXOR = 6,
00050 BINARY_EXOR = 7,
00051 BEST_MIN_EYE_OPENING = 8 };
00052
00053
00058
00087 class ElecSignalStat
00088 {
00089 public:
00090
00092
00093 ElecSignalStat(OptSignal * oOptSignal2,
00094 Photodetector *oPhotodetector2);
00095
00096
00098
00107 ElecSignalStat(string InFileName,OptSignal *oOptSignal2,
00108 Photodetector *oPhotodetector2);
00109
00110 ~ElecSignalStat(void);
00111
00115
00116 void SetUseAbsCurrentFlag(bool Value);
00117
00119
00120 string WriteTypeClockRecovery(void);
00121
00124
00125 void ClearElecSignalStat(void);
00126
00127 void ClearGaussianPDFsMonteCarlo(void);
00128
00133
00134 void ComputePerformanceStatistics(void);
00135
00141
00142 void UpdatePerformanceStatistics(void);
00143
00147
00148 void ComputeEqualizedPerformanceStatistics(void);
00149
00153
00154 void UpdateEqualizedPerformanceStatistics(void);
00155
00156 cplx *GetSignalTimeDomain(void) {return sfftPM.tPowerSignal;};
00157
00158 int GetBitFromString(int ii){return oOptSignal->oBitString->GetBit(0,ii);};
00159
00163
00164 double GetMinAmplitudeMargin();
00165
00168
00169 void WriteFileEyeDiagram(string outFile);
00170
00173
00174 void WriteFileEyeDiagramFixedCLK(string outFile);
00175
00178
00179 double GetClockRecoveryTime(void)
00180 {return ClockRecoveryTime=GetTargetTime();};
00181
00183
00184 double GetClockRecoveryTimeBeforeTimeShift(void)
00185 { return ClockRecoveryTimeBeforeTimeShift;};
00186
00189
00190 double GetClockTimeForMonteCarloEye(void);
00191
00192 double GetClockCurrent(void);
00193
00208
00209 void OutputGaussianStatisticsFromMonteCarlo(string FileID);
00210 void SetTimeSlices(void);
00211 void ComputeAndOutputMomentsFromMonteCarlo(string FileID);
00212 void ComputeAveragePDFs(void);
00213 void WriteFilePDFTimeSlicesAndAveragePDFs(string FileID);
00214 void ComputeMinimumBERAndDecisionThreshold(string FileID);
00215 void WriteFilePairVectors(double * x, double *y, int dim,
00216 string OutFileName);
00217
00220
00221 double GetPowerMeanBit(int BitIndex);
00222
00223
00224
00229
00230 double GetPowerStdDevBit(int BitIndex);
00231
00232
00235
00236 double GetQtBit0(void) {return qtBit0;};
00237
00240
00241 double GetQtBit1(void) {return qtBit1;};
00242
00245
00246 double GetBit0_PowerMax(void) {return Bit0_PowerMax;};
00247
00250
00251
00252 double GetBit1_PowerMin(void) {return Bit1_PowerMin;};
00253
00257
00258 double GetBit0_PowerMean(void)
00259 {return Bit0_PowerSum/qtBit0;};
00260
00264
00265 double GetBit1_PowerMean(void)
00266 {return Bit1_PowerSum/qtBit1;};
00267
00271
00272 double GetBit0_PowerStdDev(void)
00273 {return sqrt( (Bit0_PowerSquareSum
00274 -qtBit0*sq(GetBit0_PowerMean()))
00275 /(qtBit0 - 1.) );};
00276
00280
00281
00282 double GetBit1_PowerStdDev(void)
00283 {return sqrt( (Bit1_PowerSquareSum
00284 -qtBit1*sq(GetBit1_PowerMean()))
00285 /(qtBit1 - 1.) );};
00286
00287 double GetElecTimeDomainSNR(void)
00288 {return (GetBit1_PowerMean() - GetBit0_PowerMean() )
00289 /GetBit0_PowerMean();};
00290
00294
00295 double GetQ_Factor(void);
00296
00300
00301 double GetBitErrorRate(void) {return
00302 exp(-sq(GetQ_Factor())/2)/(GetQ_Factor()*sqrt(2*pi));};
00303
00306
00307 double GetBitErrorRate(double Q_Factor) {return
00308 exp(-sq(Q_Factor)/2)/(Q_Factor*sqrt(2*pi));};
00309
00310 double GetAmplitudeMargin(void) {return AmplitudeMargin;};
00311
00312 double GetMeanPower(void) {return MeanPower;};
00313
00314 int GetBitStringShift(void) {return BitStringShift;};
00315
00316
00318
00319 double GetQtIsolatedBit0(void) {return qtIsolatedBit0;};
00320 double GetQtIsolatedBit1(void) {return qtIsolatedBit1;};
00321 double GetIsolatedBit0_PowerMax(void) {return IsolatedBit0_PowerMax;};
00322 double GetIsolatedBit1_PowerMin(void) {return IsolatedBit1_PowerMin;};
00323
00324 double GetIsolatedBit0_PowerMean(void)
00325 {return IsolatedBit0_PowerSum/qtIsolatedBit0;};
00326
00327 double GetIsolatedBit1_PowerMean(void)
00328 {return IsolatedBit1_PowerSum/qtIsolatedBit1;};
00329
00330 double GetIsolatedBit0_PowerStdDev(void)
00331 {return sqrt( (IsolatedBit0_PowerSquareSum
00332 -qtIsolatedBit0*sq(GetIsolatedBit0_PowerMean()))
00333 /(qtIsolatedBit0 - 1.) );};
00334
00335 double GetIsolatedBit1_PowerStdDev(void)
00336 {return sqrt( (IsolatedBit1_PowerSquareSum
00337 -qtIsolatedBit1*sq(GetIsolatedBit1_PowerMean()))
00338 /(qtIsolatedBit1 - 1.) );};
00339
00340 double GetElecTimeDomainSNR_IsolatedBits(void)
00341 {return (GetIsolatedBit1_PowerMean() - GetIsolatedBit0_PowerMean() )
00342 /GetIsolatedBit0_PowerMean();};
00343
00344 double GetQ_FactorFromIsolatedBits(void);
00345
00346
00349
00350
00351 void SetOptElecFiltersForGaussianStatistics(
00352 OptFilter *oOptFilter,ElecFilter *oElecFilter);
00353
00359
00360 void ResetOptElecFiltersForGaussianStatistics(void);
00361
00364
00365 void ResetOptElecFilterBandwidthsForGaussianStatistics(
00366 double FreqFWHM_OptFilter2,
00367 double f3dB_ElecFilter2);
00368
00369 void CheckGaussianStatisticsInitialization(string CallingMethod);
00370
00371
00373
00374 double GetMeanNoiseGaussianStatistics(double TotalNoiseSpectralDensity);
00375
00377
00378 double GetNoiseNoiseVarianceGaussianStatistics(
00379 double TotalNoiseSpectralDensity,
00380 double DOP_Noise);
00381
00386
00387 double GetIntegralForNoiseNoiseVarianceGaussianStatistics(void);
00388
00389
00392
00393 double GetSignalNoiseVarianceForUnpolarizedNoiseGaussianStatistics(
00394 double Time,
00395 double TotalNoiseSpectralDensity);
00396
00400
00401 double GetSignalNoiseVarianceForPolarizedSignalGaussianStatistics(
00402 double Time,
00403 double * UnitStokesSignal,
00404 double * UnitStokesNoise,
00405 double TotalNoiseSpectralDensity,
00406 double DOP_Noise);
00407
00412
00413 double GetIntegralForSignalNoiseVariance(OptSignal *OptSignalA,
00414 OptSignal *OptSignalB,
00415 double TimeShiftA, double TimeShiftB, double Time);
00416
00417
00418 double GetEnhancementFactor(double OSA_NoiseBandwidth);
00419 double GetNormalizedEnhancementFactor(void);
00420
00421 double GetESNR_Mark_GaussianStatistics(double NoiseSpectralDensity);
00422
00423 double GetESNR_GaussianStatistics(double NoiseSpectralDensity);
00424 double GetNormKcoeff1_GaussianStatistics(void);
00425 double GetNormKcoeff0_GaussianStatistics(void);
00426 double GetNormNumberNoiseModes_GaussianStatistics(void);
00427 double GetCurrentExtinctionRatio_GaussianStatistics(void);
00428 double GetQ_FactorFromESNR_GaussianStatistics( double ESNR);
00429 double GetQ_FactorFromESNR_GaussianStatistics( double ESNR,
00430 double NoiseSpectralDensityX,
00431 double NoiseSpectralDensityY);
00432
00433
00434 double GetQ_FactorGaussianStatisticsWorstPattern(
00435 double NoiseSpectralDensity);
00436 double GetQ_FactorGaussianStatisticsWorstPattern(
00437 double NoiseSpectralDensityX,double NoiseSpectralDensityY);
00438
00439 double GetQ_FactorGaussianStatisticsFirstPattern(
00440 double NoiseSpectralDensityX,double NoiseSpectralDensityY);
00441
00443 double GetQ_FactorGaussianStatisticsFromBER(double NoiseSpectralDensity);
00444 double GetQ_FactorGaussianStatisticsFromBER(double NoiseSpectralDensityX,
00445 double NoiseSpectralDensityY);
00446
00447 double GetBER_GaussianStatisticsFromDecisionThreshold(
00448 double DecisionCurrent);
00449 double GetBER_GaussianStatistics(void);
00450 double MinimizeSqQ_FactorVersusBER(double Q_FactorTmp);
00451
00452 double brentHu(double ax, double bx, double cx, double (*f)(double),
00453 double tol,double *xmin);
00454
00455 double testsq(double ax);
00456
00457
00458 double GetMeanASE_ASE(double NoiseSpectralDensity);
00459 double GetMeanASE_ASE(double NoiseSpectralDensityX,
00460 double NoiseSpectralDensityY);
00461
00462 double GetStdDevASE_ASE(double NoiseSpectralDensity);
00463 double GetStdDevASE_ASE(double NoiseSpectralDensityX,
00464 double NoiseSpectralDensityY);
00465
00466 double GetStdDevSignal_ASE_BitSlot(int BitSlot,
00467 double NoiseSpectralDensity);
00468 double GetStdDevSignal_ASE_BitSlot(int BitSlot,
00469 double NoiseSpectralDensityX,
00470 double NoiseSpectralDensityY);
00471 double GetStdDevSignal_ASE_TimeIndex(int TargetIndexTime2,
00472 double NoiseSpectralDensityX,
00473 double NoiseSpectralDensityY);
00474
00475
00476 double GetStdDevWorstBit1_GaussianStatistics(double NoiseSpectralDensity);
00477 double GetStdDevWorstBit1_GaussianStatistics(
00478 double NoiseSpectralDensityX,
00479 double NoiseSpectralDensityY);
00480
00481 double GetStdDevWorstBit0_GaussianStatistics(double NoiseSpectralDensity);
00482 double GetStdDevWorstBit0_GaussianStatistics(
00483 double NoiseSpectralDensityX,
00484 double NoiseSpectralDensityY);
00485
00486 double GetMinCurrentBit1(void);
00487 double GetMaxCurrentBit0(void);
00488
00489 double GetMinCurrentBit1(int *BitSlotMinCurrentBit1);
00490 double GetMaxCurrentBit0(int *BitSlotMaxCurrentBit0);
00491
00492
00493 double GetCurrentFirstBit1(int *BitSlotCurrentFirstBit1);
00494 double GetCurrentFirstBit0(int *BitSlotCurrentFirstBit0);
00495
00496 double GetCurrentBitFromRecoveredSignal(int BitSlotCurrentBit);
00497 double GetCurrentBit(int BitSlotCurrentBit);
00498
00499
00500 double GetMeanCurrentIsolatedBit1(void);
00501 double GetMeanCurrentIsolatedBit0(void);
00502
00503 int GetQtPoints(void) {return qtPoints;};
00504 double GetDeltaTime(void) {return DeltaTime;};
00505 int GetBit(int BitSlot) {return oOptSignal->oBitString->GetBit(0,BitSlot);};
00506 double GetBitLength(void) {return BitLength;};
00507 int GetStringLength(void) {return StringLength;};
00508
00509
00510
00511
00512
00513
00515
00519 void InitPatternStats(void);
00520
00522
00523 void AllocateMemoryForPatternStats(void);
00524
00526
00527 void ReleaseMemoryForPatternStats(void);
00528
00530
00535 void ClearPatternStats(void);
00536
00540
00541 void EnumeratePatterns(ofstream * OutFile);
00542
00545
00546
00547 bool GetPattern(int PatternIndex,int BitIndex);
00548
00550
00551 bool GetCenterBitPattern(int PatternIndex);
00552
00555
00556 int GetPatternIndex(bool * LocalPatternArray, int LengthOfPattern);
00557
00559
00571 void UpdatePatternStats(int BitIndex,double PowerElecSignal);
00572
00573
00575
00576 bool PatternEquality(bool * PatternArray1, bool * PatternArray2,
00577 int LengthOfPattern);
00578
00579
00583
00587 void PreparePatternStatsForOutput(void);
00588
00590
00591 void WriteFilePatternStats(string OutFileName);
00592
00593
00594
00595 OptSignal *oOptSignal;
00596 Photodetector *oPhotodetector;
00597 double *BitIntensity;
00598
00599
00600
00601
00602 private:
00603
00604
00605
00606 void InitElecSignalStat(OptSignal * oOptSignal2,
00607 Photodetector *oPhotodetector2);
00608
00609
00613
00614 void ComputePerformanceStatisticsNoTimeShift(void);
00615
00617
00618 void UpdateMoments(int BitIndex,double PowerElecSignal);
00619
00620 void ComputeTargetFreqIndex(void);
00621
00623
00624 int GetTargetIndexTime(void);
00625
00626
00628
00629 double GetTargetTime(void);
00630
00631 double ComputePhaseTargetFreq(void);
00632 int GetTargetIndexTimeBestQ_Factor(void);
00633 int GetTargetIndexTimeBestMinEyeOpening(void);
00634
00636 void UpdateClock(void);
00637
00638
00639
00640 int ObjectInitialized;
00641 bool UseAbsCurrentFlag;
00642
00643 cfftw *fft;
00644 fftPowerMatrices sfftPM;
00645 typePulse TypePulse;
00646 int qtPoints;
00647 int qtPointsLast;
00648 double DeltaTime, TimeWindow;
00649 double DeltaFreq;
00650 int StringLength;
00651 double BitLength;
00652 double BitRateChann;
00653
00654 typeClockRecovery TypeClockRecovery;
00655
00656 int UseSmoothingToRecoverClockFlag;
00657 double GaussianSmoothingFWHM;
00658
00659 int BitStringShift;
00660
00661 double InputClockRecoveryTime;
00662 double ClockRecoveryTime;
00663 double ClockRecoveryTimeBeforeTimeShift;
00664
00665 int TargetFreqIndex;
00666 int FirstTargetIndexTime;
00667 int SumRelTargetIndexTime;
00668
00669 int NumCallsToUpdateClock;
00670 double SumTargetIndexTimesForUpdateClock;
00671
00672 int qtRunsEyeDiagram;
00673 int qtRunsEyeDiagramFixedCLK;
00674
00675 double Q_Factor;
00676 double BitErrorRate;
00677 double AmplitudeMargin;
00678 double MeanPower;
00679
00680 int qtBit0, qtBit1;
00681 double Bit0_PowerSum,Bit1_PowerSum;
00682 double Bit0_PowerSquareSum, Bit1_PowerSquareSum;
00683 double Bit0_PowerMax, Bit1_PowerMin;
00684
00685 int qtIsolatedBit0, qtIsolatedBit1;
00686 double IsolatedBit0_PowerSum,IsolatedBit1_PowerSum;
00687 double IsolatedBit0_PowerSquareSum, IsolatedBit1_PowerSquareSum;
00688 double IsolatedBit0_PowerMax, IsolatedBit1_PowerMin;
00689
00690
00691
00692 bool InitializedGaussianStatisticsFlag;
00693 double *VariancesCurrentSignalNoiseBeating;
00694
00695 OptSignal *oOptSignal1;
00696 OptSignal *oOptSignal2;
00697 OptSignal *oOptSignal3;
00698 OptSignal *oOptSignalX;
00699
00700 OptFilter *oOrigOptFilter;
00701 OptFilter *oOptFilter2;
00702 Photodetector *oPhotodetector2;
00703 ElecFilter *oElecFilter2;
00704
00705 ElecSignalStat *oElecSignalStat2;
00706
00707
00708
00709 OptSignal *oOptSignal4;
00710 OptFilter *oOptFilter4;
00711 Photodetector *oPhotodetector4;
00712 ElecFilter *oElecFilter4;
00713 ElecSignalStat *oElecSignalStat4;
00714 double BER_GaussianStatistics;
00715 double Q_FactorPre;
00716 double NoiseSpectralDensityX_PD;
00717 double NoiseSpectralDensityY_PD;
00718
00719
00720
00721 bool DoGaussianPDFsMonteCarloFlag;
00722 int NumTimeSlices;
00723 double * TimeSlices;
00724 int * TimeSliceIndices;
00725 int * BitString;
00726
00727 double * StdDevCurrentMonteCarlo;
00728 double * MeanCurrentMonteCarlo;
00729
00730 double * PowerSumBit;
00731 double * PowerSquareSumBit;
00732 int * qtBit;
00733
00734 double MinCurrent,MaxCurrent,DeltaCurrent;
00735 int NumPointsCurrent;
00736 double * CurrentVector;
00737
00738 double * BERGaussianPDFs;
00739 double * AverageGaussianPDFZeros;
00740 double * AverageGaussianPDFOnes;
00741 double ** GaussianPDFTimeSlices;
00742 double * GaussianPDFTimeSlicesStorageVec;
00743
00744
00745
00746
00749
00750 bool ComputePatternStatsFlag;
00751
00754
00755 int PatternLength;
00756
00758
00759 int NumPatterns;
00760
00762
00763 bool * PatternArray;
00764
00768
00769
00770 double * MeanPattern;
00771
00776
00777 double * StdDevPattern;
00778
00780
00781 int * NumOccurencesPattern;
00782
00784
00785 double * VoltageSumPattern;
00786
00787
00789
00790 double * VoltageSumSquaresPattern;
00791
00793
00794 double * MaximumVoltagePattern;
00795
00797
00798 double * MinimumVoltagePattern;
00799
00800 };
00801
00802 #endif