基于卷积神经网络的一维信号降噪(简单版,MATLAB)

简单演示一下基于卷积神经网络的一维信号降噪,有个大致印象即可。

%% Plot the previous training CNN.
set_plot_defaults('on')
load('denoiser_sparse.mat');
h1{1} = double(conv1);
h1{2} = double(conv2);
h1{3} = reshape(double(conv3),[8,1,17]);
figure(1)
[r,c,~] = size(h1{1});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{1}(i,j,:))))
hold on
plot(flip(squeeze(h1{1}(i,j,:))))
hold off
box off
end
end
sgtitle('layer1 (8x1)', 'FontSize', 10);

figure(2)
[r,c,~] = size(h1{3});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{3}(i,j,:))))
hold on
plot(flip(squeeze(h1{3}(i,j,:))))
hold off
box off
end
end
sgtitle('layer3 (1x8)', 'FontSize', 10);

%% Plot the previous training CNN.
load('remove_13_retrained.mat');
h1{1} = double(conv1);
h1{2} = double(conv2);
h1{3} = double(conv3);
set_plot_defaults('on')
figure(3)
[r,c,~] = size(h1{1});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{1}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{1}(i,j,:))))
hold off
xlim([0,10])
ylim([-1.2,1.2])
box off
end
end
sgtitle('layer1 (2x1)', 'FontSize', 10);
%

figure(4)
[r,c,~] = size(h1{2});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{2}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{2}(i,j,:))))
hold off
xlim([0,38])
ylim([-0.25,inf])
box off
end
end
sgtitle('layer2 (2x2)', 'FontSize', 10);

figure(5)
[r,c,~] = size(h1{3});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{3}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{3}(i,j,:))))
hold off
box off
end
end
sgtitle('layer3 (1x2)', 'FontSize', 10);

clear
% close all
N = 500;
K = 50;
sigma = 1;
groundtruth = zeros(1, N);
index_random = randperm(N);
index = index_random(1:K);
groundtruth(index) = 10*2*(rand(1,K) - 0.5);
noise = sigma * randn(1,N);
input = groundtruth + noise;

%% Plot the components of the input signal.
set_plot_defaults('on')
figure(6)
subplot(3,1,1)
plot(1:N, groundtruth)
title('S[n]')
ylim([-10 10])
box off
subplot(3,1,2)
plot(1:N, noise)
title('N[n]')
ylim([-10 10])box off
subplot(3,1,3)
plot(1:N, input)
title('x[n]')
ylim([-10 10])
box off

%% Create the proposed CNN
threshold1 = 2.4;
threshold2 = 4.8;
rho = 1; % rho is the ratio between output and input signal.
l = 37; % l is the length of the filters in the second layer.
training_sigma = 2; % The standard deviation of the Gaussian noise in the training data is between 0 and training_sigm
training_num = 60000; % training_num is the number of the training signals.
training_type = 2; % 1 means Uniform and 2 means Gaussian.
istrain_flag = false; % istrain_flag can determine if training a new CNN or directly using the trained parameters.
h1 = create_denoiser(l,rho,threshold1,threshold2,training_type,istrain_flag);
%% Plot the output of each layer
set_plot_defaults('on')
figure(7)
l1 = layer(input, h1{1});
subplot(3,1,1)
plot(1:N,input)
title('x[n]')
ylim([-12,12])
xlim([0,500])
box off
subplot(3,1,2)
plot(1:N,l1(1,:))
title('x_1[n]')
ylim([0,12])
xlim([0,500])
box off
subplot(3,1,3)
plot(1:N,l1(2,:))
title('x_2[n]')
ylim([0,12])
xlim([0,500])
box off
% set(

figure(8)
l2_NR = conv1d(l1,h1{2});
l2 = ReLU(l2_NR);
subplot(2,2,1)
plot(1:N,l2_NR(1,:))
title('c_1[n]')
ylim([-10,20])
xlim([0,500])
box off
subplot(2,2,3)
plot(1:N,l2_NR(2,:))
title('c_2[n]')
ylim([-10,20])
xlim([0,500])
box off
subplot(2,2,2)
plot(1:N,l2(1,:))
title('c_1[n] after ReLU')
ylim([0,12])
xlim([0,500])
box off
subplot(2,2,4)
plot(1:N,l2(1,:))
title('c_1[n] after ReLU')
ylim([0,12])
xlim([0,500])
box off

figure(9)
l3 = conv1d(l2,h1{3});
plot(1:N,l3)
title('y[n]')
ylim([-12,12])
xlim([0,500])
box off
title('y[n]')

%% Plot the structure of the proposed CNN
set_plot_defaults('on')
figure(10)
[r,c,~] = size(h1{1});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{1}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{1}(i,j,:))))
hold off
xlim([0,10])
ylim([-1.2,1.2])
box off
end
end
sgtitle('layer1 (2x1)', 'FontSize', 10);

figure(11)
title('Layer 2')
[r,c,~] = size(h1{2});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{2}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{2}(i,j,:))))
hold on
plot(19,h1{2}(i,j,19), 'MarkerSize', 10)
hold on
if i == j
text(20,h1{2}(i,j,19)-0.05, '\alpha_1')
text(30,h1{2}(i,j,8)+0.4, '\beta_1')
else
text(20,h1{2}(i,j,19)-0.05, '\alpha_2')
text(30,h1{2}(i,j,8)+0.2, '\beta_2')
end
plot(30,h1{2}(i,j,8), 'MarkerSize', 10)
hold off
xlim([0,38])
ylim([-0.25,inf])
box off
end
end
sgtitle('layer2 (2x2)', 'FontSize', 10);

figure(12)
title('Layer 3')
[r,c,~] = size(h1{3});
for i=1:1:r
for j=1:1:c
subplot(r,c,c*i-(c-j))
stem(flip(squeeze(h1{3}(i,j,:))), 'filled', 'MarkerSize', 2)
hold on
plot(flip(squeeze(h1{3}(i,j,:))))
hold off
box off
end
end
sgtitle('layer3 (1x2)', 'FontSize', 10);

%% Plot the output signal v.s. input signal and display the thresholds.
set_plot_defaults('on')
output = CNN(input,h1);
figure(13)
plot(input, output, 'o', 'MarkerSize', 4)
hold on;
line([threshold1 threshold1], [-10 10],'Color','magenta','LineStyle','--')
line([threshold2 threshold2], [-10 10],'Color','red','LineStyle','--')
line([-threshold1 -threshold1], [-10 10],'Color','magenta','LineStyle','--')
line([-threshold2 -threshold2], [-10 10],'Color','red','LineStyle','--')
xlabel('Input')
ylabel('Output')
grid
axis equal square
line([-10 10], [-10 10])
axis([-10,10,-10,10])
box off

%% Create the proposed CNN
threshold1 = 2.61;
threshold2 = 5.26;
rho = 1; % rho is the ratio between output and input signal.
l = 37; % l is the length of the filters in the second layer.
training_sigma = 2; % The standard deviation of the Gaussian noise in the training data is between 0 and training_sigm
training_num = 60000; % training_num is the number of the training signals.
training_type = 1; % 1 means Uniform and 2 means Gaussian.
istrain_flag = false; % istrain_flag can determine if training a new CNN or directly using the trained parameters.
h1 = create_denoiser(l,rho,threshold1,threshold2,training_type,istrain_flag);
N = 500;
K = 25;
sigma = 0.5;
groundtruth = zeros(1, N);
index_random = randperm(N);
index = index_random(1:K);
groundtruth(index) = 10*2*(rand(1,K) - 0.5);
noise = sigma * randn(1,N);
input = groundtruth + noise;
%% Display groundtruth, input signal and output signal. Plot input signal v.s. output signal in two forms. Pure signal cas
set_plot_defaults('on')
figure(14)
output = CNN(groundtruth, h1);
subplot(3,1,1)
plot(groundtruth)
title('pure signal (S[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,2)
plot(groundtruth)
title('noisy signal (x[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,3)
plot(output)
title('output signal (y[n])');
xlim([1,500])
ylim([-10,10])
box off

n = 1:N;
figure(15)
stem(n, groundtruth, 'MarkerSize', 4)
hold on
plot(n, output, 'ro', 'MarkerSize', 4)
hold off
legend('Input (x[n])', 'Output (y[n])', 'Location', 'SouthEast', 'FontSize', 10)
xlim([1,500])
ylim([-10,10])
% title('Input v.s. output')
box off

figure(16)
plot(groundtruth, output, 'ro')
hold on
xlabel('Input')
ylabel('Output')
grid
axis equal square
line([-10 10], [-10 10])
hold off
% title('Input v.s. output')
box off

%% Display groundtruth, input signal and output signal. Plot input signal v.s. output signal in two forms. Pure noise case
set_plot_defaults('on')
figure(17)
output = CNN(noise, h1);
subplot(3,1,1)
plot(zeros(1,N))
title('pure signal (S[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,2)
plot(noise)
title('noisy signal (x[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,3)
plot(output)
title('output signal (y[n])');
xlim([1,500])
ylim([-10,10])
box off

n = 1:N;
figure(18)
stem(n, noise, 'MarkerSize', 4)
hold on
plot(n, output, 'ro', 'MarkerSize', 4)
hold off
legend('Input (x[n])', 'Output (y[n])')
xlim([1,500])
ylim([-4,4])
% title('Input v.s. output')
box off

figure(20)
output = CNN(input, h1);
subplot(3,1,1)
plot(groundtruth)
title('pure signal (S[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,2)
plot(input)
title('noisy signal (x[n])');
xlim([1,500])
ylim([-10,10])
box off
subplot(3,1,3)
plot(output)
title('output signal (y[n])');
xlim([1,500])
ylim([-10,10])
box off

%% Create input signal (noisy signal) and ground truth (pure signal) for the performance part.
% N is the total length of the pure sparse signal.
% K is the number of non-zeros in the pure sparse signal.
% As a result, 1-K/N determines the sparsity of the pure signal.
N = 500;
num = 1000;
sigma_set = logspace(log10(0.1), log10(2), 20);
% sigma_set = 0.1:0.1:2;
MSE_output_ave = zeros(3,length(sigma_set));
MSE_input_ave = zeros(3,length(sigma_set));
SNR_output_ave = zeros(3,length(sigma_set));
SNR_input_ave = zeros(3,length(sigma_set));
for m = 1:1:3
K = 25 * m;
for i = 1:1:length(sigma_set)
sigma = sigma_set(i);
SNR_output = zeros(1,num);
SNR_input = zeros(1,num);
MSE_output = zeros(1,num);
MSE_input = zeros(1,num);
for j = 1:1:num
groundtruth = zeros(1, N);
index_random = randperm(N);
index = index_random(1:K);
groundtruth(index) = 10*2*(rand(1,K) - 0.5);
% groundtruth(index) = 10*randn(1,K);
input_noise = sigma*randn(1,N);
input = groundtruth + input_noise;
output = CNN(input, h1);
noise = output - groundtruth;
MSE_output(j) = mean(noise.^2);
MSE_input(j) = mean(input_noise.^2);
SNR_output(j) = 10*log10(mean(groundtruth.^2)/MSE_output(j));
SNR_input(j) = 10*log10(mean(groundtruth.^2)/MSE_input(j));
end
SNR_output_ave(m,i) = mean(SNR_output);
SNR_input_ave(m,i) = mean(SNR_input);
% MSE_output_ave(m,i) = mean(MSE_output);
% MSE_input_ave(m,i) = mean(MSE_input);
MSE_output_ave(m,i) = sqrt(mean(MSE_output));
MSE_input_ave(m,i) = sqrt(mean(MSE_input));
end
end
%% Plot the performance v.s. sparsity and noise level.
set_plot_defaults('on')
figure(23)
semilogx(sigma_set,SNR_output_ave(1,:),'r.-',sigma_set,SNR_output_ave(2,:),'k.-',sigma_set,SNR_output_ave(3,:),'g.-')
hold on
semilogx(sigma_set,SNR_input_ave(1,:),'rx-',sigma_set,SNR_input_ave(2,:),'kx-',sigma_set,SNR_input_ave(3,:),'gx-')
hold off
legend('Output SNR, sparsity = 95%','Output SNR, sparsity = 90%','Output SNR, sparsity = 85%', ...
'Input SNR, sparsity = 95%', 'Input SNR, sparsity = 90%', 'Input SNR, sparsity = 85%')
xlabel('σ')
ylabel('SNR in dB')
set(gca, 'xtick', [0.1 0.2 0.5 1 2.0])
xlim([min(sigma_set) max(sigma_set)])
box off
%

工学博士,担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:现代信号处理,机器学习/深度学习,时间序列分析/预测,设备智能故障诊断与健康管理PHM等。

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

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

相关文章

Java_异常

介绍 编译时异常: 除RuntimeException和他的子类,其他都是编译时异常。编译阶段需要进行处理,作用在于提醒程序眼 运行时异常: RuntimeException本身和其所有子类,都是运行时异常。编译阶段不报错,是程序…

Java17 --- SpringCloud之Nacos

目录 一、下载nacos并运行 1.1、创建9001微服务作为提供者 1.2、创建80微服务作为消费者 二、naocs配置中心规则与动态刷新 2.1、创建3377微服务 2.2、在nacos中创建配置文件 三、nacos数据模型之Namespace-Group-Datald 3.1、DatalD方案 3.2、Group方案 3.3、Name…

python软件开发遇到的坑-相对路径文件读写异常,不稳定

1. os.chdir()会影响那些使用相对路径读写文件的程序,使其变得不稳定,默认情况下,当前工作目录是主程序所在目录,使用os.chdir会将当前工作目录修改到其他路径。 资料: python相对路径写对了却报错是什么原因呢&#…

蜜蜂收卡系统 加油卡充值卡礼品卡自定义回收系统源码 前后端开源uniapp可打包app

本文来自:蜜蜂收卡系统 加油卡充值卡礼品卡自定义回收系统源码 前后端开源uniapp可打包app - 源码1688 卡券绿色循环计划—— 一项旨在构建卡券价值再利用生态的社会责任感项目。在当前数字化消费日益普及的背景下,大量礼品卡、优惠券因各种原因未能有效…

mib browser读取mib文件的oid(飞塔防火墙为例)

在配置zabbix监控的时候,配置监控项最为麻烦,一般我们都会套用模板,这种方式比较简单,但是有些设备就是没有现成的zabbix模板,怎么办? 今天我们使用MIB Browser来获取设备SNMP的OID,然后加入zabbix 。 1.什么是MIB Browser SNMP客户端工具MIB Browser, 全名iReasonin…

ARP详解

2.4 ARP 如图2-10所示,当网络设备有数据要发送给另一台网络设备时,必须要知道对方的网络层地址(即IP地址)。IP地址由网络层来提供,但是仅有IP地址是不够的,IP数据报文必须封装成帧才能通过数据链路进行发送…

RuntimeError: Tensor must have a last dimension with stride 1

我在使用torch.view_as_complex将weight转化为复数时,遇到了这样一个错误:由于我在对weight使用view_as_complex之前使用了F.interpolate函数进行了分辨率调整,因此只需对张量weight添加.contiguous()即可。

拿到B端系统设计需求该如何入手,这样做准没错!

在拿到B端系统设计需求后,以下是一些入手的步骤和方法: 理解需求 首先,仔细阅读和理解所提供的需求文档。了解系统的目标、功能需求、用户需求、非功能需求等方面的要求。如果有任何不清楚或模糊的地方,及时与需求提出方进行沟通…

vue+sortablejs来实现列表拖拽——sortablejs的使用

sortablejs官网:https://sortablejs.com/ 最近在看form-builder组件,发现里面有用到sortablejs插件,用于实现拖拽效果。 但是这个官网中的配置,实在是看不懂,太简单又太复杂,不实用。 下面记录一下我的使用&#xff…

Redis 实战之RDB文件结构

RDB文件结构 databases 部分key_value_pairs 部分value 的编码字符串对象列表对象集合对象哈希表对象有序集合对象INTSET 编码的集合ZIPLIST 编码的列表、哈希表或者有序集合 总结AOF持久化的实现命令追加 AOF 文件的写入与同步小结 在本章之前的内容中, 我们介绍了…

C++优先级队列priority_queue模拟实现

priority_queue模拟实现 1. priority_queue介绍2. priority_queue使用2.1 priority_queue显示定义2.2priority_queue接口使用 3. 仿函数4. priority_queue模拟实现4.1 向上调整算法4.2 向下调整算法4.3 实现priority_queue的接口4.4 使用[仿函数](https://legacy.cplusplus.com…

Springboot+Vue项目-基于Java+MySQL的流浪动物管理系统(附源码+演示视频+LW)

大家好!我是程序猿老A,感谢您阅读本文,欢迎一键三连哦。 💞当前专栏:Java毕业设计 精彩专栏推荐👇🏻👇🏻👇🏻 🎀 Python毕业设计 &…

MCP3008-I/SL 模数转换器ADC SPI接口 模拟信号采集

MCP3008-I/SL 模数转换器ADC 贴片SOIC16 MCP3008-I/SL 是一款模数转换器(ADC),属于 SAR(逐次逼近寄存器)架构的 ADC。它具有以下特点: 8 通道单 ADC 最大采样率:200ksps(千样点每秒…

为什么byte 的取值范围是 [-128,127]

在计算机中,byte(字节)是存储数据的基本单位,通常用8位二进制数字表示一个字节。在字节中,最高位的最左边一位是符号位,用来表示正负号,值为0表示正数,值为1表示负数。 如果将byte定…

URL过滤

什么是URL过滤? URL过滤是一种针对用户的URL请求进行上网控制的技术,通过允许或禁止用户访问某些网页资源,达到规范上网行为和降低安全风险的目的。 URL过滤可以基于URL分类、特定URL等多种方式限制URL访问。 URL过滤的主要作用如下&#xf…

Python Flask框架(一)初识Flask

Flask是使用Python编写的Web微框架。Web框架可以使我们不用关心底层的请求响应处理,更方便高效的编写Web程序。Flask有两个主要依赖,一个是WSGI(Web Server Gateway Interface,web服务器网关接口)工具集,另…

【文献解析】3D高斯抛雪球是个什么玩意

论文地址:https://arxiv.org/abs/2308.04079 项目:3D Gaussian Splatting for Real-Time Radiance Field Rendering 代码:git clone https://github.com/graphdeco-inria/gaussian-splatting --recursive 一、文章概述 1.1问题导向 辐射…

USB3.0接口——(1)基础知识

1.背景 USB 3.0是一种USB规范,该规范由英特尔等公司发起。 USB协议版本 命名约定 USB-IF组织引入命名约定,将端口列为 USB 5 Gbps、USB 10 Gbps、USB 20 Gbps 、USB 40 Gbps,而不使用版本号。获得 USB-IF 认证的 USB 产品的制造商会获得带…

SAP 长文本语言代码维护

在SAP中,我们发现长文本都是有语言代码的,如果需要新增一个语言代码的话,需要通过程序RSCPCOLA进行维护处理 具体实现步骤如下: 1. 输入事务码SE38,输入程序名RSCPCOLA,然后点击执行按钮 2. 维护信函语言…

sklearn的make_blobs函数

make_blobs是一个用于生成随机数据点的实用函数, from sklearn.datasets import make_blobs X,Y make_blobs(n_samples2000,n_features2,centers12,cluster_std0.05,center_box[-5,5],random_state21)n_samples: 要生成的样本数量。centers: 要生成的簇&#xff0…