Indexing in 4D array

9 ビュー (過去 30 日間)
SHAMA NOREEN
SHAMA NOREEN 2022 年 4 月 11 日
回答済み: Pratik 2023 年 10 月 9 日
I am writing a program where I have 15 Eb/No values for each Eb/No there are 100 packets to be transmitted from Transmitter to reciever. Each packet can have multiple OFDM symbols and each OFDM symbol can have 132 subcarriers.
So my array looks like (EbNo,no_packets,OFDM symbols,no_subcarriers)
for each group of subcarriers I have to perform certain operations. I have to take the average of the power present on each subcarrier. I also have to perform some other functions.
Given the no of symbols are 2 , the average of matrix should be 2*15*100 matrix. But I am stuck in indexing . I have tried many possibilities but my avaerage isnt right.
Also I am passing values into other functions. So should I mention the indexing or not.
for EbN0id = 1:length(EbN0dB_vec)
for np=1:Nof_TxPackets
%------------coding and modulation
[x_time,dataIn,dataMod] = LDPC_Coding_and_Modulation_Power(Nof_BitsPerPacket, poly, bgn, Length_dataEnc, rv, ModOrder(m), nLayers, Nof_OFDMSymbols, Bit_x_symbol(m), Nof_Subcarriers, Nfft, Ncp,optimal_power);
%-----------Add Multipath Channel
if Multipath_Flag
[y_time,H_k] = AddMultipathChannel(DelayProfile_samples, Fading(fi+1:np*Nof_OFDMSymbols,:), Nfft, Ncp, fi, Ts_OFDM, Nof_OFDMSymbols, x_time, Nof_Subcarriers);
else
H_k = ones(Nof_OFDMSymbols,Nof_Subcarriers);
y_time = x_time;
end
Average_power(:,EbN0id,np)=(sum(optimal_power(:,:,EbN0id,np)))/Nof_Subcarriers
gamma(:,:,EbN0id,np)=Gamma_SNR(variance_of_noise, optimal_power(:,:,EbN0id,np),aver_power(:,EbN0id,np),H_k(:,:,EbN0id,np)) ;

回答 (1 件)

Pratik
Pratik 2023 年 10 月 9 日
Hi Shama,
In my understanding, you have a 4D array optimal_power with the dimensions:EbNo, no_packets, no_OFDM_symbols, no_subcarriers. You are attempting to calculate the average power for each packet, each Eb/No value and each OFDM symbol where the result should have the dimensions: no_OFDM_symbols, EbNo, no_packets.
Taking the average to get average power involves summing over the last dimension of the array which is no_subcarriers, then dividing this sum by the number of subcarriers and finally using the “permute” function to get the array in the expected dimension.
The following code snippet demonstrates the use of “permute” function and how the average can be calculated:
% Calculate sum over no_subcarriers dimension
sum_power = sum(optimal_power, 4);
% Calculate average power
Average_power_default = sum_power / Nof_Subcarriers;
% Permute the dimensions
Average_power = permute(Average_power_default, [3 1 2]);
Average_power_default will be a 3D array with dimensions: EbNo, no_packets, no_OFDM_symbols, which represents the average power for each Eb/No value, each packet, and each OFDM symbol. "Average_power" represents the array with expected dimension.
While using the Gamma_SNR function, you should pass the entire 4D array optimal_power and let the function handle the indexing itself. If the need is to pass only a specific part of the array the”:” operator can be used to select all elements belonging to a specific dimension.
Please refer to the following MathWorks documentation link for more information on “permute” function:
Please refer to the following MathWorks documentation link for more information on array indexing:
Hope this helps!

カテゴリ

Help Center および File ExchangeOFDM についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by