-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.m
More file actions
153 lines (130 loc) · 3.69 KB
/
Copy pathdemo.m
File metadata and controls
153 lines (130 loc) · 3.69 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
%% Demo of (ISLR) estimating a low-rank and sparse matrix from noisy observation
%
% Please cite as:
% Improved Sparse and Low-Rank Matrix Estimation. (PrePrint)
% A. Parekh and I. W. Selesnick. Preprint https://arxiv.org/abs/1605.00042
%
% Contact: Ankit Parekh, ankit.parekh@nyu.edu
% Last Edit: 11/24/16.
%% Initialize Definitions
clear, clc; close all;
rse = @(org, est) norm(org-est) / norm(org);
dB = @(x) 20 * log10(abs(x));
SNR = @(x,y) 10 * log10(sum(abs(x).^2)/sum(abs(x-y).^2));
%% Load test signal
load TestSignal;
fs = 22050;
N = length(s);
n = 0:N-1;
% Create noisy signal
rng('default')
sigma = 0.03;
y = s + sigma*randn(size(s));
% Make transforms
R = 64; M = 2; K = 1; Nfft = 512;
[AH, A, normA] = MakeTransforms('STFT',N,[R M K Nfft]);
% Plot noise free data
figure(1), clf
subplot(2,1,1), plot(n/fs, s,'k')
box off
title('Noise free speech signal (y)')
xlim([0 N]/fs)
ylim([-0.3 0.3])
As = A(s);
subplot(2,1,2)
tt = R/M * ( (0:size(As, 2)) - 1 )/fs; % tt : time axis for STFT
imagesc(tt, [0 0.5], dB(As(1:Nfft/2+1, :)), max(dB(As(:))) + [-50 -5])
axis xy
xlim([0 N]/fs)
ylim([0 0.3])
title('STFT of Noise-free data')
ylabel('Frequency')
xlabel('Time(s)')
colorbar
% Plot the noisy data
figure(2), clf
subplot(2,1,1), plot(n/fs, y,'k')
ylim([-0.3 0.3])
xlim([0 N]/fs)
box off
title(sprintf('Noisy speech signal (y), SNR = %2.2f dB', SNR(s,y)))
Ay = A(y);
subplot(2,1,2)
tt = R/M * ( (0:size(Ay, 2)) - 1 )/fs;
imagesc(tt, [0 0.5], dB(Ay(1:Nfft/2+1, :)), max(dB(As(:))) + [-50 -5])
axis xy
colorbar
xlim([0 N]/fs)
ylim([0 0.3])
title('STFT of Noisy data')
ylabel('Frequency')
xlabel('Time(s)')
%% Estimate matrix X using atan and l1 penalty
lam1 = 0.029;
lam2 = 0.015;
mu = 1.5;
Nit = 20;
pen = 'atan';
[Ax, cost] = lrs_single(Ay,0.1,lam1,lam2,mu,pen,Nit);
[AxL1,costL1] = lrs_single(Ay,0.1,0.025,0.009,mu,'l1',Nit);
%% Plot cost function history
figure(3), clf
plot(cost, 'k'); hold on
plot(costL1, ':.k')
legend('ISLR', 'SLR')
title('Cost function history for atan (ISLR) and L1 (SLR)')
box off
%%
figure(4), clf
subplot(4,1,1)
tt = R/M * ( (0:size(As, 2)) - 1 )/fs; % tt : time axis for STFT
imagesc(tt, [0 1], dB(As(1:Nfft/2+1, :)), [-65 -20])
axis xy
title('(a) Clean speech spectrogram')
xlim([0 N]/fs)
ylim([0 0.3])
colorbar
ylabel('Frequency (kHz)')
subplot(4,1,2)
tt = R/M * ( (0:size(Ay, 2)) - 1 )/fs; % tt : time axis for STFT
imagesc(tt, [0 1], dB(Ay(1:Nfft/2+1, :)),[-65 -20])
axis xy
title(sprintf('(b) Noisy speech spectrogram. SNR = %2.2f dB', SNR(s,real(AH(Ay)))))
xlim([0 N]/fs)
ylim([0 0.3])
ylabel('Frequency (kHz)')
colorbar
subplot(4,1,3)
tt = R/M * ( (0:size(AxL1, 2)) - 1 )/fs; % tt : time axis for STFT
imagesc(tt, [0 1], dB(A(AH(AxL1(1:Nfft/2+1, :)))),[-65 -20])
axis xy
title(sprintf('(c) SLR estimate. SNR = %2.2f dB', SNR(s,real(AH(AxL1)))))
xlim([0 N]/fs)
ylim([0 0.3])
ylabel('Frequency (kHz)')
colorbar
subplot(4,1,4)
tt = R/M * ( (0:size(Ax, 2)) - 1 )/fs; % tt : time axis for STFT
imagesc(tt, [0 1], dB(A(AH(Ax(1:Nfft/2+1, :)))),[-65 -20])
axis xy
title(sprintf('(d) ISLR (proposed) estimate. SNR = %2.2f dB', SNR(s,real(AH(Ax)))))
set(gca,'XTick',0:0.05:0.2,'YTick',0:0.1:0.3)
xlim([0 N]/fs)
ylim([0 0.3])
ylabel('Frequency (kHz)')
box off
xlabel('Time (s)')
colorbar
set(gcf','PaperPosition',[0 0 3 5])
%% Comparison of SVD values
figure(5), clf
plot(svd(Ay),'color',[0.5 0.5 0.5],'Marker','.'); hold on
plot(svd(As),'.-k');
plot(svd(Ax),'.--k');
plot(svd(AxL1),'.:k');
box off
title('Comparison of Singular Values')
xlabel('index (k)')
ylabel('Singular value \sigma_k(X)')
legend('Noisy','Clean','ISLR','SLR')
xlim([1 12])