- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试编写一个简单的独立程序,该程序使用 CDF 9/7 小波对一维列表执行单级离散小波变换,然后对其进行重构。我只是使用卷积/滤波器组方法来了解它的工作原理。换句话说,将列表与滤波器进行卷积以获得比例系数,将列表与不同的滤波器进行卷积以获得小波系数,但只能从所有其他元素开始执行此操作。然后上采样(即在元素之间添加零),对小波和比例系数应用滤波器,将它们加在一起,得到原始列表。
我可以让它为 Haar 小波滤波器工作,但是当我尝试使用 CDF 9/7 滤波器时,它不会产生相同的输入。然而,结果列表和原始列表的总和是一样的。
我确定这是卷积中的一个非常愚蠢的错误,但我就是想不通。我已经尝试了一堆卷积排列,比如将过滤器集中在索引“i”上,而不是从它的左边缘开始,但似乎没有任何效果......这可能是那些会造成的错误之一当我弄清楚时,我拍了拍我的头。
代码如下:
import random
import math
length = 128
array = list()
row = list()
scaleCoefficients = list()
waveletCoefficients = list()
reconstruction = list()
def upsample(lst, index):
if (index % 2 == 0):
return 0.0
else:
return lst[index/2]
for i in range(length):
array.append(random.random())
## CDF 9/7 Wavelet (doesn't work?)
DWTAnalysisLowpass = [.026749, -.016864, -.078223, .266864, .602949, .266864, -.078223, -.016864, .026749]
for i in range(len(DWTAnalysisLowpass)):
DWTAnalysisLowpass[i] = math.sqrt(2.0) * DWTAnalysisLowpass[i]
DWTAnalysisHighpass = [0.0, .091272, -.057544, -0.591272, 1.115087, -.591272, -.057544, .091272, 0.0]
for i in range(len(DWTAnalysisHighpass)):
DWTAnalysisHighpass[i] = 1.0/math.sqrt(2.0) * DWTAnalysisHighpass[i]
DWTSynthesisLowpass = [0.0, -.091272, -.057544, 0.591272, 1.115087, .591272, -.057544, -.091272, 0.0]
for i in range(len(DWTSynthesisLowpass)):
DWTSynthesisLowpass[i] = 1.0/math.sqrt(2.0) * DWTSynthesisLowpass[i]
DWTSynthesisHighpass = [.026749, .016864, -.078223, -.266864, .602949, -.266864, -.078223, .016864, .026749]
for i in range(len(DWTSynthesisHighpass)):
DWTSynthesisHighpass[i] = math.sqrt(2.0) * DWTSynthesisHighpass[i]
## Haar Wavelet (Works)
## c = 1.0/math.sqrt(2)
## DWTAnalysisLowpass = [c,c]
## DWTAnalysisHighpass = [c, -c]
## DWTSynthesisLowpass = [c, c]
## DWTSynthesisHighpass = [-c, c]
## Do the forward transform - we only need to do it on half the elements
for i in range(0,length,2):
newVal = 0.0
## Convolve the next j elements
for j in range(len(DWTAnalysisLowpass)):
index = i + j
if(index >= length):
index = index - length
newVal = newVal + array[index]*DWTAnalysisLowpass[j]
scaleCoefficients.append(newVal)
newVal = 0.0
for j in range(len(DWTAnalysisHighpass)):
index = i + j
if(index >= length):
index = index - length
newVal = newVal + array[index]*DWTAnalysisHighpass[j]
waveletCoefficients.append(newVal)
## Do the inverse transform
for i in range(length):
newVal = 0.0
for j in range(len(DWTSynthesisHighpass)):
index = i + j
if(index >= length):
index = index - length
newVal = newVal + upsample(waveletCoefficients, index)*DWTSynthesisHighpass[j]
for j in range(len(DWTSynthesisLowpass)):
index = i + j
if(index >= length):
index = index - length
newVal = newVal + upsample(scaleCoefficients, index)*DWTSynthesisLowpass[j]
reconstruction.append(newVal)
print sum(reconstruction)
print sum(array)
print reconstruction
print array
顺便说一句,我从这里的附录中获取了过滤器值:http://www1.cs.columbia.edu/~rso2102/AWR/Files/Overbeck2009AWR.pdf ,但我也看到它们也用在一堆 matlab 示例代码中。
最佳答案
实际上,我自己通过比较系数,然后使用此提升实现中的代码进行重构来解决了这个问题:
http://www.embl.de/~gpau/misc/dwt97.c
基本上,我1) 使边界条件对称,而不是周期性的2) 必须以某些方式抵消卷积(和上采样)才能使其全部对齐。
这是代码,以防其他人遇到问题。我觉得这仍然过于复杂,特别是因为它没有真正记录在任何地方,但至少它有效。这还包括我用来针对该引用进行测试的“开关”,我必须修改 Haar 小波才能使其工作。
import random
import math
length = int()
array = list()
row = list()
scaleCoefficients = list()
waveletCoefficients = list()
reconstruction = list()
switch = False
def upsample1(lst, index):
if (index % 2 == 0):
return lst[index/2]
else:
return 0.0
def upsample2(lst, index):
if (index % 2 == 0):
return 0.0
else:
return lst[index/2]
## Generate a random list of floating point numbers
if (not switch):
length = 128
for i in range(length):
array.append(random.random())
else:
length = 32
for i in range(32):
array.append(5.0+i+.4*i*i-.02*i*i*i)
## First Part Just Calculates the Filters
## CDF 9/7 Wavelet
DWTAnalysisLowpass = [.026749, -.016864, -.078223, .266864, .602949, .266864, -.078223, -.016864, .026749]
for i in range(len(DWTAnalysisLowpass)):
DWTAnalysisLowpass[i] = math.sqrt(2.0) * DWTAnalysisLowpass[i]
DWTAnalysisHighpass = [.091272, -.057544, -0.591272, 1.115087, -.591272, -.057544, .091272]
for i in range(len(DWTAnalysisHighpass)):
DWTAnalysisHighpass[i] = DWTAnalysisHighpass[i]/math.sqrt(2.0)
DWTSynthesisLowpass = [-.091272, -.057544, 0.591272, 1.115087, .591272, -.057544, -.091272]
for i in range(len(DWTSynthesisLowpass)):
DWTSynthesisLowpass[i] = DWTSynthesisLowpass[i]/math.sqrt(2.0)
DWTSynthesisHighpass = [.026749, .016864, -.078223, -.266864, .602949, -.266864, -.078223, .016864, .026749]
for i in range(len(DWTSynthesisHighpass)):
DWTSynthesisHighpass[i] = math.sqrt(2.0) * DWTSynthesisHighpass[i]
## Haar Wavelet
## c = 1.0/math.sqrt(2)
## DWTAnalysisLowpass = [c,c]
## DWTAnalysisHighpass = [c, -c]
## DWTSynthesisLowpass = [-c, c]
## DWTSynthesisHighpass = [c, c]
# Do the forward transform. We can skip every other sample since they would
# be removed in the downsampling anyway
for i in range(0,length,2):
newVal = 0.0
## Convolve the next j elements by the low-pass analysis filter
for j in range(len(DWTAnalysisLowpass)):
index = i + j - len(DWTAnalysisLowpass)/2
if(index >= length):
index = 2*length - index - 2
elif (index < 0):
index = -index
newVal = newVal + array[index]*DWTAnalysisLowpass[j]
# append the new value to the list of scale coefficients
scaleCoefficients.append(newVal)
newVal = 0.0
# Convolve the next j elements by the high-pass analysis filter
for j in range(len(DWTAnalysisHighpass)):
index = i + j - len(DWTAnalysisHighpass)/2 + 1
if(index >= length):
index = 2*length - index - 2
elif (index < 0):
index = -index
newVal = newVal + array[index]*DWTAnalysisHighpass[j]
# append the new value to the list of wavelet coefficients
waveletCoefficients.append(newVal)
# Do the inverse transform
for i in range(length):
newVal = 0.0
# convolve the upsampled wavelet coefficients with the high-pass synthesis filter
for j in range(len(DWTSynthesisHighpass)):
index = i + j - len(DWTSynthesisHighpass)/2
if(index >= length):
index = 2*length - index - 2
elif (index < 0):
index = -index
newVal = newVal + upsample2(waveletCoefficients, index)*DWTSynthesisHighpass[j]
# convolve the upsampled scale coefficients with the low-pass synthesis filter, and
# add it to the previous convolution
for j in range(len(DWTSynthesisLowpass)):
index = i + j - len(DWTSynthesisLowpass)/2
if(index >= length):
index = 2*length - index - 2
elif (index < 0):
index = -index
newVal = newVal + upsample1(scaleCoefficients, index)*DWTSynthesisLowpass[j]
reconstruction.append(newVal)
print ("Sums: ")
print sum(reconstruction)
print sum(array)
print ("Original Signal: ")
print array
if (not switch):
print ("Wavelet Coefficients: ")
for i in range(len(scaleCoefficients)):
print ("sc[" + str(i) + "]: " + str(scaleCoefficients[i]))
for i in range(len(waveletCoefficients)):
print ("wc[" + str(i) + "]: " + str(waveletCoefficients[i]))
print ("Reconstruction: ")
print reconstruction
关于python - CDF 9/7 离散小波变换(卷积),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5049984/
如何在 Flutter 中使 slider 离散看起来像上图? slider discrete 最佳答案 使用 divisions Slider 的属性(property)小部件将其分成相等的部分,然
我正在创建一个带有颜色条的散点图 plt.scatter(X, Y, c=Z) plt.colorbar() plt.show() plt.close() 其中 X 和 Y 是 float 组,Z 是
我刚刚在 android studio 中发现了 seekbar 离散小部件,我发现它非常有用,但我不知道如何删除步骤指示器,或者用更合适的可绘制对象更改它们。 有人设法做到了吗? 这是我当前搜索栏的
问题 请注意以下问题:巫师可以创建和销毁 rune 。创建一个新的 rune 需要消耗与先前创建的 rune 数量成比例的法力。摧毁 rune 会恢复创建 rune 所用的法力。下面,我提出一个可能的
我正在尝试使用 ggplot2 中的 sf 和 geom_sf 制作 map ,其中一组点数据使用连续颜色比例(-1 到 1),一组线数据使用离散比例(a、b、c、d)着色。但是,当我在同一张 map
我正在尝试在具有连续状态(dim.= 20)和离散操作(3 个可能的操作)的环境中找到最佳策略。并且有一个特定的时刻:对于最佳策略,一个操作(称为“操作 0”)的选择频率应比其他两个操作高得多(频率约
仅使用 x-y 位置移动绘制圆弧的最佳方法是什么?例如,假设我想在点 (4,4) 处绘制一个半径为 4 的圆。让我们看看我的“抽屉”从 (4,0) 开始,每个方向的分辨率为 0.1 步。我将如何创建一
我正在使用一个使用广义加法模型的随机站点级效应来拟合一个模型,该模型在 mgcv 中实现。 R 包。我一直在使用函数 gam() 执行此操作但是,为了加快速度,我需要转到 bam()框架,与gam()
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
这个问题在这里已经有了答案: Make a line separated by group in bar chart (3 个答案) 关闭上个月。 我正在尝试使用 ggplot2 在条形图的每个条上
是否可以同时使用 Intel HD 4000 集成显卡和独立 GPU,OpenCL(或 CUDA)作为设备,CPU 作为主机?我想要一些代码在集成显卡上运行,而其他代码同时在我的 GPU 上运行。 最
我是一名优秀的程序员,十分优秀!