C代码小波变换及说明 [英] C Code Wavelet Transform and Explanation

查看:98
本文介绍了C代码小波变换及说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 C 中实现小波变换,但我以前从未这样做过.我读过一些关于小波的文章,理解了增长子空间"的想法,以及 Mallat 的单边滤波器组本质上是同一个想法.

I am trying to implement a wavelet transform in C and I have never done it before. I have read some about Wavelets, and understand the 'growing subspaces' idea, and how Mallat's one sided filter bank is essentially the same idea.

然而,我被困在如何实际实现 Mallat 的快速小波变换上.这是我目前的理解:

However, I am stuck on how to actually implement Mallat's fast wavelet transform. This is what I understand so far:

  1. 高通滤波器 h(t) 为您提供细节系数.对于给定的尺度 j,它是母小波 W(t) 的反射、扩张和归一化版本.

  1. The high pass filter, h(t), gives you the detail coefficients. For a given scale j, it is a reflected, dilated, and normed version of the mother wavelet W(t).

g(t) 是弥补差异的低通滤波器.应该是h(t)的正交镜

g(t) is then the low pass filter that makes up the difference. It is supposed to be the quadrature mirror of h(t)

要获得第 j 级的细节系数或近似系数,您需要分别将信号块与 h(t) 或 g(t) 进行卷积,并将信号下采样 2^{j}(即取每 2^{j} 个值)

To get the detail coefficients, or the approximation coefficients for the jth level, you need to convolve your signal block with h(t) or g(t) respectively, and downsample the signal by 2^{j} (ie take every 2^{j} value)

但是这些是我的问题:

  1. 当我知道 h(t) 时如何找到 g(t)?

  1. How can I find g(t) when I know h(t)?

如何计算此变换的逆?

你有任何我可以参考的 C 代码吗?(是的,我在 wiki 上找到了一个,但没有帮助)

Do you have any C code that I can reference? (Yes I found the one on wiki but it doesn't help)

我想说的代码是:

A.这是过滤器

B.这是转换(非常明确)C.) 这是逆变换(同样适用于假人)

B. Here is the transform (very explicitly) C.) Here is the inverse transform (again for dummies)

感谢您的耐心等待,但似乎没有步骤 1 - 步骤 2 - 步骤 3 等指南,并提供明确的示例(不是 HAAR,因为所有系数都是 1,这让事情变得混乱).

Thanks for your patience, but there doesn't seem to be a Step1 - Step2 - Step3 -- etc guide out there with explicit examples (that aren't HAAR because all the coefficients are 1s and that makes things confusing).

推荐答案

用于 fwt 的 Mallat 配方非常简单.如果您查看 matlab 代码,例如 script 由 Jeffrey Kantor 编写,所有步骤都很明显.

the Mallat recipe for the fwt is really simple. If you look at the matlab code, eg the script by Jeffrey Kantor, all the steps are obvious.

在 C 中需要做更多的工作,但这主要是因为您需要处理自己的声明和分配.

In C it is a bit more work but that is mainly because you need to take care of your own declarations and allocations.

首先,关于你的总结:

  1. 通常滤波器h是一个低通滤波器,代表缩放函数(父)
  2. 同样,g通常是代表小波(母)的高通滤波器
  3. 您不能在 1 个过滤 + 下采样步骤中执行 J 级分解.在每个级别,您通过使用 h 和下采样进行过滤来创建一个近似信号 c,并通过使用 g 进行过滤来创建一个细节信号 d 和下采样,并在下一级重复此操作(使用当前的 c)
  1. usually the filter h is a lowpass filter, representing the scaling function (father)
  2. likewise, g is usually the highpass filter representing the wavelet (mother)
  3. you cannot perform a J-level decomposition in 1 filtering+downsampling step. At each level, you create an approximation signal c by filtering with h and downsampling, and a detail signal d by filtering with g and downsampling, and repeat this at the next level (using the current c)

关于您的问题:

About your questions:

  1. 对于正交小波基的滤波器 h,[h_1 h_2 .. h_m h_n],QMF 为 [h_n -h_m .. h_2 -h_1],其中 n 是偶数,m==n-1
  2. 逆变换与 fwt 相反:在每个级别上,它对细节 d 和近似值 c 进行上采样,将 d 卷积>gch,并将信号加在一起——参见对应的 matlab 脚本.
  1. for a filter h of an an orthogonal wavelet basis, [h_1 h_2 .. h_m h_n], the QMF is [h_n -h_m .. h_2 -h_1], where n is an even number and m==n-1
  2. the inverse transform does the opposite of the fwt: at each level it upsamples detail d and approximation c, convolves d with g and c with h, and adds the signals together -- see the corresponding matlab script.

使用这个信息,并给定一个 len 类型的 double 点的信号 x,缩放 hf 系数(也是 double 类型)的小波 g 过滤器,以及分解级别 lev,这一段代码实现了 Mallat fwt:

Using this information, and given a signal x of len points of type double, scaling h and wavelet g filters of f coefficients (also of type double), and a decomposition level lev, this piece of code implements the Mallat fwt:

double *t=calloc(len+f-1, sizeof(double));
memcpy(t, x, len*sizeof(double));        
for (int i=0; i<lev; i++) {            
    memset(y, 0, len*sizeof(double));
    int len2=len/2;
    for (int j=0; j<len2; j++)           
        for (int k=0; k<f; k++) {          
            y[j]     +=t[2*j+k]*h[k];      
            y[j+len2]+=t[2*j+k]*g[k];      
        }
    len=len2;                            
    memcpy(t, y, len*sizeof(double));    
}
free(t);

它使用一个额外的数组:一个工作区"t 来复制近似c(输入信号x 开始)为下一次迭代.

It uses one extra array: a 'workspace' t to copy the approximation c (the input signal x to start with) for the next iteration.

看这个例子 C program,你可以用 gcc 编译 -std=c99 -fpermissive main.cpp 并使用 ./a.out 运行.

See this example C program, which you can compile with gcc -std=c99 -fpermissive main.cpp and run with ./a.out.

逆也应该是这样的.祝你好运!

The inverse should also be something along these lines. Good luck!

这篇关于C代码小波变换及说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆