小波压缩Python

问题描述 投票:0回答:1

我试图用小波变换压缩时间序列,我看到它可以平滑信号,但我只想得到最重要的点及其位置并删除其余的,但我不知道一旦我有了小波系数我该如何压缩信号,点数更少

import matplotlib.pyplot as plt
plt.plot(noisy_signal)
plt.title("Noisy Signal")
coeffs = pywt.wavedec(noisy_signal, 'db2', level=2)
threshold = 0.5
coeffs_thresholded = [pywt.threshold(c, threshold, mode='soft') for c in coeffs]

# Reconstruct the signal from the thresholded coefficients
denoised_signal = pywt.waverec(coeffs_thresholded, 'db2')
plt.plot(denoised_signal) 

我得到这个结果,即使第二个信号被平滑,两个信号也具有相同的长度

python wavelet pywavelets
1个回答
0
投票

“coeffs_thresholded”列表的长度将与“coeffs”列表的长度相同,因为您正在对“coeffs”中的每个系数应用阈值。该代码不是删除高于阈值的系数,而是用默认值 0 的替代值替换它们。(检查文档

首先,验证 coeffs 列表中是否有低于阈值的值。然后你就可以做

coeffs_thresholded = [pywt.threshold(c, threshold, mode='soft') if pywt.threshold(c, threshold, mode='soft') > 0 for c in coeffs] 

© www.soinside.com 2019 - 2024. All rights reserved.