isce3 0.25.0
Loading...
Searching...
No Matches
WinChirpRgCompPow.icc
1// Implementation of WinChirpRgCompPow.h
2
3#include <cmath>
4#include <type_traits>
5
6#include <isce3/except/Error.h>
7#include <isce3/focus/Chirp.h>
8#include <isce3/focus/RangeComp.h>
9
10namespace isce3 { namespace antenna { namespace detail {
11
12template<typename T>
13std::vector<T> genRaisedCosineWin(int size, double ped)
14{
15 // check the arguments
16 static_assert(std::is_floating_point_v<T>,
17 "'genRaisedCosineWin' requires floating-point output/template "
18 "type!");
19 if (size < 1)
20 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
21 "Raisedcosine window size must be a positive value!");
22 if (ped < 0.0 || ped > 1.0)
23 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
24 "The raisedcosine window pedestal shall be a "
25 "value within [0, 1]!");
26 // form the window function
27 std::vector<T> rc_win(size);
28 if (size == 1) {
29 rc_win[0] = 1;
30 return rc_win;
31 }
32 const double cos_fact {2.0 * M_PI / (size - 1)};
33 const double scalar {-0.5 * (1.0 - ped)};
34 const double offset {0.5 * (1.0 + ped)};
35 for (int idx = 0; idx < size; ++idx)
36 rc_win[idx] = scalar * std::cos(cos_fact * idx) + offset;
37 return rc_win;
38}
39
40inline std::vector<std::complex<float>> genRcosWinChirp(double sample_freq,
41 double chirp_slope, double chirp_dur, double win_ped, bool norm)
42{
43 // check the arguments
44 if (!(sample_freq > 0.0))
45 throw isce3::except::InvalidArgument(
46 ISCE_SRCINFO(), "Sampling frequency must be a positive value!");
47 if (!(chirp_dur > 0.0))
48 throw isce3::except::InvalidArgument(
49 ISCE_SRCINFO(), "Chirp duration must be a positive value!");
50
51 // form an analythical chirp with rectangular envelope
52 auto chp =
53 isce3::focus::formLinearChirp(chirp_slope, chirp_dur, sample_freq);
54 Eigen::Map<Eigen::VectorXcf> chp_map(chp.data(), chp.size());
55
56 // form the window function
57 auto rcw = genRaisedCosineWin(static_cast<int>(chp.size()), win_ped);
58 Eigen::Map<Eigen::VectorXf> rcw_map(rcw.data(), rcw.size());
59
60 // perform windowing in time-domain and force unit-energy!
61 // Note that Applying window func in time domian only works for LFM!
62 // In general, It shall be done in Freq domian to propely bandlimit any
63 // waveform!
64 chp_map = chp_map.cwiseProduct(rcw_map);
65 if (norm)
66 chp_map.normalize();
67 return chp;
68}
69
70inline Eigen::ArrayXd meanRgCompEchoPower(
71 const Eigen::Ref<const RowMatrixXcf>& echo_mat,
72 const std::vector<std::complex<float>>& chirp_ref)
73{
74 // check length of ref chirp versus range bins (columns) of echo
75 if (static_cast<Eigen::Index>(chirp_ref.size()) > echo_mat.cols())
76 throw isce3::except::LengthError(ISCE_SRCINFO(),
77 "Chirp ref is longer than range bins or number "
78 "columns of echo!");
79
80 // form rangecomp object with valid mode (truncated true range bins w/o
81 // two-way group delay!)
82 auto rgc_obj = isce3::focus::RangeComp(chirp_ref, echo_mat.cols(), 1,
84 // final number of range bins and range lines(or pulses)
85 const auto nrgbs = rgc_obj.outputSize();
86 const auto nrgls = echo_mat.rows();
87 // Allocate and Initialize the final mean power vector
88 Eigen::ArrayXd mean_pow = Eigen::ArrayXd::Zero(nrgbs);
89 // allocate range line vector for range compression output
90 Eigen::ArrayXcf rgc_line(nrgbs);
91
92 for (Eigen::Index pulse = 0; pulse < nrgls; ++pulse) {
93 // range compression per range line
94 rgc_obj.rangecompress(rgc_line.data(), echo_mat.row(pulse).data());
95 // get the power and add up its double precision version
96 mean_pow += rgc_line.abs2().cast<double>();
97 }
98 mean_pow /= nrgls;
99 return mean_pow;
100}
101
102inline std::tuple<Eigen::ArrayXd, Eigen::ArrayXd> rangeCalibAvgEchoPower(
103 const Eigen::Ref<const Eigen::ArrayXd>& echo_pow, double rg_start,
104 double rg_spacing, int size_avg)
105{
106 // check some inputs
107 if (!(rg_spacing > 0.0))
108 throw isce3::except::InvalidArgument(
109 ISCE_SRCINFO(), "Range spacing must be a positive value.");
110 const auto echo_size = static_cast<int>(echo_pow.size());
111 if (size_avg < 1 || size_avg > echo_size)
112 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
113 "Block size for averaging must be within [1, echo_size]");
114
115 const int nrgb {echo_size / size_avg};
116 // form the slant range vector
117 const double drg {size_avg * rg_spacing};
118 const double rg_first {rg_start + 0.5 * (size_avg - 1) * rg_spacing};
119 const double rg_last {rg_first + (nrgb - 1) * drg};
120 Eigen::ArrayXd sr = Eigen::ArrayXd::LinSpaced(nrgb, rg_first, rg_last);
121 // allocate calibrated power vector
122 Eigen::ArrayXd cal_pow(nrgb);
123 // loop over range blocks
124 for (int idx = 0; idx < nrgb; ++idx) {
125 // path loss calib factor correction
126 auto cal_fact = std::pow(sr(idx) / rg_first, 3);
127 // take a mean of the block and then apply calib factor due to range
128 cal_pow(idx) =
129 echo_pow.segment(idx * size_avg, size_avg).mean() * cal_fact;
130 }
131 return {cal_pow, sr};
132}
133
134}}} // namespace isce3::antenna::detail
std::vector< std::complex< float > > genRcosWinChirp(double sample_freq, double chirp_slope, double chirp_dur, double win_ped=0.0, bool norm=true)
Generate a unit-energy raised-cosine-windowed baseband complex analytical chirp.
Definition WinChirpRgCompPow.icc:40
std::vector< T > genRaisedCosineWin(int size, double ped)
Generate a raised-cosine window function with a desired pedestal.
Definition WinChirpRgCompPow.icc:13
std::tuple< Eigen::ArrayXd, Eigen::ArrayXd > rangeCalibAvgEchoPower(const Eigen::Ref< const Eigen::ArrayXd > &echo_pow, double rg_start, double rg_spacing, int size_avg=1)
Path-loss corrected/calibrated averaged/decimated uniformly-sampled echo power as a function of slant...
Definition WinChirpRgCompPow.icc:102
Eigen::ArrayXd meanRgCompEchoPower(const Eigen::Ref< const RowMatrixXcf > &echo_mat, const std::vector< std::complex< float > > &chirp_ref)
Averaged Power of range compressed complex raw echo over multiple range lines as a function of true v...
Definition WinChirpRgCompPow.icc:70
Range compression processor.
Definition RangeComp.h:11
@ Valid
The output contains only the valid discrete convolution of the input with the matched filter.
Definition RangeComp.h:31
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.