±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 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;
}
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

fxj126

ľ³æ (СÓÐÃûÆø)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï ¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
sitp_710: ½ð±Ò+10, ¡ï¡ï¡ïºÜÓаïÖú, ¸Ðл´ð¸´ 2016-05-28 08:35:23
Ö±½Ó#include<vector>ÊÔÊÔ£¿
2Â¥2016-05-27 16:30:19
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

sitp_710

Ìú³æ (СÓÐÃûÆø)

ÒýÓûØÌû:
2Â¥: Originally posted by fxj126 at 2016-05-27 16:30:19
Ö±½Ó#include<vector>ÊÔÊÔ£¿

¸Ðл´ð¸´£¡ÔÚbwt.hÍ·ÎļþÖУ¬¸ÄдΪinclude<vector>£¬ÕÒ²»µ½vector.hµÄ±àÒë´íÎóûÓÐÁË£¬ÓÖ³öÏÖÈçÏÂһЩ´íÎóÌáʾ£º
´íÎó        1        error C1083: ÎÞ·¨´ò¿ª°üÀ¨Îļþ:¡°utilities.h¡±: No such file or directory
        2        IntelliSense: ÎÞ·¨´ò¿ª Ô´ Îļþ "timing.h"       
        3        IntelliSense: 䶨Òå±êʶ·û "Vector"       
»¹ÓÐһЩÆäËûµÄ´íÎó£¬ÇëÎÊÕ⼸¸öÍ·ÎļþÊDZàÒëÆ÷Ìṩ¹«Óе쬻¹ÊÇÔ­×÷Õß±àдµÄµ«Ã»ÓÐÌṩµÄÍ·Îļþ£¿Ð»Ð»£¡
±àÒëÌáʾ"vector.h"ÎÞ·¨ÕÒµ½£¬´ó¼ÒÄܰï²âÊÔÏÂÕâ¸öС²¨±ä»»³ÌÐòÂð£¿
´íÎóÌáʾ.JPG

3Â¥2016-05-28 08:43:26
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

wruieasy

Ìú³æ (³õÈëÎÄ̳)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

ÊDz»ÊÇÍü¼ÇÏÂÔØvector.hºÍvector.cppÁË£¿VecotrÀàÔÚvector.h±»¶¨Ò壿
4Â¥2016-05-31 22:06:56
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ÁÖ¿ÓÅÁ¿Ë

гæ (³õÈëÎÄ̳)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

ÊDz»ÊÇÍü¼ÇÏÂÔØvector.hºÍvector.cppÁË£¿VecotrÀàÔÚvector.h±»¶¨Ò壿
5Â¥2016-11-23 11:24:34
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

sitp_710

Ìú³æ (СÓÐÃûÆø)

Êǵģ¬ÎÒÒѽâ¾ö£¬ºóÀ´ÕÒµ½Õâ¸öÎļþÁË£¡

·¢×ÔСľ³æAndroid¿Í»§¶Ë
6Â¥2016-11-23 14:08:05
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ sitp_710 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] ũѧ¿¼ÑÐÇóµ÷¼Á +3 dkdkxm 2026-04-01 3/150 2026-04-02 16:04 by wangjagri
[¿¼ÑÐ] 342Çóµ÷¼Á +13 Mary Keen 2026-03-28 14/700 2026-04-02 14:28 by olim
[¿¼ÑÐ] ÄÜÔ´¶¯Á¦ µ÷¼Á +3 ²»ÆÆ²»Á¢0 2026-04-02 3/150 2026-04-02 12:46 by ffffjjjj
[¿¼ÑÐ] Çóµ÷¼ÁÍÆ¼ö +3 ÄÏɽÄÏ@ 2026-04-01 3/150 2026-04-02 12:09 by xiaoranmu
[¿¼ÑÐ] 311Çóµ÷¼Á +9 Ó¸ҵÄСÎâ 2026-04-02 9/450 2026-04-02 11:37 by Sammy2
[¿¼ÑÐ] 272Çóµ÷¼Á£¬½ÓÊÜ¿çרҵµ÷¼Á£¡ +4 ÏÐÓ㬠2026-03-31 4/200 2026-04-02 11:18 by guyan1000
[¿¼ÑÐ] 266Çóµ÷¼Á +4 ѧԱ97LZgn 2026-04-02 4/200 2026-04-02 09:52 by yulian1987
[¿¼ÑÐ] Ò»Ö¾Ô¸211£¬335·Ö£¬0856£¬Çóµ÷¼ÁԺУºÍµ¼Ê¦ +14 Çã____Ïô 2026-03-27 15/750 2026-04-02 09:21 by olim
[¿¼ÑÐ] Çóµ÷¼Á£¬Ò»Ö¾Ô¸ÄϾ©Ê¦·¶´óѧ¼ÆËã»úר˶£¬³õÊÔ373£¬Áù¼¶Í¨¹ý£¬ +3 ¼ÆËã»ú×·ÃÎÈË 2026-04-01 3/150 2026-04-02 07:57 by fxue1114
[¿¼ÑÐ] 320·Ö£¬²ÄÁÏÓ뻯¹¤×¨Òµ£¬Çóµ÷¼Á +14 Ò»¶¨Éϰ¶aaa 2026-03-27 18/900 2026-04-01 20:10 by »ý¼«µ÷¼ÁµÄСѧÉ
[¿¼ÑÐ] µ÷¼Á +3 ºÃºÃ¶ÁÊé¡£ 2026-04-01 3/150 2026-04-01 17:06 by zhouyuwinner
[¿¼ÑÐ] µ÷¼Á +5 ºÃºÃ¶ÁÊé¡£ 2026-03-28 7/350 2026-04-01 15:32 by ÍõÁÁ_´óÁ¬Ò½¿Æ´ó
[¿¼ÑÐ] 318Çóµ÷¼Á +8 ÆßÒä77 2026-04-01 8/400 2026-04-01 10:37 by Jaylen.
[¿¼ÑÐ] ¡¾µ÷¼Á¡¿Ò»Ö¾Ô¸ÏôóÉúÎïÓëÒ½Ò©µ÷¼Á +3 EchoϺÃ× 2026-03-31 3/150 2026-04-01 08:40 by JourneyLucky
[¿¼ÑÐ] 070300»¯Ñ§354Çóµ÷¼Á +15 101´ÎÏ£Íû 2026-03-28 15/750 2026-03-31 17:58 by jp9609
[¿¼ÑÐ] 254²ÄÁÏÓ뻯¹¤Çóµ÷¼Á +3 º²¶¬ÁÖéª 2026-03-30 4/200 2026-03-31 17:53 by yishunmin
[¿¼ÑÐ] 315Çóµ÷¼Á +6 akie... 2026-03-28 7/350 2026-03-31 16:48 by asdfzly
[¿¼ÑÐ] 263Çóµ÷¼Á +3 DDDDuu 2026-03-27 3/150 2026-03-31 16:21 by ÍÁľ˶ʿÕÐÉú
[¿¼ÑÐ] ÄϾ©´óѧ»¯Ñ§µ÷¼Á +11 ¾°Ëæ·ç 2026-03-29 16/800 2026-03-31 10:14 by herarysara
[¿¼ÑÐ] 083000ѧ˶274Çóµ÷¼Á +12 LiÀîÓã 2026-03-26 12/600 2026-03-31 10:01 by cal0306
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û