44 arma::mat wcoeffs(X.n_rows, scales.n_elem);
45 arma::vec psi_xval(1024);
48 arma::uword old_length = X.n_rows;
54 if (wavelet ==
"mexh"){
55 psi_xval = arma::linspace(-8, 8, 1024);
56 psi = (2/std::sqrt(3.0) * std::pow(arma::datum::pi, -0.25)) * (arma::ones(1024) - arma::pow(psi_xval, 2)) % arma::exp(-arma::pow(psi_xval, 2)/2);
58 else if (wavelet ==
"haar"){
59 psi_xval = arma::linspace(0, 1, 1024);
62 psi.rows(1, 511) = arma::ones(511);
63 psi.rows(512, 1022) = -1*arma::ones(511);
65 }
catch(std::exception e){
66 std::cerr <<
"Error calculating wavelet!" <<std::endl;
71 psi_xval -= arma::ones(psi_xval.n_elem)*psi_xval(0);
72 double dxval = psi_xval(1);
73 double xmax = psi_xval(psi_xval.n_elem - 1);
77 arma::uword i, scale, shift_by;
79 for (i = 0; i < scales.n_elem; ++i){
82 f = arma::zeros(X.n_elem);
83 j = arma::floor(arma::linspace(0, scale*xmax, scale*xmax + 1)/(scale*dxval));
84 j_u.set_size(j.n_elem);
87 for (arma::uword k = 0; k < j_u.n_elem; ++k){
91 f.rows(0, j.n_elem-1) = arma::flipud(psi.elem(j_u)) - arma::mean(psi.elem(j_u));
93 if (f.n_rows != X.n_rows){
94 std::cerr <<
"scale too large!" << std::endl;
102 shift_by = X.n_rows - std::floor((
double) j.n_rows/2) + scale*xmax;
107 if (w.n_rows > old_length)
108 w.shed_rows(old_length, w.n_rows - 1);
112 }
catch(std::exception e){
113 std::cerr <<
"error in CWT algorithm!" << std::endl;
114 std::cerr <<
"scale = " << scale;
123 arma::vec
Vespucci::Math::Transform::cwt_spdbc(
const arma::vec &X, std::string wavelet, arma::uword qscale,
double threshold, std::string threshold_method, arma::uword window_size, arma::umat &peak_extrema, arma::vec &baseline)
126 arma::vec peak_magnitudes;
127 arma::uvec scales(1);
132 dX_transform.insert_rows(0, 1,
true);
139 }
catch(std::exception e){
140 std::cerr << std::endl <<
"exception! cwt_spdbc" << std::endl;
141 std::cerr << e.what();
151 double threshold, std::string threshold_method,
152 arma::uword window_size, arma::field<arma::umat> &peak_positions,
153 arma::mat &baselines)
155 baselines.set_size(X.n_rows, X.n_cols);
158 arma::vec current_corrected;
159 arma::mat corrected(X.n_rows, X.n_cols);
160 arma::umat current_peakpos;
161 peak_positions.set_size(X.n_cols);
164 for (i = 0; i < X.n_cols; ++i){
168 threshold_method, window_size,
169 current_peakpos, baseline);
171 peak_positions(i) = current_peakpos;
172 baselines.col(i) = baseline;
173 corrected.col(i) = current_corrected;
175 }
catch(std::exception e){
176 std::cerr << std::endl <<
"exception! cwt_spdbc_mat" << std::endl;
177 std::cerr <<
"i = " << i << std::endl;
178 std::cerr << e.what();
189 std::string wavelet, arma::uword qscale,
190 double threshold, std::string threshold_method,
191 arma::mat &transform)
193 transform.set_size(X.n_rows, X.n_cols);
194 arma::uvec scales(1);
197 arma::umat peak_positions;
198 arma::mat peak_extrema(X.n_rows, X.n_cols);
199 arma::vec spectrum, current_transform, dtransform, peak_magnitudes;
201 for (i = 0; i < X.n_cols; ++i){
204 transform.col(i) = current_transform;
206 dtransform.insert_rows(0, 1,
true);
208 threshold, threshold_method,
213 catch(std::exception e){
214 std::cerr <<
"CWTPeakAnalysis" << std::endl;
215 std::cerr <<
"i = " << i << std::endl;
229 arma::field<arma::mat> results(X.n_cols);
230 for (arma::uword i = 0; i < results.n_elem; ++i){
VESPUCCI_EXPORT arma::vec ExtendToNextPow(arma::vec X, arma::uword n)
T diff(const T &X, arma::uword deriv_order=1)
Vespucci::Math::diff.
VESPUCCI_EXPORT arma::vec PeakExtrema(arma::uword vector_size, arma::umat peak_positions)
T conv_fft(const T &A, const T &B, std::string type)
T rotate(const T &X, arma::uword shift_by, bool slide_back=true)
cmplx FADDEEVA() w(cmplx z, double relerr)
VESPUCCI_EXPORT arma::vec EstimateBaseline(arma::vec X, arma::umat peaks, arma::uword window_size)
EstimateBaseline.
VESPUCCI_EXPORT arma::uvec FindPeakPositions(arma::vec X, arma::vec dX, double sel, double threshold, arma::uvec &local_minima)