760 const std::string &psdDir,
765 realT lpRegPrecision,
766 std::vector<realT> &mags,
768 bool uncontrolledLifetimes,
773 std::string dir = psdDir +
"/" + subDir;
776 mkdir( dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
779 std::string fn = dir +
'/' +
"params.txt";
782 fout <<
"#---------------------------\n";
783 m_aosys->dumpAOSystem( fout );
784 fout <<
"#---------------------------\n";
785 fout <<
"# Analysis Parameters\n";
786 fout <<
"# mnMax = " << mnMax <<
'\n';
787 fout <<
"# mnCon = " << mnCon <<
'\n';
788 fout <<
"# lpNc = " << lpNc <<
'\n';
790 for(
size_t i = 0; i < mags.size() - 1; ++i )
791 fout << mags[i] <<
",";
792 fout << mags[mags.size() - 1] <<
'\n';
793 fout <<
"# lifetimeTrials = " << lifetimeTrials <<
'\n';
794 fout <<
"# uncontrolledLifetimes = " << uncontrolledLifetimes <<
'\n';
795 fout <<
"# writePSDs = " << std::boolalpha << writePSDs <<
'\n';
796 fout <<
"# writeXfer = " << std::boolalpha << writeXfer <<
'\n';
802 realT fs = 1.0 / m_aosys->tauWFS();
803 realT tauWFS = m_aosys->tauWFS();
804 realT deltaTau = m_aosys->deltaTau();
806 std::vector<sigproc::fourierModeDef> fms;
809 size_t nModes = 0.5 * fms.size();
811 Eigen::Array<
realT, -1, -1> gains, vars, speckleLifetimes, gains_lp, vars_lp, speckleLifetimes_lp;
813 gains.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
814 vars.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
815 speckleLifetimes.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
817 gains( mnMax, mnMax ) = 0;
818 vars( mnMax, mnMax ) = 0;
819 speckleLifetimes( mnMax, mnMax ) = 0;
821 gains_lp.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
822 vars_lp.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
823 speckleLifetimes_lp.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
825 gains_lp( mnMax, mnMax ) = 0;
826 vars_lp( mnMax, mnMax ) = 0;
827 speckleLifetimes_lp( mnMax, mnMax ) = 0;
832 Eigen::Array<
realT, -1, -1> lpC;
836 lpC.resize( nModes, lpNc );
840 std::vector<realT> S_si, S_lp;
844 for(
size_t s = 0; s < mags.size(); ++s )
847 mkdir( psdOutDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
852 mkdir( psdOutDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
857 m_aosys->beta_p( 1, 1 );
861 for(
size_t s = 0; s < mags.size(); ++s )
863 m_aosys->starMag( mags[s] );
867 realT opticalGain{ 1.0 };
873 realT ncp = m_aosys->ncp_wfe();
874 m_aosys->ncp_wfe( 0 );
876 realT lam_sci = m_aosys->lam_sci();
877 m_aosys->lam_sci( m_aosys->lam_wfs() );
879 realT S = m_aosys->strehl();
880 std::cerr << S <<
"\n";
882 for(
int s = 0; s < 4; ++s )
884 m_aosys->opticalGain( S );
885 m_aosys->optd( m_aosys->optd() );
886 S = m_aosys->strehl();
887 std::cerr << S <<
"\n";
892 m_aosys->lam_sci( lam_sci );
893 m_aosys->ncp_wfe( ncp );
896 m_aosys->optd( m_aosys->optd() );
897 realT strehl = m_aosys->strehl();
901 realT localMag = mags[s];
907 realT gopt_lp, var_lp;
909 std::vector<realT> tfreq;
910 std::vector<realT> tPSDp;
914 std::vector<realT> tfreqHF;
915 std::vector<realT> tPSDpHF;
919 getGridPSD( tfreq, tPSDp, psdDir, 0, 1 );
922 while( tfreq[imax] <= 0.5 * fs )
925 if( imax > tfreq.size() - 1 )
929 if( imax < tfreq.size() - 1 && tfreq[imax] <= 0.5 * fs * ( 1.0 + 1e-7 ) )
936 tfreqHF.assign( tfreq.begin(), tfreq.end() );
939 tfreq.erase( tfreq.begin() + imax, tfreq.end() );
941 tPSDpPOL.resize( tfreq.size() );
944 std::vector<realT> tPSDn;
945 tPSDn.resize( tfreq.size() );
949 tflp.m_precision0 = lpRegPrecision;
967 std::vector<std::complex<realT>> ETFxn;
968 std::vector<std::complex<realT>> NTFxn;
970 if( lifetimeTrials > 0 )
972 ETFxn.resize( tfreq.size() );
973 NTFxn.resize( tfreq.size() );
998#pragma omp for schedule( dynamic, 5 )
999 for(
size_t i = 0; i < nModes; ++i )
1005 if( fabs( (
realT)m / m_aosys->D() ) >= m_aosys->spatialFilter_ku() ||
1006 fabs( (
realT)n / m_aosys->D() ) >= m_aosys->spatialFilter_kv() )
1008 gains( mnMax + m, mnMax + n ) = 0;
1009 gains( mnMax - m, mnMax - n ) = 0;
1011 gains_lp( mnMax + m, mnMax + n ) = 0;
1012 gains_lp( mnMax - m, mnMax - n ) = 0;
1014 vars( mnMax + m, mnMax + n ) = 0;
1015 vars( mnMax - m, mnMax - n ) = 0;
1017 vars_lp( mnMax + m, mnMax + n ) = 0;
1018 vars_lp( mnMax - m, mnMax - n ) = 0;
1019 speckleLifetimes( mnMax + m, mnMax + n ) = 0;
1020 speckleLifetimes( mnMax - m, mnMax - n ) = 0;
1021 speckleLifetimes_lp( mnMax + m, mnMax + n ) = 0;
1022 speckleLifetimes_lp( mnMax - m, mnMax - n ) = 0;
1027 realT k = sqrt( m * m + n * n ) / m_aosys->D();
1030 getGridPSD( tPSDp, psdDir, m, n );
1037 tPSDpHF.assign( tPSDp.begin() + imax, tPSDp.end() );
1041 tPSDp.erase( tPSDp.begin() + imax, tPSDp.end() );
1048 if( m_uncorrectedOG )
1050 for(
size_t n = 0; n < tPSDp.size(); ++n )
1052 tPSDpPOL[n] = tPSDp[n] * pow( opticalGain, 2 );
1057 for(
size_t n = 0; n < tPSDp.size(); ++n )
1059 tPSDpPOL[n] = tPSDp[n];
1065 bool inside =
false;
1067 if( m_aosys->circularLimit() )
1069 if( m * m + n * n <= mnCon * mnCon )
1074 if( fabs( m ) <= mnCon && fabs( n ) <= mnCon )
1085 wfsNoisePSD<realT>( tPSDn,
1086 m_aosys->beta_p( m, n ) / sqrt( opticalGain ),
1087 m_aosys->Fg( localMag ),
1089 m_aosys->npix_wfs( (
size_t)0 ),
1090 m_aosys->Fbg( (
size_t)0 ),
1091 m_aosys->ron_wfs( (
size_t)0 ) );
1097 var = go_si.
clVariance( tPSDp, tPSDn, gopt );
1104 if( m_uncorrectedOG )
1106 gopt *= opticalGain;
1110 var = go_si.
clVariance( tPSDp, tPSDn, gopt );
1150 <<
"fourierTemporalPSD::analyzePSDGrid: regularizeCoefficients returned error ";
1151 std::cerr << rv <<
' ';
1152 std::cerr << __FILE__ <<
' ' << __LINE__ <<
'\n';
1155 for(
int n = 0; n < lpNc; ++n )
1157 lpC( i, n ) = go_lp.
a( n );
1160 if( m_uncorrectedOG )
1162 go_lp.aScale( opticalGain );
1163 go_lp.bScale( opticalGain );
1164 gopt_lp *= opticalGain;
1167 var_lp = go_lp.
clVariance( tPSDp, tPSDn, gopt_lp );
1178 tPSDn.assign( tPSDn.size(), 0.0 );
1184 go_lp.
a( std::vector<realT>( { 1 } ) );
1185 go_lp.
b( std::vector<realT>( { 1 } ) );
1190 if( gopt > 0 && var > var0 )
1196 if( gopt_lp > gopt && var_lp > var )
1201 go_lp.
a( std::vector<realT>( { 1 } ) );
1202 go_lp.
b( std::vector<realT>( { 1 } ) );
1207 gains( mnMax + m, mnMax + n ) = gopt;
1208 gains( mnMax - m, mnMax - n ) = gopt;
1210 gains_lp( mnMax + m, mnMax + n ) = gopt_lp;
1211 gains_lp( mnMax - m, mnMax - n ) = gopt_lp;
1213 vars( mnMax + m, mnMax + n ) = var;
1214 vars( mnMax - m, mnMax - n ) = var;
1216 vars_lp( mnMax + m, mnMax + n ) = var_lp;
1217 vars_lp( mnMax - m, mnMax - n ) = var_lp;
1221 if( ( lifetimeTrials > 0 || writeXfer ) && ( uncontrolledLifetimes || inside ) )
1223 std::vector<realT> spfreq, sppsd;
1227 for(
size_t i = 0; i < tfreq.size(); ++i )
1229 ETFxn[i] = go_si.
clETF( i, gopt );
1230 NTFxn[i] = go_si.
clNTF( i, gopt );
1235 for(
size_t i = 0; i < tfreq.size(); ++i )
1244 std::string tfOutFile =
1257 std::string fOutFile = tfOutFile +
"freq.binv";
1262 if( lifetimeTrials > 0 )
1264 speckleAmpPSD( spfreq, sppsd, tfreq, tPSDp, ETFxn, tPSDn, NTFxn, lifetimeTrials );
1267 realT splifeT = 100.0;
1270 realT tau = pvm(
error, spfreq, sppsd, splifeT ) * ( splifeT ) / spvar;
1272 speckleLifetimes( mnMax + m, mnMax + n ) = tau;
1273 speckleLifetimes( mnMax - m, mnMax - n ) = tau;
1280 for(
size_t i = 0; i < tfreq.size(); ++i )
1282 ETFxn[i] = go_lp.
clETF( i, gopt_lp );
1283 NTFxn[i] = go_lp.
clNTF( i, gopt_lp );
1288 for(
size_t i = 0; i < tfreq.size(); ++i )
1297 std::string tfOutFile =
1310 std::string fOutFile = tfOutFile +
"freq.binv";
1315 if( lifetimeTrials > 0 )
1317 speckleAmpPSD( spfreq, sppsd, tfreq, tPSDp, ETFxn, tPSDn, NTFxn, lifetimeTrials );
1320 realT splifeT = 100.0;
1323 realT tau = pvm(
error, spfreq, sppsd, splifeT ) * ( splifeT ) / spvar;
1325 speckleLifetimes_lp( mnMax + m, mnMax + n ) = tau;
1326 speckleLifetimes_lp( mnMax - m, mnMax - n ) = tau;
1335 std::string psdOutFile =
1340 std::vector<realT> psdOut( tPSDp.size() + tPSDpHF.size() );
1347 for(
size_t i = 0; i < tfreq.size(); ++i )
1349 go_si.
clTF2( ETF, NTF, i, gopt );
1350 psdOut[i] = tPSDp[i] * ETF + tPSDn[i] * NTF;
1353 for(
size_t i = 0; i < tPSDpHF.size(); ++i )
1355 psdOut[tfreq.size() + i] = tPSDpHF[i];
1360 for(
size_t i = 0; i < tfreq.size(); ++i )
1362 psdOut[i] = tPSDp[i];
1365 for(
size_t i = 0; i < tPSDpHF.size(); ++i )
1367 psdOut[tfreq.size() + i] = tPSDpHF[i];
1391 for(
size_t i = 0; i < tfreq.size(); ++i )
1393 go_lp.
clTF2( ETF, NTF, i, gopt_lp );
1394 psdOut[i] = tPSDp[i] * ETF + tPSDn[i] * NTF;
1396 for(
size_t i = 0; i < tPSDpHF.size(); ++i )
1398 psdOut[tfreq.size() + i] = tPSDpHF[i];
1403 for(
size_t i = 0; i < tfreq.size(); ++i )
1405 psdOut[i] = tPSDp[i];
1408 for(
size_t i = 0; i < tPSDpHF.size(); ++i )
1410 psdOut[tfreq.size() + i] = tPSDpHF[i];
1430 Eigen::Array<
realT, -1, -1> cim;
1434 ff.
write( fn, gains );
1437 ff.
write( fn, vars );
1441 realT Ssi = exp( -1 * cim.sum() );
1442 S_si.push_back( strehl );
1446 ff.
write( fn, cim );
1448 if( lifetimeTrials > 0 )
1451 ff.
write( fn, speckleLifetimes );
1457 ff.
write( fn, gains_lp );
1460 ff.
write( fn, lpC );
1463 ff.
write( fn, vars_lp );
1468 realT Slp = strehl * exp( -1 * cim.sum() ) /
1470 S_lp.push_back( Slp );
1474 ff.
write( fn, cim );
1476 if( lifetimeTrials > 0 )
1479 ff.
write( fn, speckleLifetimes_lp );
1485 fn = dir +
"/strehl_si.txt";
1487 for(
size_t i = 0; i < mags.size(); ++i )
1489 fout << mags[i] <<
" " << S_si[i] <<
"\n";
1496 fn = dir +
"/strehl_lp.txt";
1498 for(
size_t i = 0; i < mags.size(); ++i )
1500 fout << mags[i] <<
" " << S_lp[i] <<
"\n";
1511 const std::string &subDir,
1513 const std::string &psdDir,
1514 const std::string &CvdPath,
1517 std::vector<realT> &mags,
1522 std::string dir = psdDir +
"/" + subDir;
1525 mkdir( dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
1528 std::string fn = dir +
'/' +
"splife_params.txt";
1531 fout <<
"#---------------------------\n";
1532 m_aosys->dumpAOSystem( fout );
1533 fout <<
"#---------------------------\n";
1534 fout <<
"# Analysis Parameters\n";
1535 fout <<
"# mnMax = " << mnMax <<
'\n';
1536 fout <<
"# mnCon = " << mnCon <<
'\n';
1537 fout <<
"# mags = ";
1538 for(
size_t i = 0; i < mags.size() - 1; ++i )
1539 fout << mags[i] <<
",";
1540 fout << mags[mags.size() - 1] <<
'\n';
1541 fout <<
"# lifetimeTrials = " << lifetimeTrials <<
'\n';
1543 fout <<
"# writePSDs = " << std::boolalpha << writePSDs <<
'\n';
1547 realT fs = 1.0 / m_aosys->tauWFS();
1548 realT tauWFS = m_aosys->tauWFS();
1549 realT deltaTau = m_aosys->deltaTau();
1552 std::vector<sigproc::fourierModeDef> fms;
1555 size_t nModes = 0.5 * fms.size();
1556 std::cerr <<
"nModes: " << nModes <<
" (" << fms.size() <<
")\n";
1558 Eigen::Array<
realT, -1, -1> speckleLifetimes;
1559 Eigen::Array<
realT, -1, -1> speckleLifetimes_lp;
1561 speckleLifetimes.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
1562 speckleLifetimes( mnMax, mnMax ) = 0;
1564 speckleLifetimes_lp.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
1565 speckleLifetimes_lp( mnMax, mnMax ) = 0;
1571 std::vector<realT> tfreq;
1572 std::vector<realT> tPSDp;
1573 std::vector<realT> tPSDn;
1574 std::vector<complexT> tETF;
1575 std::vector<complexT> tNTF;
1577 if( getGridFreq( tfreq, psdDir ) < 0 )
1581 while( tfreq[imax] <= 0.5 * fs )
1584 if( imax > tfreq.size() - 1 )
1588 if( imax < tfreq.size() - 1 && tfreq[imax] <= 0.5 * fs * ( 1.0 + 1e-7 ) )
1591 tfreq.erase( tfreq.begin() + imax, tfreq.end() );
1594 tPSDn.resize( tfreq.size() );
1595 std::vector<std::vector<realT>> sqrtOPDPSD;
1596 sqrtOPDPSD.resize( nModes );
1598 std::vector<std::vector<realT>> opdPSD;
1599 opdPSD.resize( nModes );
1601 std::vector<realT> psd2sided;
1604 std::vector<realT> modeVar;
1605 modeVar.resize( nModes );
1611 for(
size_t i = 0; i < nModes; ++i )
1614 int m = fms[2 * i].m;
1615 int n = fms[2 * i].n;
1618 if( getGridPSD( tPSDp, psdDir, m, n ) < 0 )
1620 tPSDp.erase( tPSDp.begin() + imax, tPSDp.end() );
1627 opdPSD[i].resize( psd2sided.size() );
1628 sqrtOPDPSD[i].resize( psd2sided.size() );
1630 for(
size_t j = 0; j < psd2sided.size(); ++j )
1632 opdPSD[i][j] = psd2sided[j] * modeVar[i];
1633 sqrtOPDPSD[i][j] = sqrt( psd2sided[j] );
1637 size_t sz2Sided = psd2sided.size();
1639 std::vector<realT> freq2sided;
1640 freq2sided.resize( sz2Sided );
1643 tPSDp.resize( tfreq.size() );
1644 tETF.resize( tfreq.size() );
1645 tNTF.resize( tfreq.size() );
1647 std::vector<std::vector<realT>> sqrtNPSD;
1648 sqrtNPSD.resize( nModes );
1650 std::vector<realT> noiseVar;
1651 noiseVar.resize( nModes );
1653 std::vector<std::vector<complexT>> ETFsi;
1654 std::vector<std::vector<complexT>> ETFlp;
1655 ETFsi.resize( nModes );
1656 ETFlp.resize( nModes );
1658 std::vector<std::vector<complexT>> NTFsi;
1659 std::vector<std::vector<complexT>> NTFlp;
1660 NTFsi.resize( nModes );
1661 NTFlp.resize( nModes );
1663 std::string tfInFile;
1664 std::string etfInFile;
1665 std::string ntfInFile;
1669 ff.
read( Cvd, CvdPath );
1671 std::vector<std::complex<realT>> tPSDc, psd2sidedc;
1677 for(
size_t s = 0; s < mags.size(); ++s )
1682 for(
size_t i = 0; i < nModes; ++i )
1685 int m = fms[2 * i].m;
1686 int n = fms[2 * i].n;
1689 bool inside =
false;
1691 if( m_aosys->circularLimit() )
1693 if( m * m + n * n <= mnCon * mnCon )
1698 if( fabs( m ) <= mnCon && fabs( n ) <= mnCon )
1703 wfsNoisePSD<realT>( tPSDn,
1704 m_aosys->beta_p( m, n ),
1705 m_aosys->Fg( mags[s] ),
1707 m_aosys->npix_wfs( (
size_t)0 ),
1708 m_aosys->Fbg( (
size_t)0 ),
1709 m_aosys->ron_wfs( (
size_t)0 ) );
1715 sqrtNPSD[i].resize( psd2sided.size() );
1716 for(
size_t j = 0; j < psd2sided.size(); ++j )
1717 sqrtNPSD[i][j] = sqrt( psd2sided[j] );
1719 ETFsi[i].resize( sz2Sided );
1720 ETFlp[i].resize( sz2Sided );
1721 NTFsi[i].resize( sz2Sided );
1722 NTFlp[i].resize( sz2Sided );
1732 for(
size_t j = 0; j < psd2sidedc.size(); ++j )
1733 ETFsi[i][j] = psd2sidedc[j];
1739 for(
size_t j = 0; j < psd2sidedc.size(); ++j )
1740 NTFsi[i][j] = psd2sidedc[j];
1748 for(
size_t j = 0; j < psd2sidedc.size(); ++j )
1749 ETFlp[i][j] = psd2sidedc[j];
1755 for(
size_t j = 0; j < psd2sidedc.size(); ++j )
1756 NTFlp[i][j] = psd2sidedc[j];
1760 for(
int q = 0; q < ETFsi.size(); ++q )
1773 std::vector<std::vector<realT>> spPSDs;
1774 spPSDs.resize( nModes );
1775 for(
size_t pp = 0; pp < spPSDs.size(); ++pp )
1777 spPSDs[pp].resize( tavgPgram.
size() );
1778 for(
size_t nn = 0; nn < spPSDs[pp].size(); ++nn )
1782 std::vector<std::vector<realT>> spPSDslp;
1783 spPSDslp.resize( nModes );
1784 for(
size_t pp = 0; pp < spPSDslp.size(); ++pp )
1786 spPSDslp[pp].resize( tavgPgram.
size() );
1787 for(
size_t nn = 0; nn < spPSDslp[pp].size(); ++nn )
1788 spPSDslp[pp][nn] = 0;
1798 math::ft::fftT<realT, std::complex<realT>, 1, 0> fftF( sqrtOPDPSD[0].size() );
1802 std::vector<std::complex<realT>> tform1( sqrtOPDPSD[0].size() );
1803 std::vector<std::complex<realT>> tform2( sqrtOPDPSD[0].size() );
1804 std::vector<std::complex<realT>> Ntform1( sqrtOPDPSD[0].size() );
1805 std::vector<std::complex<realT>> Ntform2( sqrtOPDPSD[0].size() );
1807 std::vector<std::complex<realT>> tform1lp( sqrtOPDPSD[0].size() );
1808 std::vector<std::complex<realT>> tform2lp( sqrtOPDPSD[0].size() );
1809 std::vector<std::complex<realT>> Ntform1lp( sqrtOPDPSD[0].size() );
1810 std::vector<std::complex<realT>> Ntform2lp( sqrtOPDPSD[0].size() );
1813 sigproc::psdFilter<realT, 1> pfilt;
1814 pfilt.psdSqrt( &sqrtOPDPSD[0], tfreq[1] - tfreq[0] );
1817 sigproc::psdFilter<realT, 1> nfilt;
1818 nfilt.psdSqrt( &sqrtNPSD[0], tfreq[1] - tfreq[0] );
1821 std::vector<std::vector<realT>> hts;
1822 hts.resize( 2 * nModes );
1825 std::vector<std::vector<realT>> htsCorr;
1826 htsCorr.resize( 2 * nModes );
1828 for(
size_t pp = 0; pp < hts.size(); ++pp )
1830 hts[pp].resize( sqrtOPDPSD[0].size() );
1831 htsCorr[pp].resize( sqrtOPDPSD[0].size() );
1835 std::vector<realT> N_n;
1836 N_n.resize( sz2Sided );
1838 std::vector<realT> N_nm;
1839 N_nm.resize( sz2Sided );
1846 std::vector<realT> tpgram( avgPgram.
size() );
1850 spTS.resize( 2 * mnMax + 1, 2 * mnMax + 1, tform1.size() );
1853 spTSlp.resize( 2 * mnMax + 1, 2 * mnMax + 1, tform1.size() );
1857 for(
int zz = 0; zz < lifetimeTrials; ++zz )
1860 std::complex<realT>( ( tform1.size() ), 0 );
1865 for(
size_t pp = 0; pp < nModes; ++pp )
1868 for(
size_t nn = 0; nn < hts[2 * pp].size(); ++nn )
1870 hts[2 * pp][nn] = normVar;
1874 pfilt.psdSqrt( &sqrtOPDPSD[pp], tfreq[1] - tfreq[0] );
1877 pfilt( hts[2 * pp] );
1881 fftF( tform1.data(), hts[2 * pp].data() );
1884 for(
size_t nn = 0; nn < hts[2 * pp].size(); ++nn )
1885 tform1[nn] = tform1[nn] * scale;
1887 fftB( hts[2 * pp + 1].data(), tform1.data() );
1897 for(
size_t pp = 0; pp < hts.size(); ++pp )
1899 for(
size_t nn = 0; nn < hts[0].size(); ++nn )
1901 htsCorr[pp][nn] = 0;
1904 for(
size_t qq = 0; qq <= pp; ++qq )
1906 realT cvd = Cvd( qq, pp );
1907 realT *d1 = htsCorr[pp].data();
1908 realT *d2 = hts[qq].data();
1909 for(
size_t nn = 0; nn < hts[0].size(); ++nn )
1911 d1[nn] += d2[nn] * cvd;
1929 for(
size_t pp = 0; pp < nModes; ++pp )
1935 realT norm = sqrt( modeVar[pp] / var );
1936 for(
size_t nn = 0; nn < htsCorr[2 * pp].size(); ++nn )
1937 htsCorr[2 * pp][nn] *= norm;
1940 norm = sqrt( modeVar[pp] / var );
1941 for(
size_t nn = 0; nn < htsCorr[2 * pp + 1].size(); ++nn )
1942 htsCorr[2 * pp + 1][nn] *= norm;
1945 scale = std::complex<realT>( tform1.size(), 0 );
1950 for(
size_t pp = 0; pp < nModes; ++pp )
1955 fftF( tform1.data(), htsCorr[2 * pp].data() );
1956 fftF( tform2.data(), htsCorr[2 * pp + 1].data() );
1959 for(
int nn = 0; nn < sz2Sided; ++nn )
1967 pfilt.psdSqrt( &sqrtNPSD[pp], tfreq[1] - tfreq[0] );
1968 nfilt.filter( N_n );
1969 nfilt.filter( N_nm );
1973 realT norm = sqrt( noiseVar[pp] / Nactvar );
1974 for(
size_t q = 0; q < N_n.size(); ++q )
1976 for(
size_t q = 0; q < N_nm.size(); ++q )
1980 fftF( Ntform1.data(), N_n.data() );
1981 fftF( Ntform2.data(), N_nm.data() );
1984 for(
size_t mm = 0; mm < tform1.size(); ++mm )
1987 tform1lp[mm] = tform1[mm] * ETFlp[pp][mm] / scale;
1988 tform2lp[mm] = tform2[mm] * ETFlp[pp][mm] / scale;
1990 Ntform1lp[mm] = Ntform1[mm] * NTFlp[pp][mm] / scale;
1991 Ntform2lp[mm] = Ntform2[mm] * NTFlp[pp][mm] / scale;
1993 tform1[mm] *= ETFsi[pp][mm] / scale;
1994 tform2[mm] *= ETFsi[pp][mm] / scale;
1996 Ntform1[mm] *= NTFsi[pp][mm] / scale;
1997 Ntform2[mm] *= NTFsi[pp][mm] / scale;
2001 int m = fms[2 * pp].m;
2002 int n = fms[2 * pp].n;
2005 fftB( htsCorr[2 * pp].data(), tform1.data() );
2006 fftB( htsCorr[2 * pp + 1].data(), tform2.data() );
2007 fftB( N_n.data(), Ntform1.data() );
2008 fftB( N_nm.data(), Ntform2.data() );
2010 for(
int i = 0; i < hts[2 * pp].size(); ++i )
2012 realT h1 = htsCorr[2 * pp][i] + N_n[i];
2013 realT h2 = htsCorr[2 * pp + 1][i] + N_nm[i];
2015 spTS.
image( i )( mnMax + m, mnMax + n ) = ( pow( h1, 2 ) + pow( h2, 2 ) );
2016 spTS.
image( i )( mnMax - m, mnMax - n ) = spTS.
image( i )( mnMax + m, mnMax + n );
2019 fftB( htsCorr[2 * pp].data(), tform1lp.data() );
2020 fftB( htsCorr[2 * pp + 1].data(), tform2lp.data() );
2021 fftB( N_n.data(), Ntform1lp.data() );
2022 fftB( N_nm.data(), Ntform2lp.data() );
2024 for(
int i = 0; i < hts[2 * pp].size(); ++i )
2026 realT h1 = htsCorr[2 * pp][i] + N_n[i];
2027 realT h2 = htsCorr[2 * pp + 1][i] + N_nm[i];
2029 spTSlp.
image( i )( mnMax + m, mnMax + n ) = ( pow( h1, 2 ) + pow( h2, 2 ) );
2030 spTSlp.
image( i )( mnMax - m, mnMax - n ) = spTSlp.
image( i )( mnMax + m, mnMax + n );
2037 std::vector<realT> speckAmp( spTS.planes() );
2038 std::vector<realT> speckAmplp( spTS.planes() );
2040 for(
size_t pp = 0; pp < nModes; ++pp )
2042 int m = fms[2 * pp].m;
2043 int n = fms[2 * pp].n;
2047 for(
int i = 0; i < spTS.planes(); ++i )
2049 speckAmp[i] = spTS.
image( i )( mnMax + m, mnMax + n );
2050 speckAmplp[i] = spTSlp.
image( i )( mnMax + m, mnMax + n );
2053 mnlp += speckAmplp[i];
2055 mn /= speckAmp.size();
2056 mnlp /= speckAmplp.size();
2059 for(
int i = 0; i < speckAmp.size(); ++i )
2061 for(
int i = 0; i < speckAmplp.size(); ++i )
2062 speckAmplp[i] -= mnlp;
2065 avgPgram( tpgram, speckAmp );
2066 for(
size_t nn = 0; nn < spPSDs[pp].size(); ++nn )
2067 spPSDs[pp][nn] += tpgram[nn];
2069 avgPgram( tpgram, speckAmplp );
2070 for(
size_t nn = 0; nn < spPSDslp[pp].size(); ++nn )
2071 spPSDslp[pp][nn] += tpgram[nn];
2078 std::vector<realT> spFreq( spPSDs[0].size() );
2079 for(
size_t nn = 0; nn < spFreq.size(); ++nn )
2080 spFreq[nn] = tavgPgram[nn];
2083 taus.
resize( 2 * mnMax + 1, 2 * mnMax + 1 );
2084 tauslp.resize( 2 * mnMax + 1, 2 * mnMax + 1 );
2087 std::vector<realT> clPSD;
2091 imc.resize( 2 * mnMax + 1, 2 * mnMax + 1, spPSDs[0].size() );
2092 imclp.resize( 2 * mnMax + 1, 2 * mnMax + 1, spPSDs[0].size() );
2093 clPSD.resize( sz2Sided );
2100 for(
size_t pp = 0; pp < nModes; ++pp )
2102 spPSDs[pp][0] = spPSDs[pp][1];
2103 spPSDslp[pp][0] = spPSDslp[pp][1];
2105 int m = fms[2 * pp].m;
2106 int n = fms[2 * pp].n;
2111 for(
size_t nn = 0; nn < spPSDs[pp].size(); ++nn )
2113 spPSDs[pp][nn] /= lifetimeTrials;
2116 for(
size_t nn = 0; nn < sz2Sided; ++nn )
2119 opdPSD[pp][nn] * norm( ETFsi[pp][nn] ) + pow( sqrtNPSD[pp][nn], 2 ) * norm( NTFsi[pp][nn] );
2126 for(
size_t nn = 0; nn < spPSDs[pp].size(); ++nn )
2128 spPSDs[pp][nn] *= var / pvar;
2129 imc.
image( nn )( mnMax + m, mnMax + n ) = spPSDs[pp][nn];
2130 imc.
image( nn )( mnMax - m, mnMax - n ) = spPSDs[pp][nn];
2134 for(
size_t nn = 0; nn < spPSDslp[pp].size(); ++nn )
2136 spPSDslp[pp][nn] /= lifetimeTrials;
2139 for(
size_t nn = 0; nn < sz2Sided; ++nn )
2142 opdPSD[pp][nn] * norm( ETFlp[pp][nn] ) + pow( sqrtNPSD[pp][nn], 2 ) * norm( NTFlp[pp][nn] );
2149 for(
size_t nn = 0; nn < spPSDslp[pp].size(); ++nn )
2151 spPSDslp[pp][nn] *= var / pvar;
2152 imclp.
image( nn )( mnMax + m, mnMax + n ) = spPSDslp[pp][nn];
2153 imclp.
image( nn )( mnMax - m, mnMax - n ) = spPSDslp[pp][nn];
2159 realT T = ( 1.0 / ( spFreq[1] - spFreq[0] ) ) * 10;
2161 realT tau = pvm(
error, spFreq, spPSDs[pp], T ) * ( T ) / var;
2162 taus( mnMax + m, mnMax + n ) = tau;
2163 taus( mnMax - m, mnMax - n ) = tau;
2167 tau = pvm(
error, spFreq, spPSDslp[pp], T ) * ( T ) / var;
2168 tauslp( mnMax + m, mnMax + n ) = tau;
2169 tauslp( mnMax - m, mnMax - n ) = tau;
2176 ff.
write( fn, taus );
2179 ff.
write( fn, tauslp );
2184 ff.
write( fn, imc );
2187 ff.
write( fn, imclp );