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

news2024/9/22 15:32:34

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

%% 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.coloradmin.cn/o/1678643.html

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

相关文章

又一款爆火AI游戏诞生!《换你来当爹》做对了什么?| ShowMeAI体验报告

社区里几百人玩一款AI游戏的场面,值得记录一下! 大模型游戏化极度看重〖有趣〗程度。 可有趣的灵魂那么难得,以至于只要一眼,我们就在产品的海洋里发现了 ta 。 1. 有趣的灵魂在发疯疯疯 《换你来当爹》是一款全员发疯的AI游戏&am…

分页查询PageHelper插件分页条件查询(xml映射文件,动态SQL)

黑马程序员JavaWeb开发教程 文章目录 一、分页查询-分析二、分页查询-实现1. 实现思路1.1 controller1.2 service1.3 mapper 1.4 postman测试接口 三、分页查询-PageHelper插件1. 引入pageHelper插件的依赖2. 修改原来的代码2.1 mapper2.2 serviceimpl2.3 postman测试接口 四、…

第83天: 代码审计-PHP 项目RCE 安全调试追踪代码执行命令执行

案例一:CNVD拿1day-RCE命令执行-百家CMS 这里用代码审计系统搜索system,可以利用的是第一种 打开看细节 查找函数引用 查找$_file第一次出现的地方 这个时候就明白了,必须上传文件,然后利用文件名,去执行system命令 …

基于YOLOv5的道路裂缝检测,加入一种基于内容引导注意力(CGA)的混合融合提升2个多点

💡💡💡本文主要内容:详细介绍道路裂缝检测整个过程,从数据集到训练模型到结果可视化分析。 💡💡💡通过加入一种基于内容引导注意力(CGA)的混合融合提升检测性能, 特征融合创新 | 一…

硬盘坏道如何检测和修复?

硬盘是我们储存数据的重要设备,然而在使用过程中,我们可能会遇到一些困扰,比如硬盘出现坏道的问题。那么,什么是坏道呢?硬盘出现坏道会对我们的性能和数据安全产生影响吗?如何去检测和修复这些坏道呢&#…

js积累一(ipv4正则校验+弹窗方式)

1. ipv4地址,点分十进制的校验 var regexIP /^((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))$/; if(strRegex.test(ip)) //true: 通过 2. 三种弹窗方式: alert();confirm(); prompt() 1&a…

微分阻尼作用的理解

先说阻尼的作用,阻尼能够缩短系统整定时间,减小系统响应的振动幅度。 1、CODESYS位置式PID(完整ST源代码) CODESYS位置式PID(完整ST源代码)_codesys pid功能块-CSDN博客文章浏览阅读1.2k次,点赞2次,收藏2次。CODESYS增量式PID完整源代码请参看下面文章链接:CODESYS增量式…

echarts的柱状图使用

1. 柱状图&#xff08;柱体顶部使用外部图片 相关代码 <template><div class"out-bg"><div class"container" ref"warnChartRef"></div></div> </template><script> import * as echarts from echar…

【Linux系统编程】基本指令(二)

目录 1、mv指令 2、cat指令 输出重定向 ​编辑 追加重定向 输入重定向 3、more指令 4、less指令 5、head指令 6、tail指令 与时间相关的指令 7、date指令 8、cal指令 9、find指令 10、grep指令 11、zip/unzip指令 1、mv指令 mv文件是用来对文件或目录进行重命名…

网络爬虫安全:90后小伙,用软件非法搬运他人原创视频被判刑

目录 违法视频搬运软件是网络爬虫 如何发现偷盗视频的爬虫&#xff1f; 拦截违法网络爬虫 央视《今日说法》栏目近日报道了一名程序员开发非法视频搬运软件获利超700多万&#xff0c;最终获刑的案例。 国内某知名短视频平台报警称&#xff0c;有人在网络上售卖一款视频搬运…

玩转Matlab-Simscape(初级)- 07 - 基于Solidworks、Matlab Simulink、COMSOL的协同仿真(理论部分3)

** 玩转Matlab-Simscape&#xff08;初级&#xff09;- 07 - 基于Solidworks、Matlab Simulink、COMSOL的协同仿真&#xff08;理论部分3&#xff09; ** 目录 玩转Matlab-Simscape&#xff08;初级&#xff09;- 07 - 基于Solidworks、Matlab Simulink、COMSOL的协同仿真&am…

探索Dapper与EF Core等ORM框架的神器

Dapper的好处&#xff1a; 轻量级&#xff1a;Dapper是一个非常轻量级的库&#xff0c;对性能的影响非常小。它主要关注于执行SQL查询和映射查询结果到对象&#xff0c;因此它的设计和实现都非常简洁。直接SQL&#xff1a;Dapper鼓励直接写SQL&#xff0c;而不是使用抽象查询语…

从独立开发者到成为SeaTunnel社区的贡献者,我做对了哪些事儿?

个人介绍 大家好&#xff0c;我是闫成雨&#xff0c;目前是一名独立开发者。专注于数据开发、机器学习、资源调度算法和分布式系统。 GitHub ID: CheneyYin 个人主页&#xff1a;https://cheneyyin.github.io/ 为社区做了哪些贡献 加强了Spark引擎和Flink引擎对SeaTunnel数据…

photoshop(PS)有什么快速提升工作效率的功能?或者实用功能?这里告诉你7条!

1:文件太多&#xff0c;不方便马上找到需要插入元素&#xff08;元素放入PS会发现&#xff0c;位置不知道在哪里&#xff09;&#xff0c;点击需要选中或者搭配的元素&#xff0c;ctrlV就可以快速插入目标/图层元素的位置了&#xff01; 点击当前元素&#xff0c;选中&#xf…

MT3035 逆波兰式

思路&#xff1a; 两个栈str1和sr2&#xff0c;分别存放运算符和结果。 如果是数字&#xff0c;直接放入str2中。 如果是运算符&#xff1a; 1. ( &#xff1a;直接放入 str1 2. /-/*// 看栈顶元素&#xff0c;若当前字符优先级比栈顶大&#xff0c;则压到str1中&#x…

【STL】string

本节博客主要是介绍了一下CPP标准库中的string这一容器的相关用法和常用接口&#xff0c;有需要借鉴即可。 目录 1.string介绍1.1CPP标准库与STL关系1.2string历史问题与介绍 2.string概要3.Member functions3.1constructor3.2operator 4.访问4.1[]访问4.2迭代器访问4.3范围for…

软件测试的一些概念

一.基本概念 1.什么事需求 1&#xff09;需求的定义 用户需求&#xff1a;可以简单理解为甲方提出的需求&#xff0c;如果没有甲方&#xff0c;那么就是终端用户使用产品时&#xff0c;必须完成的任务&#xff0c;该需求一般比较简略 软件需求&#xff1a;或则叫功能需求&a…

【Amplify_自己写的shadr遇到没有阴影的解决方案】

Amplify 自己写的shadr遇到没有阴影的解决方案 2020-01-21 16:04 本来我有个百试很灵的投射阴影脚本。 这次不灵光了&#xff01;地形内建材质&#xff0c;这个不支持投射的阴影~~奇了怪了。 可以采用引用的方式UsePass加入阴影部分代码&#xff0c;具体操作如下&#xff1…

视觉SLAM14精讲——三维空间刚体运动1.2

三维空间刚体运动 欧拉角 欧拉角可以说是零理解成本的表示形式&#xff0c;由于有万向锁的问题被绝大部分项目所抛弃。欧拉角的每个轴旋转都有固定好的名称&#xff0c;这些名称十分直观&#xff1a; Z轴旋转&#xff0c;相当于左右旋转&#xff0c;叫航角&#xff0c;或偏航…

photoshop(PS)有什么快速提升工作效率的功能?或者实用功能?这里告诉你5条!

1:文件太多&#xff0c;不方便马上找到需要插入元素&#xff08;元素放入PS会发现&#xff0c;位置不知道在哪里&#xff09;&#xff0c;点击需要选中或者搭配的元素&#xff0c;ctrlV就可以快速插入目标/图层元素的位置了&#xff01; 点击当前元素&#xff0c;选中&#xf…