00001 00034 #ifndef TRANSFORMS_H 00035 #define TRANSFORMS_H 00036 00037 #include <itpp/base/vec.h> 00038 #include <itpp/base/mat.h> 00039 #include <itpp/base/matfunc.h> 00040 00041 00042 namespace itpp { 00043 00084 00085 00086 00088 void fft(const cvec &in, cvec &out); 00090 cvec fft(const cvec &in); 00092 cvec fft(const cvec &in, const int N); 00094 void ifft(const cvec &in, cvec &out); 00096 cvec ifft(const cvec &in); 00098 cvec ifft(const cvec &in, const int N); 00099 00101 void fft_real(const vec& in, cvec &out); 00103 cvec fft_real(const vec& in); 00105 cvec fft_real(const vec &in, const int N); 00107 void ifft_real(const cvec &in, vec &out); 00109 vec ifft_real(const cvec &in); 00111 vec ifft_real(const cvec &in, const int N); 00113 00114 00156 00157 00158 00160 void dct(const vec &in, vec &out); 00162 vec dct(const vec &in); 00164 void idct(const vec &in, vec &out); 00166 vec idct(const vec &in); 00168 00169 00172 00174 template <class T> Vec<T> dht(const Vec<T> &v); 00176 template <class T> void dht(const Vec<T> &vin, Vec<T> &vout); 00178 template <class T> void self_dht(Vec<T> &v); 00179 00181 template <class T> Vec<T> dwht(const Vec<T> &v); 00183 template <class T> void dwht(const Vec<T> &vin, Vec<T> &vout); 00185 template <class T> void self_dwht(Vec<T> &v); 00186 00188 template <class T> Mat<T> dht2(const Mat<T> &m); 00190 template <class T> Mat<T> dwht2(const Mat<T> &m); 00192 00193 template <class T> 00194 Vec<T> dht(const Vec<T> &v) 00195 { 00196 Vec<T> ret(v.size()); 00197 dht(v, ret); 00198 return ret; 00199 } 00200 00202 template <class T> 00203 void bitrv(Vec<T> &out) 00204 { 00205 int N = out.size(); 00206 int j = 0; 00207 int N1 = N-1; 00208 for (int i = 0; i < N1; ++i) { 00209 if (i < j) { 00210 T temp = out[j]; 00211 out[j] = out[i]; 00212 out[i] = temp; 00213 } 00214 int K = N/2; 00215 while (K <= j) { 00216 j -= K; 00217 K /= 2; 00218 } 00219 j += K; 00220 } 00221 } 00222 00223 template <class T> 00224 void dht(const Vec<T> &vin, Vec<T> &vout) 00225 { 00226 int N = vin.size(); 00227 int m = levels2bits(N); 00228 it_assert1((1<<m) == N, "dht(): The vector size must be a power of two"); 00229 00230 vout.set_size(N); 00231 00232 // This step is separated because it copies vin to vout 00233 for (int ib = 0; ib < N; ib += 2) { 00234 vout(ib) = vin(ib) + vin(ib+1); 00235 vout(ib+1) = vin(ib) - vin(ib+1); 00236 } 00237 N /= 2; 00238 00239 int l = 2; 00240 for (int i = 1; i < m; ++i) { 00241 N /= 2; 00242 int ib = 0; 00243 for (int k = 0; k < N; ++k) { 00244 for (int j = 0; j < l; ++j) { 00245 T t = vout(ib+j); 00246 vout(ib+j) += vout(ib+j+l); 00247 vout(ib+j+l) = t - vout(ib+j+l); 00248 } 00249 ib += 2*l; 00250 } 00251 l *= 2; 00252 } 00253 00254 vout /= static_cast<T>(std::sqrt(static_cast<double>(vin.size()))); 00255 } 00256 00257 template <class T> 00258 void self_dht(Vec<T> &v) 00259 { 00260 int N = v.size(); 00261 int m = levels2bits(N); 00262 it_assert1((1<<m) == N, "self_dht(): The vector size must be a power " 00263 "of two"); 00264 00265 int l = 1; 00266 for (int i = 0; i < m; ++i) { 00267 N /= 2; 00268 int ib = 0; 00269 for (int k = 0; k < N; ++k) { 00270 for (int j = 0; j < l; ++j) { 00271 T t = v(ib+j); 00272 v(ib+j) += v(ib+j+l); 00273 v(ib+j+l) = t - v(ib+j+l); 00274 } 00275 ib += 2*l; 00276 } 00277 l *= 2; 00278 } 00279 00280 v /= static_cast<T>(std::sqrt(static_cast<double>(v.size()))); 00281 } 00282 00283 template <class T> 00284 Vec<T> dwht(const Vec<T> &v) 00285 { 00286 Vec<T> ret(v.size()); 00287 dwht(v, ret); 00288 return ret; 00289 } 00290 00291 template <class T> 00292 void dwht(const Vec<T> &vin, Vec<T> &vout) 00293 { 00294 dht(vin, vout); 00295 bitrv(vout); 00296 } 00297 00298 00299 template <class T> 00300 void self_dwht(Vec<T> &v) 00301 { 00302 self_dht(v); 00303 bitrv(v); 00304 } 00305 00306 template <class T> 00307 Mat<T> dht2(const Mat<T> &m) 00308 { 00309 Mat<T> ret(m.rows(), m.cols()); 00310 Vec<T> v; 00311 00312 for (int i = 0; i < m.rows(); ++i) { 00313 v = m.get_row(i); 00314 self_dht(v); 00315 ret.set_row(i, v); 00316 } 00317 for (int i = 0; i < m.cols(); ++i) { 00318 v = ret.get_col(i); 00319 self_dht(v); 00320 ret.set_col(i, v); 00321 } 00322 00323 return transpose(ret); 00324 } 00325 00326 template <class T> 00327 Mat<T> dwht2(const Mat<T> &m) 00328 { 00329 Mat<T> ret(m.rows(), m.cols()); 00330 Vec<T> v; 00331 00332 for (int i = 0; i < m.rows(); ++i) { 00333 v = m.get_row(i); 00334 self_dwht(v); 00335 ret.set_row(i, v); 00336 } 00337 for (int i = 0; i < m.cols(); ++i) { 00338 v = ret.get_col(i); 00339 self_dwht(v); 00340 ret.set_col(i, v); 00341 } 00342 00343 return transpose(ret); 00344 } 00345 00346 00347 // ---------------------------------------------------------------------- 00348 // template instantiation 00349 // ---------------------------------------------------------------------- 00350 #ifndef _MSC_VER 00351 00353 extern template vec dht(const vec &v); 00355 extern template cvec dht(const cvec &v); 00356 00358 extern template void dht(const vec &vin, vec &vout); 00360 extern template void dht(const cvec &vin, cvec &vout); 00361 00363 extern template void self_dht(vec &v); 00365 extern template void self_dht(cvec &v); 00366 00368 extern template vec dwht(const vec &v); 00370 extern template cvec dwht(const cvec &v); 00371 00373 extern template void dwht(const vec &vin, vec &vout); 00375 extern template void dwht(const cvec &vin, cvec &vout); 00376 00378 extern template void self_dwht(vec &v); 00380 extern template void self_dwht(cvec &v); 00381 00383 extern template mat dht2(const mat &m); 00385 extern template cmat dht2(const cmat &m); 00386 00388 extern template mat dwht2(const mat &m); 00390 extern template cmat dwht2(const cmat &m); 00391 00392 #endif // #ifndef _MSC_VER 00393 00394 } // namespace itpp 00395 00396 #endif // #ifndef TRANSFORMS_H
Generated on Sat Aug 25 23:40:54 2007 for IT++ by Doxygen 1.5.2