question related with 8-PSK modulation

조회 수: 4 (최근 30일)
Abdul Hamzah
Abdul Hamzah 2024년 2월 7일
편집: Abdul Hamzah 2024년 2월 8일
Hello everyone, I am working on a matlab code for 8-QPSK modulation & demodulation to calculate BER which can be seen below :
% Modulation order M
M = 8;
k = log2(M); % Bits per symbol
EbNoVec = (5:15); % Eb/No values (dB)
numSymPerFrame = 1000; % Number of PSK symbols per frame
berEst = zeros(size(EbNoVec));
for n = 1:length(EbNoVec)
% Convert Eb/No to SNR
snrdB = EbNoVec(n) + 10*log10(k);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e7
% Generate binary data and convert to symbols
data_in = randi([0 1],numSymPerFrame,1);
%----------------------------------------------------------------
% Your modulator here:
modSig = pskmod(data_in,M,InputType='bit'); % PSK Modulation
% Pass through AWGN channel:
rxSig = awgn(modSig, snrdB); % Additive White Gaussian Noise with
% increasing snrdB
% Your demodulator here:
data_out = pskdemod(rxSig,M); % PSK Demodulation
%----------------------------------------------------------------
% Calculate the number of bit errors
nErrors = biterr(data_in,data_out);
numErrs = numErrs + nErrors;
numBits = numBits + numSymPerFrame*k;
end
% Estimate the BER
berEst(n) = numErrs/numBits;
fprintf("snrdB: %.6f berEst: %.6f " + ...
" \n \t numErrs: %d numBits: %d\n\n", snrdB, berEst(n), numErrs, numBits);
end
Error using pskmod
When InputType is set to 'Bit', the number of rows in the input X must be an integer multiple of the number of bits per symbol.
I am able to run this code when I set the M to 16 but I cannot run it when I set the M to 8, and matlab says that the error is on pskmod..do you know what's wrong with this code? Any response for this question is very appreciated, thanks before.

채택된 답변

Voss
Voss 2024년 2월 7일
With M = 8, you have log2(M) == 3 bits per symbol. Later you generate 1000 bits, but this is not an integer number of symbols at 3 bits/symbol (it is an integer at 4 bits per symbol when M = 16, so you don't get that error in that case).
It seems like you want 1000 symbols (i.e., numSymPerFrame = 1000), not 1000 bits, so you have to generate numSymPerFrame*k bits (i.e., 3000 bits when M == 8, or 4000 bits when M == 16).
Also, you need to specify OutputType='bit' in pskdemod in order to use biterr to compare bit sequences.
% Modulation order M
M = 8;
k = log2(M); % Bits per symbol
EbNoVec = (5:15); % Eb/No values (dB)
numSymPerFrame = 1000; % Number of PSK symbols per frame
berEst = zeros(size(EbNoVec));
for n = 1:length(EbNoVec)
% Convert Eb/No to SNR
snrdB = EbNoVec(n) + 10*log10(k);
% Reset the error and bit counters
numErrs = 0;
numBits = 0;
while numErrs < 200 && numBits < 1e7
% Generate binary data and convert to symbols
data_in = randi([0 1],numSymPerFrame*k,1);
%----------------------------------------------------------------
% Your modulator here:
modSig = pskmod(data_in,M,InputType='bit'); % PSK Modulation
% Pass through AWGN channel:
rxSig = awgn(modSig, snrdB); % Additive White Gaussian Noise with
% increasing snrdB
% Your demodulator here:
data_out = pskdemod(rxSig,M,OutputType='bit'); % PSK Demodulation
%----------------------------------------------------------------
% Calculate the number of bit errors
nErrors = biterr(data_in,data_out);
numErrs = numErrs + nErrors;
numBits = numBits + numSymPerFrame*k;
end
% Estimate the BER
berEst(n) = numErrs/numBits;
fprintf("snrdB: %.6f berEst: %.6f " + ...
" \n \t numErrs: %d numBits: %d\n\n", snrdB, berEst(n), numErrs, numBits);
end
snrdB: 9.771213 berEst: 0.034500 numErrs: 207 numBits: 6000 snrdB: 10.771213 berEst: 0.018750 numErrs: 225 numBits: 12000 snrdB: 11.771213 berEst: 0.012056 numErrs: 217 numBits: 18000 snrdB: 12.771213 berEst: 0.006028 numErrs: 217 numBits: 36000 snrdB: 13.771213 berEst: 0.002556 numErrs: 207 numBits: 81000 snrdB: 14.771213 berEst: 0.000976 numErrs: 202 numBits: 207000 snrdB: 15.771213 berEst: 0.000310 numErrs: 201 numBits: 648000 snrdB: 16.771213 berEst: 0.000059 numErrs: 200 numBits: 3378000 snrdB: 17.771213 berEst: 0.000008 numErrs: 78 numBits: 10002000 snrdB: 18.771213 berEst: 0.000001 numErrs: 12 numBits: 10002000 snrdB: 19.771213 berEst: 0.000000 numErrs: 0 numBits: 10002000
  댓글 수: 2
Abdul Hamzah
Abdul Hamzah 2024년 2월 7일
wow it's working....thank you so much for your help 😁🙏
Voss
Voss 2024년 2월 7일
You're welcome!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by