Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use denoising with Python Wavelet transform

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use Python wavelet transform denoising". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

one。 The principle of Wavelet denoising

The wavelet coefficient generated by the signal contains the important information of the signal. After the signal is decomposed by wavelet, the wavelet coefficient of the noise is smaller, and the wavelet coefficient of the noise is smaller than the wavelet coefficient of the signal. By selecting a suitable threshold, the wavelet coefficient larger than the threshold is considered to be generated by the signal and should be retained, while those less than the threshold are considered to be caused by noise and set to zero to achieve the purpose of denoising.

The basic problems of wavelet threshold denoising include three aspects: the selection of wavelet basis, the selection of threshold and the selection of threshold function.

(1) the selection of wavelet bases: usually we want the selected wavelets to satisfy the following conditions: orthogonality, high vanishing moment, compactness, symmetry or antisymmetry. But in fact, it is impossible for wavelets with the above properties to exist, because only Haar wavelets are symmetrical or antisymmetrical, and there is a contradiction between high vanishing moment and compact support, so the wavelets with compact support are generally selected and the more appropriate wavelets are selected according to the characteristics of the signal.

(2) the selection of threshold: an important factor that directly affects the denoising effect is the selection of threshold. Different threshold selection will have different denoising effect. At present, there are mainly general threshold (VisuShrink), SureShrink threshold, Minimax threshold, BayesShrink threshold and so on.

(3) the choice of threshold function: threshold function is the rule of modifying wavelet coefficients, and different inverse functions reflect different strategies to deal with wavelet coefficients. There are two most commonly used threshold functions: one is hard threshold function, the other is soft threshold function. There is also a Garrote function between soft and hard threshold functions.

In addition, the evaluation of the denoising effect is often judged by the signal-to-noise ratio (SNR) of the signal and the root mean square error (RMSE) of the estimated signal from the original signal.

Second, wavelet analysis is used for threshold denoising in python, pywt.threshold function # coding=gbk# is used for threshold denoising using wavelet analysis, and pywt.threshold import pywtimport numpy as npimport pandas as pd import matplotlib.pyplot as plt import math data = np.linspace (1, 10, 10) print (data) # [1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] # pywt.threshold (data, value, mode, substitute) mode modes Soft, hard, greater, less Substitute is a replacement value. You can click into the function, data/np.abs (data) * np.maximum (np.abs (data)-value, 0) data_soft = pywt.threshold (data=data, value=6, mode='soft', substitute=12) print (data_soft) # [12. 12. 12. 12. 0. 1. 2. 3. 4.] Set the value less than 6 to 12, and subtract all values greater than or equal to 6 from 6 data_hard = pywt.threshold (data=data, value=6, mode='hard', substitute=12) print (data_hard) # [12. 12. 12. 12. 12. 12. 12. 12. 12. 6. 7. 9. 10.] Set the value less than 6 to 12, and the rest remain the same data_greater = pywt.threshold (data, 6, 'greater', 12) print (data_greater) # [12. 12. 12. 12. 12. 6. 7. 9. 10.] Set the value less than 6 to 12, and the value greater than or equal to the threshold does not change data_less = pywt.threshold (data, 6, 'less', 12) print (data_less) # [1. 2. 3. 4. 5. 6. 12. 12. 12.] Set the value greater than 6 to 12, and the value less than or equal to the threshold remains the same.

three, Wavelet denoising experiment using ecg ECG signal in python #-- coding:utf-8-*-import matplotlib.pyplot as pltimport pywtimport mathimport numpy as np#get Dataecg=pywt.data.ecg () # generates ECG signal index= [] data= [] coffs= [] for i in range (len (ecg)-1): X=float (I) Y=float (ECG [I]) index.append (X) data.append (Y) # create wavelet object and define parametersw=pywt.Wavelet ('db8') # choose Daubechies8 wavelet maxlev = pywt.dwt_max_level (len (data)) W.dec_len) print ("maximum level is" + str (maxlev)) threshold=0 # Threshold for filtering#Decompose into wavelet components,to the level selected:coffs=pywt.wavedec (data,'db8',level=maxlev) # decompose the signal by wavelet transform for i in range (1 coffs): coffs [I] = pywt.threshold (pywt.threshold [I], threshold*max (coeffs [I]) datarec=pywt.waverec (coffs,'db8') # Wavelet reconstruction mintime=0maxtime=mintime+len (data) print (mintime) Maxtime) plt.figure () plt.subplot (3mintime 1) plt.plot (index [mintime:maxtime], data [time: maxtime]) plt.xlabel ('time (s)') plt.ylabel ('microvolts (uV)') plt.title ("Raw signal") plt.subplot (3) plt.plot (index [mintime: maxtime] Datarect [mintime: maxtime]) plt.xlabel ('time (s)') plt.ylabel ('microvolts (uV)') plt.title ("De-noised signal using wavelet techniques") plt.subplot (3,1,3) plt.plot (index [mintime:maxtime], data [mintime: maxtime]-datarecc [mintime: maxtime]) plt.xlabel ('time (s)') plt.ylabel ('error (uV)') plt.tight_layout () plt.show ()

If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report