-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_from_A_P_s.m
43 lines (36 loc) · 931 Bytes
/
x_from_A_P_s.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
function [x, residual_norm, x_error] = x_from_A_P_s(A, P, s, opts)
%UNTITLED19 Summary of this function goes here
% Detailed explanation goes here
arguments
A (:,:,:) double
P (:,:) double
s (:,1) double
opts.x_exp = [];
opts.real_flag = true;
opts.verbose = false;
end
Q = size(A,1);
K = size(A,2);
F = size(A,3);
assert(isequal(size(P), [Q, F]));
assert(isequal(size(s), [F, 1]));
As = A .* reshape(s, [1, 1, F]); % [Q, K, F]
As = permute(As, [1, 3, 2]); % [Q, F, K]
As = reshape(As, [], K); % [QF, K];
P = P(:); % [QF, 1];
if opts.real_flag
x = lsreal(As, P);
else
x = As\P;
end
residual_norm = norm(P-As*x);
if ~isempty(opts.x_exp)
x_error = scale_invariant_mse(x, opts.x_exp);
else
x_error = nan;
end
if opts.verbose
fprintf("x error: %.2f dB\n", 10*log10(x_error));
fprintf("residual norm (normalized): %.2f dB\n", 20*(log10(residual_norm) - log10(norm(P))));
end
end