-
Notifications
You must be signed in to change notification settings - Fork 3
/
homework3.m
87 lines (77 loc) · 2.57 KB
/
homework3.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
%% ----- Homework 3 ----- %%
clc;
clear;
close all;
A = randn(4,2) + 1j*randn(4,2);
B = randn(6,2) + 1j*randn(6,2);
X = tensor.mtx_prod_kr(A,B);
[Ahat,Bhat] = tensor.LSKRF(X,4,6);
Xhat = tensor.mtx_prod_kr(Ahat,Bhat);
disp('Checking the NMSE (dB) between the original matrix X and its'...
'reconstruction with LSKRF:')
nmsex = (norm(X- Xhat,'fro')^2)/(norm(X,'fro')^2);
nmsex = 20*log10(nmsex)
disp('Checking the NMSE (dB) between the original matrix A and its'...
'estimation:')
nmsea = (norm(A- Ahat,'fro')^2)/(norm(A,'fro')^2);
nmsea = 20*log10(nmsea)
disp('Checking the NMSE (dB) between the original matrix B and its'...
'estimation:')
nmseb = (norm(B- Bhat,'fro')^2)/(norm(B,'fro')^2);
nmseb = 20*log10(nmseb)
I = 10;
J = 10;
R = 4;
SNR = [0 5 10 15 20 25 30];
nmse = zeros(length(SNR),1);
for snr = 1:length(SNR)
for mc = 1:1000
var_noise = 1/(10^(SNR(snr)/10));
noise = sqrt(var_noise/2)*(randn(I*J,R) + 1j*randn(I*J,R));
A = randn(I,R) + 1j*randn(I,R);
B = randn(J,R) + 1j*randn(J,R);
X = tensor.mtx_prod_kr(A,B);
X_noisy = X + noise;
[Ahat,Bhat] = tensor.LSKRF(X_noisy,I,J);
Xhat = tensor.mtx_prod_kr(Ahat,Bhat);
aux = (norm(X- Xhat,'fro')^2)/(norm(X,'fro')^2);
nmse(snr,1) = nmse(snr,1) + 20*log10(aux);
end
end
nmse = nmse/1000;
figure
txt = ['I = ' num2str(I), ', J = ' num2str(J), ' and R = ' num2str(R)];
plot(SNR,nmse,'-d','color', [0.3010 0.7450 0.9330], "linewidth", 2,...
"markersize", 8, "DisplayName", txt);
hold on;
I = 30;
J = 10;
R = 4;
SNR = [0 5 10 15 20 25 30];
nmse = zeros(length(SNR),1);
for snr = 1:length(SNR)
for mc = 1:1000
var_noise = 1/(10^(SNR(snr)/10));
noise = sqrt(var_noise/2)*(randn(I*J,R) + 1j*randn(I*J,R));
A = randn(I,R) + 1j*randn(I,R);
B = randn(J,R) + 1j*randn(J,R);
X = tensor.mtx_prod_kr(A,B);
X = X + noise;
[Ahat,Bhat] = tensor.LSKRF(X,I,J);
Xhat = tensor.mtx_prod_kr(Ahat,Bhat);
aux = (norm(X- Xhat,'fro')^2)/(norm(X,'fro')^2);
nmse(snr,1) = nmse(snr,1) + 20*log10(aux);
end
end
nmse = nmse/1000;
txt = ['I = ' num2str(I), ', J = ' num2str(J), ' and R = ' num2str(R)];
plot(SNR,nmse,'-d','color', [0.4660 0.6740 0.1880], "linewidth", 2,...
"markersize", 8, "DisplayName", txt);
hold off;
title(['LSKRF performance under imperfect scenario'])
xlabel('SNR (dB)')
ylabel('NMSE (dB)')
legend_copy = legend("location", "northwest");
set(legend_copy,'Interpreter','tex','location','northeast',"fontsize", 12)
grid on;
saveas(gcf,'hw3.png')