Python环境下基于小波分析的Linear电磁谱降噪

小波变换以其良好的时频局部化特性,成功地解决了保护信号局部性和抑制噪声之间的矛盾,因此小波技术在信号降噪中得到了广泛的研究,并获得了非常好的应用效果。小波降噪中最常用的方法是小波阈值降噪。基于小波变换的阈值降噪关键是要解决两个问题:阈值的选取和阈值函数的确定,目前常用的阈值选取原则有以下四种:通用阈值(sqtwolog原则)、Stein无偏似然估计阈值(rigrsure原则)、启发式阈值(heursure原则)、极大极小阈值(minimaxi原则)。

鉴于此,采用小波分析对电磁谱信号进行降噪,完整代码如下:

import numpy as npimport matplotlib.pyplot as pltimport pywtfrom scipy import constants as consdata = open('Data.txt', 'r')
wl = []intensity = []
for line in data:    rows = [i for i in line.split()]    wl.append(float(rows[0]))    intensity.append(float(rows[1]))
h = 6.626e-34  # Planck's constant (J·s)c = 3e8       # Speed of light (m/s)k = 1.381e-23  # Boltzmann constant (J/K)temperature = 5800  # Temperature (K)wien_constant = 2.897e-3  # Wien's displacement constant (m/K)
desired_peak = 2
# Wavelength range (in meters)wavelengths = np.linspace(280, 1100, 941) * 1e-9
# Planck's law for spectral radiancedef planck_law(wavelength, temperature):    return (8 * np.pi * h * c) / (wavelength**5) / (np.exp((h * c) / (wavelength * k * temperature)) - 1)
# Calculate spectral radiance for the Sunspectral_irradiance = planck_law(wavelengths, temperature)
# Normalize to have the peak value equal to the desired valuescaling_factor = desired_peak / np.max(spectral_irradiance)spectral_irradiance *= scaling_factor
peak_wavelength = 1e9*wien_constant / temperaturepeak_wavelength
DWTcoeffs = pywt.wavedec(intensity, 'db4')DWTcoeffs[-1] = np.zeros_like(DWTcoeffs[-1])DWTcoeffs[-2] = np.zeros_like(DWTcoeffs[-2])DWTcoeffs[-3] = np.zeros_like(DWTcoeffs[-3])DWTcoeffs[-4] = np.zeros_like(DWTcoeffs[-4])#DWTcoeffs[-5] = np.zeros_like(DWTcoeffs[-5])#DWTcoeffs[-6] = np.zeros_like(DWTcoeffs[-6])#DWTcoeffs[-7] = np.zeros_like(DWTcoeffs[-7])#DWTcoeffs[-8] = np.zeros_like(DWTcoeffs[-8])#DWTcoeffs[-9] = np.zeros_like(DWTcoeffs[-9])
filtered_data=pywt.waverec(DWTcoeffs,'db4')filtered_data = filtered_data[:len(wl)]
plt.figure(figsize=(10, 6))plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.plot(wl, filtered_data,  markerfacecolor='none',color='black', label='Denoised Signal')
plt.annotate(    str(temperature)+' K BlackBody Spectrum',    ha = 'center', va = 'bottom',    xytext = (900,1.75),    xy = (700,1.60),    arrowprops = { 'facecolor' : 'black', 'shrink' : 0.05 })
plt.legend()plt.title('Wavelet Denoising of Solar Linear Spectra (280nm - 1100nm)')plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([280, 1100, 0, 2.5])plt.show()
plt.figure(figsize=(10, 12))  # Set the figure size for both subplots
# Subplot 1plt.subplot(3, 1, 1)  # Three rows, one column, index 1plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.legend()plt.title('Wavelet Denoising of Solar Linear UVB and UVA Spectra (280nm - 400nm)')plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([280, 400, 0, 2])
# Subplot 2plt.subplot(3, 1, 2)  # Three rows, one column, index 2plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([280, 400, 0, 2])
# Subplot 2plt.subplot(3, 1, 3)  # Three rows, one column, index 3plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Real Data')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([280, 400, 0, 2])
plt.tight_layout()  # Adjust layout to prevent overlappingplt.show()
plt.figure(figsize=(10, 12))  # Set the figure size for both subplots
# Subplot 1plt.subplot(3, 1, 1)  # Three rows, one column, index 1plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.legend()plt.title('Wavelet Denoising of Solar Linear Visible Spectra (400nm - 700nm)')plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([400, 700, 1, 2.5])
# Subplot 2plt.subplot(3, 1, 2)  # Three rows, one column, index 2plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([400, 700, 1, 2.5])
# Subplot 2plt.subplot(3, 1, 3)  # Three rows, one column, index 3plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Intensity $(\frac{W}{m^2nm})$')plt.axis([400, 700, 1, 2.5])
plt.tight_layout()  # Adjust layout to prevent overlappingplt.show()
plt.figure(figsize=(10, 12))  # Set the figure size for both subplots
# Subplot 1plt.subplot(3, 1, 1)  # Three rows, one column, index 1plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.legend()plt.title('Wavelet Denoising of Solar Linear Visible Spectra (400nm - 700nm)')plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([700, 1100, 0, 2.5])
# Subplot 2plt.subplot(3, 1, 2)  # Three rows, one column, index 2plt.plot(wl, intensity, color='red', label='Noisy Signal')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([700, 1100, 0, 2.5])
# Subplot 2plt.subplot(3, 1, 3)  # Three rows, one column, index 3plt.plot(wavelengths * 1e9, spectral_irradiance, color='green', label='Theoretical Irradiance')plt.plot(wl, filtered_data, markerfacecolor='none', color='black', label='Denoised Signal')plt.legend()plt.xlabel(r'Wavelength (nm)')plt.ylabel(r'Spectral Irradiance $(\frac{W}{m^2nm})$')plt.axis([700, 1100, 0, 2.5])
plt.tight_layout()  # Adjust layout to prevent overlappingplt.show()
def calculate_mse(original, denoised):    mse = np.mean(np.square(np.subtract(original, denoised)))    return mse
def calculate_rmse(original, denoised):    mse = calculate_mse(original, denoised)    rmse = np.sqrt(mse)    return rmse
def calculate_psnr(original, denoised):    max_pixel_value = 255.0  # Assuming pixel values are in the range [0, 255]    mse_value = calculate_mse(original, denoised)    psnr = 10 * np.log10((max_pixel_value ** 2) / mse_value)    return psnr
# Assuming 'original_signal' and 'denoised_signal' are your original and denoised signals as lists or arraysmse_value = calculate_mse(spectral_irradiance, filtered_data)rmse_value = calculate_rmse(spectral_irradiance, filtered_data)psnr_value = calculate_psnr(spectral_irradiance, filtered_data)
print(f"MSE: {mse_value}")print(f"RMSE: {rmse_value}")print(f"PSNR: {psnr_value} dB")

工学博士,担任《Mechanical System and Signal Processing》审稿专家,担任《中国电机工程学报》优秀审稿专家,《控制与决策》,《系统工程与电子技术》,《电力系统保护与控制》,《宇航学报》等EI期刊审稿专家。

擅长领域:现代信号处理,机器学习,深度学习,数字孪生,时间序列分析,设备缺陷检测、设备异常检测、设备智能故障诊断与健康管理PHM等。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/589947.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自定义树形筛选选择组件

先上效果图 思路:刚开始最上面我用了el-input,选择框里面内容用了el-inputel-tree使用,但后面发现最上面那个可以输入,那岂不是可以不需要下拉就可以使用,岂不是违背了写这个组件的初衷,所以后面改成div自定…

CVE-2021-30517:Type confusion bug in LoadSuperIC

前言 这个漏洞是一个比较老的洞,之所以分析这个漏洞,只要是想再学习一下 ICs 相关的知识。并该漏洞的利用是利用与 String/Function 之间的混淆,比较有意思。 环境搭建 sudo apt install python git checkout 7d5e5f6c62c3f38acee12dc4114…

网站如何运用百度文心一言API进行AI内容创作?

网站如何运用百度文心一言API进行AI内容创作? 当我们做好一个网站的时候会因为创作内容而发愁,随着chatgpt的出现,内容创作已经不再是什么困难的事情,但是由于gpt是国外的,在国内使用有诸多不便,因此我们今…

ES9学习 -- 对象的剩余参数与扩展运算符 / 正则扩展 / Promise.finally / 异步迭代

文章目录 1. 对象的剩余参数与扩展运算符1.1 对象的剩余参数1.2 扩展运算符 2. 正则扩展3. Promise.finally4. 异步迭代4.1 同步遍历器的问题4.2 异步遍历器使用 1. 对象的剩余参数与扩展运算符 1.1 对象的剩余参数 let obj { name:"kerwin", age:100, location:&…

Python疑难杂症(16)---Numpy知识集合(四)列出Numpy模块的常用函数,供查询参考。

列出Numpy模块的常用函数,供查询参考。 numpy.array:创建新的NumPy数组 numpy.zeros:创建一个以零填充的数组。 numpy.random:生成随机数组的函数。 numpy.linspace:在指定范围内生成均匀间隔的数字。 numpy.range:用间隔的值创建数组。 numpy.shape:返回一个…

【动态】江西省小型水库安全监测能力提升试点项目通过验收

近日,由北京国信华源科技有限公司和长江勘测规划设计研究有限责任公司联合承建的江西省小型水库安全监测能力提升试点项目圆满通过验收。 在项目业主单位的组织下,省项目部、特邀专家、县水利局二级项目部以及项目设计、监理、承建等单位的代表组成验收工…

质量管理工作中常用的七种方法——SunFMEA软件

质量管理工作中常用的七种方法,它们包括:流程图、检查表、因果图、排列图、直方图、散布图和统计控制图。下面SunFMEA软件将详细介绍这七大工具及其在质量管理中的应用。 一、流程图 流程图是一种用来表示一系列操作或事件的顺序的图形化工具。在质量管理…

SpringBoot(48)-使用 SkyWalking 进行分布式链路追踪

Spring Boot(48)- 使用 SkyWalking 进行分布式链路追踪 介绍 在分布式系统中,了解各个服务之间的调用关系和性能表现是非常重要的。SkyWalking 是一款开源的分布式系统监控与分析平台,能够帮助我们实现分布式系统的链路追踪、性…

51单片机入门_江协科技_20.1_Proteus串口仿真

1.为了解决51单片机学习过程中在Proteus中的串口仿真的问题,需要在Proteus中建立串口仿真的环境(目前Proteus安装在Win7x64虚拟机环境中; 2. 在CSDN中找到VSPD下载地址,在虚拟机中进行VSPD的安装,具体链接地址如下&am…

触想四代ARM架构工业一体机助力手功能康复机器人应用

一、行业发展背景 手功能康复机器人是医疗机器人的一个分支,设计用于帮助肢体障碍患者进行手部运动和力量训练,在医疗健康领域有着巨大的成长空间。 手功能康复机器人融合了传感、控制、计算、AI视觉等智能科技与医学技术,能够帮助患者改善康…

第六期丨酷雷曼无人机技能培训

第6期无人机技能提升培训 盼望着盼望着,第六期无人机技能提升培训会终于如期和大家见面了。 2024年1月1日,国务院、中央军事委员会颁布《无人驾驶航空器飞行管理暂行条例》,对民用无人机飞行活动实施更为严格的规范约束,越来越多…

实时计算平台设计方案:911-基于6U VPX的光纤图像DSP实时计算平台

基于6U VPX的光纤图像DSP实时计算平台 一、系统组成 该平台基于风冷式的 6U 6槽VPX图像处理平台,包括:计算机主板、计算机主板后板、存储板、图像信号处理板、图像信号处理板后板、图像光纤转接板、机箱背板及机箱组成。图1为系统背板结构示意图&…