-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo1D.m
99 lines (87 loc) · 2.48 KB
/
demo1D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%% 1D signal denoising using undecimated wavelet transform
%
% Ankit Parekh (ankit.parekh@nyu.edu), NYU School of Engineering
%
% Reference:
% Convex denoising using non-convex tight frame regularization
% Ankit Parekh and Ivan W. Selesnick
% IEEE Signal Process. Lett., 2015
%
% Code available at:
% https://sites.google.com/a/nyu.edu/ankit-parekh/research
%% Initializations
clear; clc; close all
rmse = @(y,x) sqrt( sum( (y(:)-x(:)).^2) / numel(y) );
SNR = @(x,y) 20*log10( norm(x(:)) / norm(x(:)-y(:)) );
addpath Functions
addpath Functions/WaveletFunctions
%% Generate noisy signal
N = 512;
n = 0:N-1;
rng('default')
s = MakeSignal('Piece-Regular', N);
sigma = 4.0;
noise = sigma * randn(size(s));
y = s + noise;
figure(1), clf
subplot(2,1,1)
plot(s,'k')
title('Clean Signal')
box off
xlim([0 N])
subplot(2,1,2)
plot(y,'k')
title('Noisy signal')
box off
xlim([0 N])
%% Perform wavelet denoising
K = 3;
J = 4;
[AH,A,normA] = MakeTransforms('DWT',N,[J K]);
lam = cell(J,1);
lamL1 = cell(J,1);
a = cell(J,1);
beta = 2.3;
betaL1 = 1.8;
w = A(y);
for i = 1:J
lam{i} = beta * sigma ./ sqrt(2).^i * ones(size(w{i}));
lamL1{i} = betaL1 * sigma ./ sqrt(2).^i * ones(size(w{i}));
a{i} = 1./lam{i};
end
mu = 2;
Nit = 25;
[x,cost] = bp_ncvxUDWT(y,A,AH,J,lam,a,mu,Nit,'atan');
disp('Solved using non-convex regularization')
[xL1,costL1] = bp_ncvxUDWT(y,A,AH,J,lamL1,a,mu,Nit,'l1');
disp('Solved using convex regularization (L1 norm)')
%% Plot the cost function
figure(2), clf
plot(1:Nit, cost,'.-k')
ylabel('Objective Function')
xlabel('Number of iterations')
box off
xlim([0 Nit])
title('L1 regularization')
figure(3),clf
plot(1:Nit, costL1,'k');
ylabel('Objective Function')
xlabel('Number of iterations')
box off
xlim([0 Nit])
title('Nonconvex regularization')
%% Plot the denoised signals
figure(4), clf
gap = 100;
plot(n,y,'k',n,x-gap,'k',n,xL1-2*gap,'k');
text(256, 50, 'Noisy Signal','horizontalAlignment','center')
text(256, -50,...
sprintf('Non-convex regularization (\\beta = 2.3, RMSE = %1.2f)',...
rmse(s,x)),'horizontalAlignment','center')
text(256, -150, ...
sprintf('L1 regularization (\\beta = 1.8, RMSE = %1.2f)',...
rmse(s,xL1)), 'horizontalAlignment','center')
box off
xlim([0 N])
set(gca,'YTick',[],'YTickLabel',[])
xlabel('Time (n)')