The following Matlab code runs only half of the for loop. Can anyone help me figure out the problem?

조회 수: 4 (최근 30일)
Here is the part of the matlab Code that I was working for an SDR development.
In the following code, when the ind in the for loop below exceeds four or more than
half fo the loop, it stops and gives me an error.
Can someone help me and let me know the reason why it happens in MATLAB.
// The code begins here.
NumFrames =10;
%% Build OFDM Modulator
FFTLength = 64;
NumGuardBandCarriers = [6; 5];
NumDataCarriers = 48;
CyclicPrefixLength = 16;
PilotCarrierIndices = [12;26;40;54];
NumOFDMSymInPreamble = 5;
NumBitsPerCharacter = 7;
SampleRate = 20e6;
Fs = SampleRate;
msgInBits = repmat(randi([0 1], NumDataCarriers, 1),10160, 1);
PayloadBits = msgInBits(:);
MSDU = ceil(length(PayloadBits)/(NumFrames*NumDataCarriers));
txData = zeros(0,1);
for ind = 0 : (NumFrames-1)
framebody = PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:);
txData = [txData; framebody];
PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:)=[];
if(ind == 4) // When Ind exceeds more than half the loop, it creates error message.
return
end
end
  댓글 수: 1
Steven Lord
Steven Lord 2020년 4월 28일
What is the full and exact text of the error message you receive? Show all the text displayed in red and/or orange when you receive the error.

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

채택된 답변

Tommy
Tommy 2020년 4월 28일
PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:)=[];
This line changes the size of PayloadBits, but you have set up MSDU, NumDataCarriers, and ind based on the initial size of PayloadBits. Will it work if you omit this line? i.e.
for ind = 0 : (NumFrames-1)
framebody = PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:);
txData = [txData; framebody];
end
  댓글 수: 2
jarul
jarul 2020년 4월 29일
Yes! I removed the line that you mentioned above. However, running the loop that you have mentioned runs till the last element. But, the last element index exceeds the limit and can not complete the array. Basically it runs n-1 array element only.
I do not know why?
jarul
jarul 2020년 4월 29일
Hai I got the result. Thanks.
The problem is PayloadBIts adds some padded bits to make the array equal size. Hence, after adding the padded extra bits in the image file. It works correctly. Here is the snippet of the code that works correctly.
I am working on Schmidl Cox algorithm for the Multi-SDR. Thanks for your valuable feedback.
% Calculate number of OFDM symbols per frame
%NumOFDMSymbols = ceil(length(PayloadBits)/(NumDataCarriers));
NumOFDMSymbols = ceil(length(PayloadBits)/(NumDataCarriers*NumFrames));
% Calculate number of bits padded in each frame
NumPadBits = (NumOFDMSymbols*NumDataCarriers*NumFrames) - length(PayloadBits);
PayloadBits(numel(PayloadBits)+NumPadBits)=0;
MSDU = ceil(length(PayloadBits)/(NumFrames*NumDataCarriers));
txData = zeros(0,1);
for ind = 0 : NumFrames-1
framebody = PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:);
txData = [txData; framebody];
%PayloadBits((ind*MSDU*NumDataCarriers)+1:(NumDataCarriers*MSDU)*(ind+1),:)=[];
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by