フィルターのクリア

Save Variable in for Loop

4 ビュー (過去 30 日間)
Ibnu Darajat
Ibnu Darajat 2022 年 10 月 29 日
コメント済み: Ibnu Darajat 2022 年 10 月 29 日
Here is the code for M-ary PSK modulation and demodulation:
custMap = [0 2 4 6 8 10 12 14 15 13 11 9 7 5 3 1];
pskModulator = comm.PSKModulator(16,'BitInput',true, ...
'SymbolMapping','Custom', ...
'CustomSymbolMapping',custMap);
pskDemodulator = comm.PSKDemodulator(16,'BitOutput',true, ...
'SymbolMapping','Custom', ...
'CustomSymbolMapping',custMap);
constellation(pskModulator)
awgnChannel = comm.AWGNChannel('BitsPerSymbol',log2(16));
errorRate = comm.ErrorRate;
ebnoVec = 6:18;
ber = zeros(size(ebnoVec));
for k = 1:length(ebnoVec)
% Reset the error counter for each Eb/No value
reset(errorRate)
% Reset the array used to collect the error statistics
errVec = [0 0 0];
% Set the channel Eb/No
awgnChannel.EbNo = ebnoVec(k);
while errVec(2) < 200 && errVec(3) < 1e7
% Generate a 1000-symbol frame
data = randi([0 1],4000,1);
% Modulate the binary data
modData = pskModulator(data);
% Pass the modulated data through the AWGN channel
rxSig = awgnChannel(modData);
% Demodulate the received signal
rxData = pskDemodulator(rxSig);
% Collect the error statistics
errVec = errorRate(data,rxData);
end
% Save the BER data
ber(k) = errVec(1);
end
berTheory = berawgn(ebnoVec,'psk',16,'nondiff');
figure
semilogy(ebnoVec,[ber; berTheory])
xlabel('Eb/No (dB)')
ylabel('BER')
grid
legend('Simulation','Theory','location','ne')
From that code we can save the BER data, my question is how to save "rxData" variable like BER data in the for loop function above?

採用された回答

VBBV
VBBV 2022 年 10 月 29 日
編集済み: VBBV 2022 年 10 月 29 日
K = 1 % place this outside the for loop
while errVec(2) < 200 && errVec(3) < 1e7
% Generate a 1000-symbol frame
data = randi([0 1],4000,1);
% Modulate the binary data
modData = pskModulator(data);
% Pass the modulated data through the AWGN channel
rxSig = awgnChannel(modData);
% Demodulate the received signal
rxData(K,k) = pskDemodulator(rxSig);
% Collect the error statistics
errVec = errorRate(data,rxData);
K = K +1;
end
  10 件のコメント
VBBV
VBBV 2022 年 10 月 29 日
Please accept the answer if it worked well
Ibnu Darajat
Ibnu Darajat 2022 年 10 月 29 日
Thankyou very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by