How to speed up this function?

조회 수: 2 (최근 30일)
Jonathan Mayers
Jonathan Mayers 2016년 5월 26일
답변: Jonathan Mayers 2016년 5월 26일
Hi all,
I am calculating a value Gamma as shown in the image below.
I have implemented this calculation as a for-loop and I suspect it could be done without using a for-loop and be faster. Every h term is the jth column of an NxK matrix and Pj is the jth column of KxK diagonal matrix P. What is the fastest way to calculate this value?
function [ GAMMA ] = gamma_dnc( P,Hh,Ht,K )
%GAMMA_DNC Calculates the component GAMMA in the DNC
% beamforming matrix V.
% Running total
total = 0;
for j = 1:K
p = P(j,j); % Select jth column of P
ht = Ht(:,j); % Select jth column of Ht
hh = Hh(:,j); % Select jth column of Hh
% Perform summation
h1 = ht*(hh');
h2 = hh*(ht');
h3 = ht*(ht');
h4 = h1 + h2 + h3;
total = total + p*h4;
end
GAMMA = mean2(total);
end
  댓글 수: 1
James Tursa
James Tursa 2016년 5월 26일
What are the dimensions of the variables? And which variables are complex?

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

채택된 답변

Jonathan Mayers
Jonathan Mayers 2016년 5월 26일
Matrix P is a real-valued matrix and the H matrices are complex-valued matrices. I have found a way to do it without looping.
function [ GAMMA ] = gamma_dnc( P,Hh,Ht )
%GAMMA_DNC Calculates the component GAMMA in the DNC
% beamforming matrix V.
% Store transposes of matrices to reduce
% function call overhead
Hh_tp = Hh';
Ht_tp = Ht';
% Compute intermediate products
H1 = Ht*Hh_tp;
H2 = Hh*Ht_tp;
H3 = Ht*Ht_tp;
H4 = H1 + H2 + H3;
H5 = P(1,1)*H4; % All users transmit with equal power
T = sum(H5); % Find sum of all columns
GAMMA = mean(T)/10; % Have to divide by 10 for some reason
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by