沃尔什变换是由+1或-1的基本函数的级数展开而成的,满足完备正交特性,属于方波型正交变换。由于沃尔什函数是二值正交函数,与数字逻辑中的两个状态相对应,因此它更适用于计算机技术、数字信号处理
沃尔什变换要求空域矩阵阶数 N N N满足 N = 2 n N=2^n N=2n,若满足,则有: F ( μ ) = ∑ x = 0 N − 1 f ( x ) g ( x , μ ) F(\mu)=\sum_{x=0}^{N-1}f(x)g(x,\mu) F(μ)=x=0∑N−1f(x)g(x,μ) g ( x , μ ) = 1 N ∏ i = 0 n − 1 ( − 1 ) ∑ i = 0 n − 1 b i ( x ) b n − 1 ( μ ) g(x,\mu)=\frac{1}{N}\prod_{i=0}^{n-1}(-1)^{\sum_{i=0}^{n-1}b_i(x)b_{n-1}(\mu)} g(x,μ)=N1i=0∏n−1(−1)∑i=0n−1bi(x)bn−1(μ)一维沃尔什反变换: f ( x ) = ∑ x = 0 N − 1 F ( μ ) h ( x , μ ) f(x)=\sum_{x=0}^{N-1}F(\mu)h(x,\mu) f(x)=x=0∑N−1F(μ)h(x,μ) h ( x , μ ) = ∏ i = 0 n − 1 ( − 1 ) ∑ i = 0 n − 1 b i ( x ) b n − 1 ( μ ) h(x,\mu)=\prod_{i=0}^{n-1}(-1)^{\sum_{i=0}^{n-1}b_i(x)b_{n-1}(\mu)} h(x,μ)=i=0∏n−1(−1)∑i=0n−1bi(x)bn−1(μ)其中, b i ( x ) b_i(x) bi(x)是 x x x的二进制表达式中第 i i i位的意思
例如 N = 2 n N=2^n N=2n, n = 3 n=3 n=3, x = 6 x=6 x=6,则有 x = 6 = ( 110 ) 2 x=6=(110)_2 x=6=(110)2,可得 b 0 ( x ) = 0 b_0(x)=0 b0(x)=0、 b 1 ( x ) = 1 b_1(x)=1 b1(x)=1、 b 2 ( x ) = 1 b_2(x)=1 b2(x)=1
与傅立叶变换不同,沃尔什变换的变换核是由+1或-1构成的二值对称矩阵
例如:求 N = 2 2 N=2^2 N=22的沃尔什变换 F ( 0 ) = 1 4 ∑ x = 0 3 [ f ( x ) ∏ i = 0 1 ( − 1 ) b i ( x ) + b 1 − i ( 0 ) ] = 1 4 [ f ( 0 ) + f ( 1 ) + f ( 2 ) + f ( 3 ) ] F(0)=\frac{1}{4}\sum_{x=0}^{3}[f(x)\prod_{i=0}^{1}(-1)^{b_i(x)+b_{1-i}(0)}]=\frac{1}{4}[f(0)+f(1)+f(2)+f(3)] F(0)=41x=0∑3[f(x)i=0∏1(−1)bi(x)+b1−i(0)]=41[f(0)+f(1)+f(2)+f(3)] F ( 1 ) = 1 4 ∑ x = 0 3 [ f ( x ) ∏ i = 0 1 ( − 1 ) b i ( x ) + b 1 − i ( 1 ) ] = 1 4 [ f ( 0 ) + f ( 1 ) − f ( 2 ) − f ( 3 ) ] F(1)=\frac{1}{4}\sum_{x=0}^{3}[f(x)\prod_{i=0}^{1}(-1)^{b_i(x)+b_{1-i}(1)}]=\frac{1}{4}[f(0)+f(1)-f(2)-f(3)] F(1)=41x=0∑3[f(x)i=0∏1(−1)bi(x)+b1−i(1)]=41[f(0)+f(1)−f(2)−f(3)] F ( 2 ) = 1 4 ∑ x = 0 3 [ f ( x ) ∏ i = 0 1 ( − 1 ) b i ( x ) + b 1 − i ( 2 ) ] = 1 4 [ f ( 0 ) − f ( 1 ) + f ( 2 ) − f ( 3 ) ] F(2)=\frac{1}{4}\sum_{x=0}^{3}[f(x)\prod_{i=0}^{1}(-1)^{b_i(x)+b_{1-i}(2)}]=\frac{1}{4}[f(0)-f(1)+f(2)-f(3)] F(2)=41x=0∑3[f(x)i=0∏1(−1)bi(x)+b1−i(2)]=41[f(0)−f(1)+f(2)−f(3)] F ( 3 ) = 1 4 ∑ x = 0 3 [ f ( x ) ∏ i = 0 1 ( − 1 ) b i ( x ) + b 1 − i ( 3 ) ] = 1 4 [ f ( 0 ) − f ( 1 ) − f ( 2 ) + f ( 3 ) ] F(3)=\frac{1}{4}\sum_{x=0}^{3}[f(x)\prod_{i=0}^{1}(-1)^{b_i(x)+b_{1-i}(3)}]=\frac{1}{4}[f(0)-f(1)-f(2)+f(3)] F(3)=41x=0∑3[f(x)i=0∏1(−1)bi(x)+b1−i(3)]=41[f(0)−f(1)−f(2)+f(3)]其中方括号中各项的符号即位变换核的符号
可见沃尔什变换的本质是将离散序列 f ( x ) f(x) f(x)中各项值的符号按规律改变进行加减运算
F ( μ , ν ) = 1 N ∑ x = 0 N − 1 ∑ x = 0 N − 1 f ( x , y ) g ( x , y , μ , ν ) F(\mu,\nu)=\frac{1}{N}\sum_{x=0}^{N-1}\sum_{x=0}^{N-1}f(x,y)g(x,y,\mu,\nu) F(μ,ν)=N1x=0∑N−1x=0∑N−1f(x,y)g(x,y,μ,ν) f ( x , y ) = 1 N ∑ μ = 0 N − 1 ∑ ν = 0 N − 1 F ( μ , ν ) g ( x , y , μ , ν ) f(x,y)=\frac{1}{N}\sum_{\mu=0}^{N-1}\sum_{\nu=0}^{N-1}F(\mu,\nu)g(x,y,\mu,\nu) f(x,y)=N1μ=0∑N−1ν=0∑N−1F(μ,ν)g(x,y,μ,ν) g ( x , y , μ , ν ) = G = 1 N ∏ i = 0 n − 1 ( − 1 ) ∑ i = 0 n − 1 [ b i ( x ) b n − 1 − i ( μ ) + b i ( y ) b n − 1 − i ( ν ) ] g(x,y,\mu,\nu)=G=\frac{1}{N}\prod_{i=0}^{n-1}(-1)^{\sum_{i=0}^{n-1}[b_i(x)b_{n-1-i}(\mu)+b_i(y)b_{n-1-i}(\nu)]} g(x,y,μ,ν)=G=N1i=0∏n−1(−1)∑i=0n−1[bi(x)bn−1−i(μ)+bi(y)bn−1−i(ν)]表达为矩阵形式为 F = 1 N 2 G f G F=\frac{1}{N^2}GfG F=N21GfG f = G F G f=GFG f=GFG
与傅立叶变换一样,二维沃尔什变换是可分离的,可以通过两个一维沃尔什变换完成计算 g ( x , y , μ , ν ) = g 1 ( x , μ ) g 2 ( y , ν ) g(x,y,\mu,\nu)=g_1(x,\mu)g_2(y,\nu) g(x,y,μ,ν)=g1(x,μ)g2(y,ν)
实例:求离散沃尔什变换
f = [ 1 3 3 1 1 3 3 1 1 3 3 1 1 3 3 1 ] f=\begin{bmatrix} 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ \end{bmatrix} f=⎣⎢⎢⎡1111333333331111⎦⎥⎥⎤可知 N = 4 N=4 N=4,其变换核为 G = [ 1 1 1 1 1 1 − 1 − 1 1 − 1 1 − 1 1 − 1 − 1 1 ] G=\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & 1 & -1 \\ 1 & -1 & -1 & 1 \\ \end{bmatrix} G=⎣⎢⎢⎡111111−1−11−11−11−1−11⎦⎥⎥⎤则有 F = 1 N 2 G f G = 1 4 2 [ 1 1 1 1 1 1 − 1 − 1 1 − 1 1 − 1 1 − 1 − 1 1 ] [ 1 3 3 1 1 3 3 1 1 3 3 1 1 3 3 1 ] [ 1 1 1 1 1 1 − 1 − 1 1 − 1 1 − 1 1 − 1 − 1 1 ] = [ 2 0 0 − 1 0 0 0 0 0 0 0 0 0 0 0 0 ] F=\frac{1}{N^2}GfG=\frac{1}{4^2}\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & 1 & -1 \\ 1 & -1 & -1 & 1 \\ \end{bmatrix}\begin{bmatrix} 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ \end{bmatrix}\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & 1 & -1 \\ 1 & -1 & -1 & 1 \\ \end{bmatrix}=\begin{bmatrix} 2 & 0 & 0 & -1 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix} F=N21GfG=421⎣⎢⎢⎡111111−1−11−11−11−1−11⎦⎥⎥⎤⎣⎢⎢⎡1111333333331111⎦⎥⎥⎤⎣⎢⎢⎡111111−1−11−11−11−1−11⎦⎥⎥⎤=⎣⎢⎢⎡200000000000−1000⎦⎥⎥⎤可以看出,沃尔什变换具有信息集中的作用,原始数据中数字越是均匀分布,变换后的数据越是集中于边角区域
与沃尔什变换类似,由哈达玛变换核组成的矩阵是一个正交对称矩阵,属于方波型正交变换,不同之处在于其行、列次序不一样。
哈达玛变换要求空域矩阵阶数 N N N满足 N = 2 n N=2^n N=2n,若满足,则有: F ( μ ) = ∑ x = 0 N − 1 f ( x ) g ( x , μ ) F(\mu)=\sum_{x=0}^{N-1}f(x)g(x,\mu) F(μ)=x=0∑N−1f(x)g(x,μ) g ( x , μ ) = 1 N ( − 1 ) ∑ i = 0 n − 1 b i ( x ) b i ( μ ) g(x,\mu)=\frac{1}{N}(-1)^{\sum_{i=0}^{n-1}b_i(x)b_{i}(\mu)} g(x,μ)=N1(−1)∑i=0n−1bi(x)bi(μ)一维哈达玛反变换: f ( x ) = ∑ x = 0 N − 1 F ( μ ) h ( x , μ ) f(x)=\sum_{x=0}^{N-1}F(\mu)h(x,\mu) f(x)=x=0∑N−1F(μ)h(x,μ) h ( x , μ ) = ( − 1 ) ∑ i = 0 n − 1 b i ( x ) b i ( μ ) h(x,\mu)=(-1)^{\sum_{i=0}^{n-1}b_i(x)b_{i}(\mu)} h(x,μ)=(−1)∑i=0n−1bi(x)bi(μ) b i ( x ) b_i(x) bi(x)是 x x x的二进制表达式中第 i i i位的意思
F ( μ , ν ) = 1 N ∑ x = 0 N − 1 ∑ x = 0 N − 1 f ( x , y ) g ( x , y , μ , ν ) F(\mu,\nu)=\frac{1}{N}\sum_{x=0}^{N-1}\sum_{x=0}^{N-1}f(x,y)g(x,y,\mu,\nu) F(μ,ν)=N1x=0∑N−1x=0∑N−1f(x,y)g(x,y,μ,ν) f ( x , y ) = 1 N ∑ μ = 0 N − 1 ∑ ν = 0 N − 1 F ( μ , ν ) g ( x , y , μ , ν ) f(x,y)=\frac{1}{N}\sum_{\mu=0}^{N-1}\sum_{\nu=0}^{N-1}F(\mu,\nu)g(x,y,\mu,\nu) f(x,y)=N1μ=0∑N−1ν=0∑N−1F(μ,ν)g(x,y,μ,ν) g ( x , y , μ , ν ) = G = 1 N ( − 1 ) ∑ i = 0 n − 1 [ b i ( x ) b i ( μ ) + b i ( y ) b i ( ν ) ] g(x,y,\mu,\nu)=G=\frac{1}{N}(-1)^{\sum_{i=0}^{n-1}[b_i(x)b_{i}(\mu)+b_i(y)b_{i}(\nu)]} g(x,y,μ,ν)=G=N1(−1)∑i=0n−1[bi(x)bi(μ)+bi(y)bi(ν)]二维哈达玛变换是可分离的,可变换为两个一维哈达玛变换来进行计算。
列率
在哈达玛矩阵中,沿列方向上符号改变的次数称为列率,类似傅立叶变换中频率的概念。
例如有矩阵 H = [ 1 1 1 1 1 − 1 1 − 1 1 1 − 1 − 1 1 − 1 − 1 1 ] H=\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1\\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1\\ \end{bmatrix} H=⎣⎢⎢⎡11111−11−111−1−11−1−11⎦⎥⎥⎤
其第一列元素符号无变化,于是第一列的列率为0;
第二列 a 12 a_{12} a12到 a 22 a_{22} a22符号由正变负、 a 22 a_{22} a22到 a 32 a_{32} a32符号由负变正、 a 32 a_{32} a32到 a 42 a_{42} a42符号由正变负,共改变3次,因此第二列的列率为3;以此类推,第三列的列率为1,第四列的列率为2
哈达玛变换在列率上是随机的,不利于实现逐次倍加法的快速运算,但是能导出一个简单的递推关系,构造其变换矩阵,而后进行哈达玛正向和反向变换
哈达玛变换核矩阵
在满足 N = 2 n N=2^n N=2n的情况下
有最低阶 N = 2 N=2 N=2时的哈达玛变换矩阵 H 2 H_2 H2为: H 2 = [ 1 1 1 − 1 ] H_2=\begin{bmatrix} 1 & 1 \\ 1 & -1 \\ \end{bmatrix} H2=[111−1]有任意阶 N = 2 N N=2N N=2N时的哈达玛矩阵为: H 2 N = [ H N H N H N − H N ] H_{2N}=\begin{bmatrix} H_N & H_N \\ H_N & -H_N \\ \end{bmatrix} H2N=[HNHNHN−HN]由此可推得: H 4 = [ H 2 H 2 H 2 − H 2 ] , H 8 = [ H 4 H 4 H 4 − H 4 ] , . . . H_{4}=\begin{bmatrix} H_2 & H_2 \\ H_2 & -H_2 \\ \end{bmatrix},H_{8}=\begin{bmatrix} H_4 & H_4 \\ H_4 & -H_4 \\ \end{bmatrix},... H4=[H2H2H2−H2],H8=[H4H4H4−H4],...
将哈达玛矩阵按照列率顺序排列,得到定序的哈达玛变换对为: F ( μ , ν ) = 1 N ∑ x = 0 N − 1 ∑ x = 0 N − 1 f ( x , y ) g ( x , y , μ , ν ) F(\mu,\nu)=\frac{1}{N}\sum_{x=0}^{N-1}\sum_{x=0}^{N-1}f(x,y)g(x,y,\mu,\nu) F(μ,ν)=N1x=0∑N−1x=0∑N−1f(x,y)g(x,y,μ,ν) f ( x , y ) = 1 N ∑ μ = 0 N − 1 ∑ ν = 0 N − 1 F ( μ , ν ) g ( x , y , μ , ν ) f(x,y)=\frac{1}{N}\sum_{\mu=0}^{N-1}\sum_{\nu=0}^{N-1}F(\mu,\nu)g(x,y,\mu,\nu) f(x,y)=N1μ=0∑N−1ν=0∑N−1F(μ,ν)g(x,y,μ,ν) g ( x , y , μ , ν ) = G = 1 N ( − 1 ) ∑ i = 0 n − 1 [ b i ( x ) p i ( μ ) + b i ( y ) p i ( ν ) ] g(x,y,\mu,\nu)=G=\frac{1}{N}(-1)^{\sum_{i=0}^{n-1}[b_i(x)p_{i}(\mu)+b_i(y)p_{i}(\nu)]} g(x,y,μ,ν)=G=N1(−1)∑i=0n−1[bi(x)pi(μ)+bi(y)pi(ν)]其中 p 0 ( μ ) = b n − 1 ( μ ) p i ( μ ) = b n − i ( μ ) + b n − 1 − i ( μ ) \begin{aligned} p_0(\mu) & = b_{n-1}(\mu) \\ p_i(\mu) & = b_{n-i}(\mu)+b_{n-1-i}(\mu) \\ \end{aligned} p0(μ)pi(μ)=bn−1(μ)=bn−i(μ)+bn−1−i(μ)表达为矩阵形式为 F = 1 N 2 H f H F=\frac{1}{N^2}HfH F=N21HfH f = H F H f=HFH f=HFH
实例:求离散哈达玛变换 f = [ 1 3 3 1 1 3 3 1 1 3 3 1 1 3 3 1 ] f=\begin{bmatrix} 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ 1 & 3 & 3 & 1 \\ \end{bmatrix} f=⎣⎢⎢⎡1111333333331111⎦⎥⎥⎤易知 N = 4 N=4 N=4,其哈达玛变换核矩阵为: H 4 = [ H 2 H 2 H 2 − H 2 ] = [ 1 1 1 1 1 − 1 1 − 1 1 1 − 1 − 1 1 − 1 − 1 1 ] H_{4}=\begin{bmatrix} H_2 & H_2 \\ H_2 & -H_2 \\ \end{bmatrix}=\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1\\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1\\ \end{bmatrix} H4=[H2H2H2−H2]=⎣⎢⎢⎡11111−11−111−1−11−1−11⎦⎥⎥⎤ H 4 H_4 H4按列率排序后得到 H 4 = [ 1 1 1 1 1 1 − 1 − 1 1 − 1 − 1 1 1 − 1 1 − 1 ] H_4=\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 1 & -1 & -1\\ 1 & -1 & -1 & 1 \\ 1 & -1 & 1 & -1\\ \end{bmatrix} H4=⎣⎢⎢⎡111111−1−11−1−111−11−1⎦⎥⎥⎤由此按照哈达玛变换的计算公式可得 F = 1 N 2 H 4 f H 4 = [ 2 0 − 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ] F=\frac{1}{N^2}H_4fH_4=\begin{bmatrix} 2 & 0 & -1 & 0 \\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0\\ \end{bmatrix} F=N21H4fH4=⎣⎢⎢⎡20000000−10000000⎦⎥⎥⎤
将沃尔什变换与哈达玛变换进行对比可以发现,两个变换的结果之间只是矩阵列的顺序不同,不会影响两者应用于压缩时的效率