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?

 Respuesta aceptada

VBBV
VBBV el 29 de Oct. de 2022
Editada: VBBV el 29 de Oct. de 2022

0 votos

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 comentarios

VBBV
VBBV el 29 de Oct. de 2022
You can add a loop counter inside the while loop.
Ibnu Darajat
Ibnu Darajat el 29 de Oct. de 2022
After I try like this:
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));
K=1;
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(K,k) = pskDemodulator(rxSig);
% Collect the error statistics
errVec = errorRate(data,rxData);
K = K+1;
end
% Save the BER data
ber(k) = errVec(1);
end
I got this error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right
side is 4000-by-1.
Error in Untitled2 (line 32)
rxData(K,k) = pskDemodulator(rxSig);
VBBV
VBBV el 29 de Oct. de 2022
rxData(:,k) = pskDemodulator(rxSig);
VBBV
VBBV el 29 de Oct. de 2022
Can you check again with the above change
Ibnu Darajat
Ibnu Darajat el 29 de Oct. de 2022
I just tried it:
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));
K=1;
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(:,k) = pskDemodulator(rxSig);
% Collect the error statistics
errVec = errorRate(data,rxData);
K = K+1;
end
% Save the BER data
ber(k) = errVec(1);
end
and got this error:
>> Untitled2
Error using ErrorRate
Multichannel operation is not supported.
Error in Untitled2 (line 34)
errVec = errorRate(data,rxData);
did i missing something? Thanks before
VBBV
VBBV el 29 de Oct. de 2022
Editada: VBBV el 29 de Oct. de 2022
errVec = errorRate(data,rxData(:,k));
Ok. Then you need to pass the vector for the rxData data as shown above
Ibnu Darajat
Ibnu Darajat el 29 de Oct. de 2022
Oke thanks that worked.
And the value result is 4000x13 double (because size Eb/No is 6:18) as shown below:
My last question, how can I retrieve data from specific row?
VBBV
VBBV el 29 de Oct. de 2022
rxData(1,:) = pskDemodulator(rxSig);
This retrieves all data from row 1
VBBV
VBBV el 29 de Oct. de 2022
Please accept the answer if it worked well
Ibnu Darajat
Ibnu Darajat el 29 de Oct. de 2022
Thankyou very much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Detection, Range and Doppler Estimation en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 29 de Oct. de 2022

Comentada:

el 29 de Oct. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by