question related with 8-PSK modulation
10 次查看(过去 30 天)
显示 更早的评论
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
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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!