Why this code gives error on line 47?
Show older comments
I downloaded the code attached from the following URL of Mathworks site:
When I run it, it gives the folloing error which I don't know why?
Unrecognized function or variable 'vec'.
Error in EPUMA>pumaUpdate (line 47)
f = -vec(U(L+1:end,:));
Error in EPUMA (line 26)
DOA_Cand = pumaUpdate(U, S, L, K, maxIter);
Error in demo (line 25)
doa_estimates = EPUMA(x, K);
7 Comments
Star Strider
on 29 Dec 2022
I looked through the code and also searched the online documentation and did an online search and couldn’t find anything. It could refer to an obsolete or renamed function, since the ‘epuma’ function was written in 2018.
Contact the authors and ask them to describe what the ‘vec’ function is supposed to do, and if there’s an updated (renamed) replacement for it.
Sadiq Akbar
on 30 Dec 2022
Star Strider
on 30 Dec 2022
My pleasure!
Please post the author’s response back here. I would like to know how this resolves.
M = 10; % # of sensors
N = 40; % # of samples
doa = [1,18]; % direction-of-arrivals
K = length(doa); % number of sources
SNR = 10; % signal-to-noise ratio
% array manifold, ULA with half-interelement spacing
A = exp(1j*[0:M-1]'*pi*sind(doa));
% uncorrelated source signals
% st = (randn(K,N) + 1j*randn(K,N))/sqrt(2);
% coherent source signals
st = (randn(K,N) + 1j*randn(K,N))/sqrt(2);
st(1,:) = st(2,:);
% additive noise
nt = (randn(M,N) + 1j*randn(M,N))/sqrt(2);
% received signal
x = A*st*10^(SNR/20) + nt;
doa_estimates = EPUMA(x, K);
norm(doa_estimates(:) - doa(:))^2
function [doa_hat] = EPUMA(x, K, L, maxIter)
%% If you find the code is useful, please cite our paper
% C. Qian, L. Huang, N. D. Sidiropoulos and H. C. So,
% "Enhanced PUMA for direction-of-arrival estimation and its performance analysis,"
% IEEE Transactions on Signal Processing, vol.64, no.16, pp.4127-4137, 2016.
%%
warning off;
if nargin<3
L = K + 1;
maxIter = 3;
elseif nargin<4
maxIter = 3;
end
[M,N] = size(x);
R = x*x'/N;
J = fliplr(eye(M));
R = 0.5*(R + J*conj(R)*J);
[U,S] = svd(R);
U = U(:,1:K);
S = diag(S);
DOA_Cand = pumaUpdate(U, S, L, K, maxIter);
%DOA_bank = combntns(DOA_Cand,K);
DOA_bank = nchoosek(DOA_Cand,K);
for i = 1:size(DOA_bank,1)
A = exp(1j*pi*[0:M-1]'*sind(DOA_bank(i,:)))/sqrt(M);
mlObjVal(i) = trace((eye(M)-A/(A'*A)*A')*R);
end
[~,I] = min(mlObjVal);
doa_hat = sort(DOA_bank(I,:));
end
function DOA = pumaUpdate(U,S,L,K,maxitr)
M = size(U,1);
D = [];
for i = 1:K
D = [D; toeplitz(U(L:M-1,i), U(L:-1:1,i))];
end
f = -vec(U(L+1:end,:));
sigman2 = mean(S(K+1:M));
SS = S(1:K) + 1e-10;
c = D\f;
for i = 1:maxitr
A = toeplitz([c(L),zeros(1,M-L-1)].', [fliplr(c.'),1,zeros(1,M-L-1)]);
W = kron(diag((SS - sigman2).^2./SS), inv(A*A'));
c = (D'*W*D)\D'*W*f;
end
c1 = c;
c = [1, c1.'];
rs = roots(c);
DOA = asin(angle(rs)/pi)*180/pi;
end
function v = vec(m)
%Helper function to turn a matrix of any size into a column vector using (:)
% This function is meant to make one-line computations easy/fast when
% subscripting already.
%SCd 01/04/2011 (First function of 2011!)
%
%Updates: -05/24/2011: Used reshape instead of colon for speed.
%
%Usage: v = vec(m)
%
%Example:
% %Original way to one line the median of a slice of 3d matrix:
% M = repmat(magic(200),[1 1 200]); %200x200x200 magic squares
% Mmed = median(reshape(M(:,:,34),[],1)); %34th slice
%
% %Using the vec() function
% Mmed = median(vec(M(:,:,34)));
%
%Input Arguments:
% -m: matrix of any size
%
%Output Arguments:
% -v: m(:)
%
%See Also: colon reshape
%
v = reshape(m,numel(m),1);
end
Star Strider
on 30 Dec 2022
Where did you find the ‘vec’ code? I didn’t see it listed amongst the functions in the ‘EPUMA’ File Exchange entry. I looked everywhere that I could think of for it and even did searches.
Torsten
on 30 Dec 2022
Seems that by chance it's the "correct" vec-function.
Star Strider
on 30 Dec 2022
Thanks.
I discovered that in my search, however I wasn’t certain it was the correct function. since I had no idea what the result was supposed to be.
In any event, a version of it should have been included in the ‘EPUMA’ function files.
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!