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

Star Strider
Star Strider 2022년 12월 29일
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
Sadiq Akbar 2022년 12월 30일
Thank you very much dear Star Strider for your kind response. Yes you are right. Let me ask the author.
Star Strider
Star Strider 2022년 12월 30일
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
ans = 0.0048
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
Star Strider 2022년 12월 30일
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.
Star Strider
Star Strider 2022년 12월 30일
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2022년 12월 30일

0 개 추천

Try this:
f = -U(L + 1 : end, :); % Extract rows (L+1) downwards, and all columns. f will be a 2-D matrix.
% Turn this 2-D matrix f into a column vector.
% Stack columns underneath each other, like [col1; col2; col3; col4; last column]
f = f(:);

댓글 수: 7

Sadiq Akbar
Sadiq Akbar 2022년 12월 30일
Thanks to both of you dear Torsten and Image Analyst. Both the codes work the same. Now whose answer should I accept as both of you have done very well?
Image Analyst
Image Analyst 2022년 12월 30일
Torsten didn't post his code as an answer. Not sure what he did or fixed. He did seem to find the vec function that Star couldn't find. I just basically looked at what the vec function did and did away with the function, since there is no need for a special function to turn a matrix into a column vector. So you won't need vec anymore.
If the Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
Sadiq Akbar
Sadiq Akbar 2022년 12월 30일
As you said, I can vote to several answers but can accept one only, so I accepted yours but also want to give vote to Torsten answer as he also solved my problem. But the problem is that vote icon is visible with your answer only. It's not visible witht he Torsten answer. So how can I vote his answer also?
Torsten
Torsten 2022년 12월 30일
No problem.
Seems this "vec" function works for your case (and does the same as in @Image Analyst answer).
Image Analyst
Image Analyst 2022년 12월 30일
@Torsten has the ability to move his comment to an Answer. Then you could vote for it. @Sadiq Akbar thanks for being so caring.
Sadiq Akbar
Sadiq Akbar 2022년 12월 30일
@Image Analyst I always accept the answer when I get satisfied. Actually I didn't know about the vote till date. However now it is known to me but the option is not available, therefore cannot do it though I would like to do it. However, thanks to all of you oncd again.
Image Analyst
Image Analyst 2022년 12월 30일
The vote capability is for other users to say that an answer is good. Sometimes original posters just accept the first one blindly. Sometimes just because it's the first one on the list and they think they can accept multiple answers (if there were multiple ones that were right). Or sometimes they accepted too quickly (like as soon as they got the very first answer) and another one comes along shortly afterwards. They can Unaccept and accept the better one, but few people bother to do that. So the votes are for the community to say which one they think is really the best answer. Or sometimes, not the absolute best answer but just a very good answer that they think the Answerer should get credit for in terms of Reputation Points. Mathworks can extend certain perks to high earning Answerers (privileges, swag mechandise, etc.) so that's why people like to earn points.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2022년 12월 29일

댓글:

2022년 12월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by