| ²é¿´: 982 | »Ø¸´: 5 | ||
sitp_710Ìú³æ (СÓÐÃûÆø)
|
[ÇóÖú]
±àÒëÌáʾ"vector.h"ÎÞ·¨ÕÒµ½£¬´ó¼ÒÄܰï²âÊÔÏÂÕâ¸öС²¨±ä»»³ÌÐòÂ𣿠ÒÑÓÐ3È˲ÎÓë
|
|
ÔÚÍøÕ¾ÉÏÕÒµ½Á˸ö¶þ½øÐ¡²¨±ä»»³ÌÐò£¬ÏëѧЩÏ£¬ÔÚVC6.0ºÍVS2010»·¾³Ï¶¼ÌáʾÎÞ·¨ÕÒµ½Vector.hµÄ±àÒë´íÎ󣬴ó¼ÒÄܰïÎÒ¿´¿´ÎÊÌâ³öÔÚÄÄÀïÂð£¿Ð»Ð»£¡ ³ÌÐòÎÒÌùÔÚÏÂÃæ£¬Ò²¿É²Î¿¼ÔÍøÕ¾£ºhttp://my.oschina.net/zmjerry/blog/8503 Í·Îļþ£º /* * Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 2 or any later version. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. A copy of the GNU General Public License is available at: * http://www.fsf.org/licensing/licenses */ /***************************************************************************** * bwt.h * * Dyadic Wavelet Transform. * * These routines are designed for computing the dyadic wavelet transform * and it's inverse transform using quadratic spline wavelet. * * To distinguish with the "dwt" (discrete wavelet transform), we call this * file as "bwt", but in fact, it should be dyadic wavelet transform. * * * Zhang Ming, 2010-03, Xi'an Jiaotong University. *****************************************************************************/ #ifndef BWT_H #define BWT_H #include <vector.h> #include <utilities.h> namespace splab { template<typename Type> Vector< Vector<Type> > bwt( const Vector<Type>&, int ); template<typename Type> Vector<Type> ibwt( const Vector< Vector<Type> >&, int ); #include <bwt-impl.h> } // namespace splab #endif // BWT_H ʵÏÖÎļþ£º /* * Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 2 or any later version. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. A copy of the GNU General Public License is available at: * http://www.fsf.org/licensing/licenses */ /***************************************************************************** * bwt-impl.h * * Implementation for Dyadic Wavelet Transform. * * Zhang Ming, 2010-03, Xi'an Jiaotong University. *****************************************************************************/ /** * Forward Transform. * The decomposition levels is specified by integer "J". The decomposed * coefficients are stroed in a "Vector< vector<Type> >" structure. * Detial coefficients are stored from 1st to Jth row, and approximation * coefficients are stored at the last row, i.e. the (J+1)th row. */ template <typename Type> Vector< Vector<Type> > bwt( const Vector<Type> &xn, int J ) { // lowpass decomposition filter Vector<Type> ld(4); ld[0] = 0.125; ld[1] = 0.375; ld[2] = 0.375; ld[3] = 0.125; ld = Type(RT2) * ld; int ldZeroStart = 1; // highpass decomposition filter Vector<Type> hd(2); hd[0] = -0.5; hd[1] = 0.5; hd = Type(RT2) * hd; int hdZeroStart = 0; // initializing the coefficients int N = xn.size(); Vector< Vector<Type> > coefs(J+1); for( int i=0; i<J; ++i ) coefs.resize(N); Vector<Type> approx(N); Vector<Type> a(xn); // get the inversion of filters Vector<Type> ll = flip(ld); Vector<Type> hh = flip(hd); int llZeroStart = 0, hhZeroStart = 0, p = 1; for( int j=0; j<J; ++j ) { // compute the 0 position of the new filters llZeroStart = ll.size()-1 - p*ldZeroStart; hhZeroStart = hh.size()-1 - p*hdZeroStart; for( int i=0; i<N; ++i ) { Type sum = 0; // compute the approximation coefficients for( int k=0; k<ll.size(); k+=p ) { int index = mod( i+llZeroStart-k, N ); sum += ll[k]*a[index]; } approx = sum; // compute the detial coefficients sum = 0; for( int k=0; k<hh.size(); k+=p ) { int index = mod( i+hhZeroStart-k, N ); sum += hh[k]*a[index]; } coefs[j] = sum; } a = approx; // dyadic upsampling ll = dyadUp( ll, 1 ); hh = dyadUp( hh, 1 ); p *= 2; } coefs[J] = approx; return coefs; } /** * Backword Transform. * The reconstruction livel is specified by integer "level", and * "levle" should between "0"(the approximation component) and "J" * (the original signal). */ template <typename Type> Vector<Type> ibwt( const Vector< Vector<Type> > &coefs, int level ) { Vector<Type> lr(4); lr[0] = 0.125; lr[1] = 0.375; lr[2] = 0.375; lr[3] = 0.125; lr = Type(RT2) * lr; int lrZeroStart = 1; Vector<Type> hr(6); hr[0] = -0.03125; hr[1] = -0.21875; hr[2] = -0.6875; hr[3] = 0.6875; hr[4] = 0.21875; hr[5] = 0.03125; hr = Type(RT2) * hr; int hrZeroStart = 2; int J = coefs.dim() - 1; if( (level < 0) || (level > J) ) { cout << "invalid reconstruction level!" << endl; return Vector<Type>(0); } int N = coefs[0].dim(); Vector<Type> a = coefs[J]; Vector<Type> xn(N); Vector<Type> ll = lr; Vector<Type> hh = hr; int llZeroStart = 0; int hhZeroStart = 0; int p = 1; // get the Jth level filters for( int j=0; j<level-1; ++j ) { p *= 2; ll = dyadUp( ll, 1 ); hh = dyadUp( hh, 1 ); } for( int j=level-1; j>=0; --j ) { // compute the 0 position of the new filters llZeroStart = p*lrZeroStart; hhZeroStart = p*hrZeroStart; // compute the jth approximation coefficients for( int i=0; i<N; ++i ) { Type sum = 0; for( int k=0; k<ll.size(); k+=p ) { int index = mod( i+llZeroStart-k, N ); sum += ll[k]*a[index]; } for( int k=0; k<hh.size(); k+=p ) { int index = mod( i+hhZeroStart-k, N ); sum += hh[k]*coefs[j][index]; } xn = sum/2; } a = xn; // dyadic downsampling ll = dyadDown( ll, 0 ); hh = dyadDown( hh, 0 ); p /= 2; } return xn; } ²âÊÔ´úÂ룺 /***************************************************************************** * bwt_test.cpp * * Dyadic wavelet transform testing. * * Zhang Ming, 2010-03, Xi'an Jiaotong University. *****************************************************************************/ #define BOUNDS_CHECK #include <iostream> #include <bwt.h> #include <timing.h> using namespace std; using namespace splab; const int Ls = 100; int main() { /************************** [ signal ] *************************/ Vector<double> s(Ls); for(int i=0; i<Ls; i++) { if(i<Ls/4) s = 0.0; else if(i<2*Ls/4) s = 1.0; else if(i<3*Ls/4) s = 3.0; else s = 0.0; } /*************************** [ BWT ] ***************************/ int level = 3; Timing cnt; double runtime = 0.0; cout << "Taking dyadic wavelet transform." << endl; cnt.start(); Vector< Vector<double> > coefs = bwt( s, level ); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (s)" << endl << endl; /*************************** [ IBWT ] **************************/ cout << "Taking inverse dyadic wavelet transform." << endl; cnt.start(); Vector<double> x = ibwt( coefs, level ); cnt.stop(); runtime = cnt.read(); cout << "The running time = " << runtime << " (s)" << endl << endl; cout << "The relative error is : norm(s-x) / norm(s) = " << norm(s-x)/norm(s) << endl << endl; return 0; } |
» ²ÂÄãϲ»¶
362Çóµ÷¼Á
ÒѾÓÐ14È˻ظ´
Çóµ÷¼Á 302·Ö³õÊÔ 0854
ÒѾÓÐ4È˻ظ´
299Çóµ÷¼Á
ÒѾÓÐ4È˻ظ´
266·Ö£¬Ò»Ö¾Ô¸µçÆø¹¤³Ì£¬±¾¿Æ²ÄÁÏ£¬Çó²ÄÁÏרҵµ÷¼Á
ÒѾÓÐ3È˻ظ´
312Çóµ÷¼Á
ÒѾÓÐ4È˻ظ´
315Çóµ÷¼Á
ÒѾÓÐ7È˻ظ´
ÍÁľ304Çóµ÷¼Á
ÒѾÓÐ3È˻ظ´
316Çóµ÷¼Á
ÒѾÓÐ16È˻ظ´
Ò»Ö¾Ô¸»ª¶«Àí¹¤´óѧ£¬080500ѧ˶£¬317·Ö£¬Çóµ÷¼Á
ÒѾÓÐ13È˻ظ´
²ÄÁÏÓ뻯¹¤306·ÖÕÒµ÷¼Á
ÒѾÓÐ9È˻ظ´
fxj126
ľ³æ (СÓÐÃûÆø)
- Ó¦Öú: 35 (СѧÉú)
- ½ð±Ò: 3531
- É¢½ð: 18
- ºì»¨: 3
- Ìû×Ó: 242
- ÔÚÏß: 74.8Сʱ
- ³æºÅ: 2926855
- ×¢²á: 2014-01-11
- רҵ: ¹âѧ
2Â¥2016-05-27 16:30:19
sitp_710
Ìú³æ (СÓÐÃûÆø)
- Ó¦Öú: 1 (Ó×¶ùÔ°)
- ½ð±Ò: 505.7
- É¢½ð: 120
- ºì»¨: 1
- Ìû×Ó: 63
- ÔÚÏß: 29.4Сʱ
- ³æºÅ: 511941
- ×¢²á: 2008-02-26
- רҵ: »úÆ÷ÈËѧ¼°»úÆ÷È˼¼Êõ
3Â¥2016-05-28 08:43:26
wruieasy
Ìú³æ (³õÈëÎÄ̳)
- Ó¦Öú: 0 (Ó×¶ùÔ°)
- ½ð±Ò: 264
- Ìû×Ó: 45
- ÔÚÏß: 18.6Сʱ
- ³æºÅ: 2289036
- ×¢²á: 2013-02-19
- רҵ: Áã¼þ³ÉÐÎÖÆÔì
4Â¥2016-05-31 22:06:56
ÁÖ¿ÓÅÁ¿Ë
гæ (³õÈëÎÄ̳)
- Ó¦Öú: 0 (Ó×¶ùÔ°)
- ½ð±Ò: 37.5
- Ìû×Ó: 17
- ÔÚÏß: 21.6Сʱ
- ³æºÅ: 3457970
- ×¢²á: 2014-10-06
- ÐÔ±ð: GG
- רҵ: ¹¤³ÌÈÈÁ¦Ñ§
5Â¥2016-11-23 11:24:34
sitp_710
Ìú³æ (СÓÐÃûÆø)
- Ó¦Öú: 1 (Ó×¶ùÔ°)
- ½ð±Ò: 505.7
- É¢½ð: 120
- ºì»¨: 1
- Ìû×Ó: 63
- ÔÚÏß: 29.4Сʱ
- ³æºÅ: 511941
- ×¢²á: 2008-02-26
- רҵ: »úÆ÷ÈËѧ¼°»úÆ÷È˼¼Êõ
6Â¥2016-11-23 14:08:05














»Ø¸´´ËÂ¥