【数字信号去噪】基于matlab柯西近端分裂CPS算法信号去噪【含Matlab源码 1889期】

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【数字信号去噪】基于matlab柯西近端分裂CPS算法信号去噪【含Matlab源码 1889期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

%% 通过 Cauchy 近端分裂算法去模糊
% y = x + n
% y is the 1D noisy signal
% x is the clear (noise-free) signal (object of interest)
% n is the additive zero-meam Gaussian noise with SNR

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars
close all
clc
%% 参数初始化
sizeSignal = 7;
M = 2^sizeSignal;
N = 2^(sizeSignal + 2);
SNRdB = 3;
rmse = @(err) sqrt(mean(abs(err(:)).^2));
truncate = @(x, M) x(1:M);
AH = @(x) fft(x, N)/sqrt(N);
A = @(X) truncate(ifft(X), M) * sqrt(N);
Niter = 500;
[x,y] = wnoise(3, sizeSignal, SNRdB);
x = x';
y = y';
%% 柯西
x_hat = AH(zeros(size(y))); % 正则化结果
iter = 1;
old_X = x_hat;
grad_f_x = @(x) AH(A(x) - y); % 梯度算子
xx = ones(size(y));
yy = 0*ones(size(y));
Lip = norm(grad_f_x(xx) - grad_f_x(yy), 2)/norm(xx - yy, 2); % Lipschitz 常数的一般计算。
mu = 1.5/Lip;
gamma = 2*sqrt(mu)/2;
delta_x = inf;
tic;
while (delta_x(iter) > 1e-3) && (iter < Niter)
    iter = iter + 1;
    Z = x_hat - mu*(AH(A(x_hat) - y));
    x_hat = CauchyProx(real(Z), gamma, mu);
    delta_x(iter) = max(abs( x_hat(:) - old_X(:) )) / max(abs(old_X(:))); % 误差计算
    old_X = x_hat;
end 
x_Cauchy = A(x_hat);
timeSim = toc;
RMSE_noisy = rmse(x - y);
RMSE_regularized = rmse(x - x_Cauchy);
fprintf('Cauchy proximal splitting (CPS) for 1D denoising\nSolved after %d iterations in %.3f seconds\nNoisy RMSE = %.3f\nReconstructed RMSE = %.3f\n', iter, timeSim, RMSE_noisy, RMSE_regularized)

figure;
set(gcf, 'Position', [100 100 800 300])
subplot('Position', [0.0501, 0.1001, 0.9, 0.85])
plot(x, 'b', 'Linewidth', 1.5)
hold on
plot(y, 'k-.', 'Linewidth', 1)
plot(x_Cauchy, 'r--', 'Linewidth', 2)
grid on
legend('Noise-free', ['Noisy (SNR = ' num2str(SNRdB) ' dB)'], 'CPS')
text(40, 0.9*max(y), ['RMSE_{Noisy} = ' num2str(RMSE_noisy)], 'Color', 'Black')
text(40, 0.6*max(y), ['RMSE_{CPS} = ' num2str(RMSE_regularized)], 'Color', 'Red')

三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.

猜你喜欢

转载自blog.csdn.net/TIQCmatlab/article/details/125338870