33 #include <itpp/itexports.h> 50 for (
int i = 0; i < v.
length(); i++) {
51 for (
int j = 0;j < norepeats;j++)
52 temp(i*norepeats + j) = v(i);
63 for (
int j = 0; j < m.
cols(); j++) {
64 for (
int i = 0;i < norepeats;i++) {
75 it_assert_debug(usf >= 1,
"upsample: upsampling factor must be equal or greater than one");
78 for (
int i = 0;i < v.
length();i++)
96 it_assert_debug(usf >= 1,
"upsample: upsampling factor must be equal or greater than one");
99 for (
int j = 0;j < v.
cols();j++)
116 it_assert_debug(usf >= 1,
"lininterp: upsampling factor must be equal or greater than one");
117 int L = (m.
cols() - 1) * usf + 1;
119 for (
int i = 0; i < m.
rows(); i++) {
120 for (
int j = 0; j < L - 1; j++)
121 u(i, j) = (m(i, j / usf) + (j % usf) / ((
double)usf) * (m(i, (j + usf) / usf) - m(i, j / usf)));
122 u(i, L - 1) = m(i, m.
cols() - 1);
138 int nrof_samples,
double t_start = 0)
140 double t_base = 1 / f_base;
141 double t_ups = 1 / f_ups;
144 it_assert_debug(f_ups > f_base,
"lininterp(): upsampled frequency must be greater than base frequency");
145 it_assert_debug((t_start >= 0) && (t_start < cols * t_base),
"lininterp(): incorrect start time offset");
146 it_assert_debug((nrof_samples * t_ups + t_start) <= (cols * t_base),
"lininterp(): too many samples required or input data to short");
147 Mat<T> u(rows, nrof_samples);
148 double curr_time = t_start;
152 while (i < cols - 1) {
153 while ((curr_time < (i + 1) * t_base) && (k < nrof_samples)) {
154 for (
int j = 0; j < rows; j++) {
155 u(j, k) = (m(j, i) * ((i + 1) * t_base - curr_time)
156 - m(j, i + 1) * (i * t_base - curr_time)) / t_base;
171 lininterp(m, usf, u);
179 it_assert_debug(usf >= 1,
"lininterp(): upsampling factor must be equal or greater than one");
180 int L = (v.
length() - 1) * usf + 1;
182 for (
int j = 0; j < L - 1; j++) {
183 u(j) = (v(j / usf) + (j % usf) / ((
double)usf) * (v((j + usf) / usf) - v(j / usf)));
185 u(L - 1) = v(v.
length() - 1);
193 lininterp(v, usf, u);
209 int nrof_samples,
double t_start = 0)
211 double t_base = 1 / f_base;
212 double t_ups = 1 / f_ups;
214 it_assert_debug(f_ups > f_base,
"lininterp(): upsampled frequency must be greater than base frequency");
215 it_assert_debug((t_start >= 0) && (t_start < len * t_base),
"lininterp(): incorrect start time offset");
216 it_assert_debug((nrof_samples * t_ups + t_start) <= (len * t_base),
"lininterp(): too many samples required or input data to short");
218 double curr_time = t_start;
222 while (i < len - 1) {
223 while ((curr_time < (i + 1) * t_base) && (k < nrof_samples)) {
224 u(k) = (v(i) * ((i + 1) * t_base - curr_time)
225 - v(i + 1) * (i * t_base - curr_time)) / t_base;
245 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec repeat(
const vec &v,
int norepeats);
247 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec repeat(
const cvec &v,
int norepeats);
249 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec repeat(
const svec &v,
int norepeats);
251 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec repeat(
const ivec &v,
int norepeats);
253 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec repeat(
const bvec &v,
int norepeats);
256 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat repeat(
const mat &m,
int norepeats);
258 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat repeat(
const cmat &m,
int norepeats);
260 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat repeat(
const smat &m,
int norepeats);
262 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat repeat(
const imat &m,
int norepeats);
264 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat repeat(
const bmat &m,
int norepeats);
267 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec upsample(
const vec &v,
int usf);
269 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec upsample(
const cvec &v,
int usf);
271 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec upsample(
const svec &v,
int usf);
273 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec upsample(
const ivec &v,
int usf);
275 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec upsample(
const bvec &v,
int usf);
278 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat upsample(
const mat &v,
int usf);
280 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat upsample(
const cmat &v,
int usf);
282 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat upsample(
const smat &v,
int usf);
284 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat upsample(
const imat &v,
int usf);
286 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
bmat upsample(
const bmat &v,
int usf);
289 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const vec &v,
int usf, vec &u);
291 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const cvec &v,
int usf, cvec &u);
293 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const svec &v,
int usf, svec &u);
295 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const ivec &v,
int usf, ivec &u);
297 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const bvec &v,
int usf, bvec &u);
300 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const mat &v,
int usf, mat &u);
302 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const cmat &v,
int usf, cmat &u);
304 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const smat &v,
int usf, smat &u);
306 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const imat &v,
int usf, imat &u);
308 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void upsample(
const bmat &v,
int usf,
bmat &u);
311 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec lininterp(
const vec &v,
int usf);
313 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec lininterp(
const cvec &v,
int usf);
316 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat lininterp(
const mat &v,
int usf);
318 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat lininterp(
const cmat &v,
int usf);
321 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void lininterp(
const vec &v,
int usf, vec &u);
323 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void lininterp(
const cvec &v,
int usf, cvec &u);
326 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void lininterp(
const mat &v,
int usf, mat &u);
328 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void lininterp(
const cmat &v,
int usf, cmat &u);
331 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat lininterp(
const mat &m,
double f_base,
double f_ups,
int nrof_samples,
double t_start);
333 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat lininterp(
const cmat &m,
double f_base,
double f_ups,
int nrof_samples,
double t_start);
336 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT vec lininterp(
const vec &v,
double f_base,
double f_ups,
int nrof_samples,
double t_start);
338 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cvec lininterp(
const cvec &v,
double f_base,
double f_ups,
int nrof_samples,
double t_start);
344 #endif // #ifndef RESAMPLING_H void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
void set_col(int c, const Vec< Num_T > &v)
Set column c to vector v.
int cols() const
The number of columns.
void clear()
Set matrix equal to the all zero matrix.
Matrix Class Definitions.
Vec< Num_T > get_col(int c) const
Get column c.
int length() const
The size of the vector.
int rows() const
The number of rows.
void clear()
Set the vector to the all zero vector.
Mat< bin > bmat
bin matrix