信号的平稳小波变换方差计算(Python)

360影视 2025-01-11 12:32 2

摘要:import matplotlib.pyplot as pltimport numpy as npimport pywtimport pywt.dataecg = pywt.data.ecg# set trim_approx to avoid keeping

import matplotlib.pyplot as pltimport numpy as npimport pywtimport pywt.dataecg = pywt.data.ecg# set trim_approx to avoid keeping approximation coefficients for all levels# set norm=True to rescale the wavelets so that the transform partitions the# variance of the input signal among the various coefficient arrays.coeffs = pywt.swt(ecg, wavelet='sym4', trim_approx=True, norm=True)ca = coeffs[0]details = coeffs[1:]print(f"Variance of the ecg signal = {np.var(ecg, ddof=1)}")variances = [np.var(c, ddof=1) for c in coeffs]detail_variances = variances[1:]print(f"Sum of variance across all SWT coefficients = {np.sum(variances)}")# Create a plot using the same y axis limits for all coefficient arrays to# illustrate the preservation of amplitude scale across levels when norm=True.ylim = [ecg.min, ecg.max]fig, axes = plt.subplots(len(coeffs) + 1)axes[0].set_title("normalized SWT decomposition")axes[0].plot(ecg)axes[0].set_ylabel('ECG Signal')axes[0].set_xlim(0, len(ecg) - 1)axes[0].set_ylim(ylim[0], ylim[1])for i, x in enumerate(coeffs):ax = axes[-i - 1]ax.plot(coeffs[i], 'g')if i == 0:ax.set_ylabel("A%d" % (len(coeffs) - 1))else:ax.set_ylabel("D%d" % (len(coeffs) - i))# Scale axesax.set_xlim(0, len(ecg) - 1)ax.set_ylim(ylim[0], ylim[1])# reorder from first to last level of coefficientslevel = np.arange(1, len(detail_variances) + 1)# create a plot of the variance as a function of levelplt.figure(figsize=(8, 6))fontdict = {'fontsize': 16, 'fontweight': 'bold'}plt.plot(level, detail_variances[::-1], 'k.')plt.xlabel("Decomposition level", fontdict=fontdict)plt.ylabel("Variance", fontdict=fontdict)plt.title("Variances of detail coefficients", fontdict=fontdict)plt.show

知乎学术咨询:

https://www.zhihu.com/consult/people/792359672131756032?isMe=1

担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:信号滤波/降噪,机器学习/深度学习,时间序列预分析/预测,设备故障诊断/缺陷检测/异常检测。

采用8种方法对一维信号进行降噪(Python)

NS: noisy signalS: original siGANlmean filter: ws = window sizemedian filter:average filter: ns = number of noisy signal(different)bandpass filter: l = low cut-off frequency, h = high ...threshold filter: r = ratio(max abs(fft) / min ...)wavelet filter: a = thresholdstd filter:NN: neural network

完整代码:

基于STA/LTA的地震事件检测(Python)

完整代码:

基于字典学习的信号与图像降噪方法(Python,ipynb文件)

import numpy as npimport matplotlib.pyplot as pltfrom scipy.io import wavfilefrom sklearn.decomposition import MiniBatchDictionaryLearningfrom sklearn.feature_extraction import image# Load the audio filerate, data = wavfile.read('pop.wav')# Normalize the datadata = data / np.max(np.abs(data))# Function to add noisedef add_noise(signal, noise_level=0.05):noise = np.random.randn(*signal.shape)noisy_signal = signal + noise_level * noisereturn noisy_signal# Add noise to the clean signalnoisy_data = add_noise(data)plt.figure(figsize=(10, 6))plt.subplot(2, 1, 1)plt.title("Original Audio Signal")plt.plot(data)plt.subplot(2, 1, 2)plt.title("Noisy Audio Signal")plt.plot(noisy_data)plt.tight_layoutplt.show

完整代码:

基于GAN的时间序列生成(Python,ipynb文件)

来源:Sug科技聚焦

相关推荐