I've tried running this code but unfortunately it doesn't work because of the 'symPower' is unrecognizable function or variable. Would definitely appreciate the help. Thanks

2 ビュー (過去 30 日間)
Kaeshwin
Kaeshwin 2022 年 10 月 4 日
回答済み: Vijay 2022 年 10 月 14 日
function [powerFactor,decOrder] = allocatePower(symPower,gainH,targetSNR_1,targetSNR_2,nVar)
% This function is to allocate transmit power to users based on their
% channel gain. The power is allocated to make both users achieve a target
% SNR.
[numUE,numSC] = size(gainH);
% Channel gain levels
gainDiff = diff(gainH,[],1); % column2-column1
highGain(logical(gainDiff<0)) = 1;
highGain(logical(gainDiff>0)) = 2;
lowGain(logical(gainDiff>0)) = 1;
lowGain(logical(gainDiff<0)) = 2;
highGain = highGain.';
lowGain = lowGain.';
% Calculate power allocation factor
powerFactor = zeros(numSC,numUE);
for sc = 1:numSC
lowPower = targetSNR_2*nVar./(symPower*gainH(highGain(sc),sc));
highPower = (targetSNR_1*(lowPower.*symPower*gainH(highGain(sc),sc)+nVar))./symPower*gainH(lowGain(sc),sc);
highPowerFactor = highPower./(highPower+lowPower);
lowPowerFactor = lowPower./(highPower+lowPower);
powerFactor(sc,highGain(sc)) = lowPowerFactor;
powerFactor(sc,lowGain(sc)) = highPowerFactor;
end
decOrder = zeros(numSC,numUE);
[~,decOrder(:,1)] = max(powerFactor,[],2);
[~,decOrder(:,2)] = min(powerFactor,[],2);
Output: allocatePower(symPower, gainH, targetSNR_1, targetSNR_2, nVar)
Unrecognized function or variable 'symPower'.

回答 (1 件)

Vijay
Vijay 2022 年 10 月 14 日
Hello @Kaeshwin
Please make sure all variables are defined before using them.
For example
symPower, on of the variables used while calling, must be defined first
you need to define all the variables before calling the function allocatePower.
Example Values:
symPower = 1;
gainH = 0.2;
targetSNR_1 = 10;
targetSNR_2 = 20;
nvar=100;
%above values are just for example, please chose suitable values.
[output_1, output_2] = allocatePower(symPower, gainH, taragetSNR_1, targetSNR_2, nvar);

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by