资源简介
使用小波DB4进行分解一维信号,进行三层分解,可以自行修改,实现多层分解。
代码片段和文件信息
#include “stdio.h“
#include “stdlib.h“
#include “math.h“
#include “string.h“
#include “ctype.h“
#include
typedef struct {
/* pointers to coupled filters */
/* analysis */
double* p_h; /* h low pass analysis filter */
double* p_g; /* g high pass analysis filter */
/* synthesis */
double* p_H; /* h~ low pass synthesis filter */
double* p_G; /* g~ high pass synthesis filter */
/* filters length */
union
{
int hlen; /* length of h filter */
int Glen; /* length of g~ filter */
};
union
{
int Hlen; /* length of h~ filter */
int glen; /* length of g filter */
};
/* filters offsides */
int os_h; /* offside of filter h */
int os_g; /* offside of filter g */
} WAVELET_COEFF;
static void get_coupled_coeffs(double* pin double* pout int ilen)
{
int i;
int isign;
isign = -1;
/* get the coupled coeffs */
for(i = 0; i < ilen; i++)
{
*(pout + i) = *(pin + ilen - i - 1) * isign;
isign = isign * -1;
}
}
/*
initialize the wavelet coefficients
if pH is 0 the wavelet is orthogonal
if the function succeeds return 1. otherwise return 0.
*/
static void wavelet_coeffs_init(
WAVELET_COEFF* pwvlt /* pointer to wavelet strut */
double* ph /* h coeffs */
int ilen_h /* h coeff length */
double* pH /* h~ coeffs */
int ilen_H /* h~ coeff length */
int os_h /* h offside */
int os_g /* g offside */
)
{
/* orthogonal */
/* allocate coupled coefficients buffer */
pwvlt->p_g = (double*)malloc(sizeof(double) * ilen_h);
/* For orthogonal wavelets using the relation: */
/* g[n] = (-1)^n * h[1-n] */
get_coupled_coeffs(ph pwvlt->p_g ilen_h);
/* set wavelet coeffs */
pwvlt->p_h = ph;
pwvlt->p_H = ph;
pwvlt->p_G = pwvlt->p_g;
/* wavelet length */
pwvlt->hlen = ilen_h;
pwvlt->glen = ilen_h;
/* set wavelet offsides */
pwvlt->os_h = os_h;
pwvlt->os_g = os_g;
}
static void wavelet_clear(WAVELET_COEFF* pwvlt)
{
if(pwvlt->p_g)
free(pwvlt->p_g);
}
static void dwt_1d_analysis(
WAVELET_COEFF* pwvlt /* pointer to wavelet strut */
double* pin /* input sequence */
int ilen /* input sequence length */
double* pout /* result sequence */
)
{
int i j k n;
double* ph *pg; /* pointers to wavelet coeffs */
double* p1 *p2; /* temporary pointers */
/* the transform equation is: */
/* smooth part: a(j+1)[p] = sum(n=1..N1){a(j)[2p-n]*h[-n]} */
/* detail part: d(j+1)[p] = sum(n=1..N2){a(j)[2p-n]*g[-n]} */
/* where N1 is the length of h N2 is the length of g */
/* a(j) is the input sequence */
n = ilen / 2;
/* point to the end of wavelet coeffs */
ph = pwvlt->p_h + pwvlt->hlen - 1;
pg = pwvlt->p_g + pwvlt->glen - 1;
/* orthogonal */
/* handle the left offside */
for(i = 0; i < pwvlt->hlen / 2; i++)
{
/* smooth component */
k = i - pwvlt->os_h;
k = k < 0 ? k + n : k;
p1 = pout + k;
*p1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 512 2008-03-26 10:36 最新小波程序\aa.dsw
文件 50176 2008-03-26 21:27 最新小波程序\aa.ncb
文件 5844 2008-03-24 11:03 最新小波程序\wdata.dat
文件 1222 2008-03-26 21:26 最新小波程序\aa.plg
文件 8064 2008-03-26 21:26 最新小波程序\负荷.txt
文件 3905 2008-03-26 11:20 最新小波程序\a.cpp
文件 8064 2008-03-26 21:26 最新小波程序\重构.txt
文件 4291 2008-03-26 19:27 最新小波程序\aa.dsp
文件 1092 2008-03-26 21:26 最新小波程序\三层低频系数.txt
文件 1008 2008-03-26 21:26 最新小波程序\三层高频系数.txt
文件 2016 2008-03-26 21:26 最新小波程序\二层高频系数.txt
文件 4032 2008-03-26 21:26 最新小波程序\一层高频系数.txt
文件 10195 2008-03-26 21:24 最新小波程序\a.h
文件 44378 2008-03-26 21:26 最新小波程序\compare.txt
文件 1928 2008-03-26 21:26 最新小波程序\c.cpp
文件 48640 2008-03-26 21:27 最新小波程序\aa.opt
目录 0 2008-03-26 10:36 最新小波程序\Debug
目录 0 2008-03-26 10:36 最新小波程序
----------- --------- ---------- ----- ----
195585 19
评论
共有 条评论