I am getting some errors of a script that I try to run

22 ビュー (過去 30 日間)
Yasantha
Yasantha 2024 年 3 月 31 日
回答済み: Alberto Alvarez Polegre 2024 年 4 月 17 日
When I run below script
% Parameters
M = 16; % Modulation order
k = log2(M); % Bits per symbol
numBits = k * 2.5e5; % Total bits to process
sps = 4; % Samples per symbol (oversampling factor)
filtlen = 10; % Filter length in symbols
rolloff = 0.25; % Filter rolloff factor
% Generate random binary data
dataIn = randi([0 1], numBits, 1);
% Apply convolutional encoding
constrlen = [5 4]; % Code constraint length
genpoly = [23 35 0; 0 5 13]; % Generator polynomials
tPoly = poly2trellis(constrlen, genpoly);
dataEnc = convenc(dataIn, tPoly);
% Modulate using 16-QAM
dataSymbolsIn = bit2int(dataEnc, k);
dataMod = qammod(dataSymbolsIn, M);
% Apply raised cosine filtering
rrcFilter = rcosdesign(rolloff, filtlen, sps);
txSignal = upfirdn(dataMod, rrcFilter, sps, 1);
% Add AWGN (simulate noisy channel)
SNR_dB = 10; % Signal-to-noise ratio in dB
rxSignal = awgn(txSignal, SNR_dB, 'measured');
% Demodulate 16-QAM
dataSymbolsOut = qamdemod(rxSignal, M, 'OutputType', 'bit');
% Viterbi decoding
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
% Calculate bit error rate
bitErrors = biterr(dataIn, decodedData);
bitErrorRate = bitErrors / numBits;
fprintf('Bit Error Rate: %.4f\n', bitErrorRate);
I am getting below errors,
Error using vitdec (line 271)
Length of the input code vector must be a multiple of the number of bits in an
input symbol.
Error in test3 (line 34)
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
can someone help me to correct them

回答 (1 件)

Alberto Alvarez Polegre
Alberto Alvarez Polegre 2024 年 4 月 17 日
You forgot to include the filter at the receiver. Try this:
% Parameters
M = 16; % Modulation order
k = log2(M); % Bits per symbol
numBits = k * 2.5e5; % Total bits to process
sps = 4; % Samples per symbol (oversampling factor)
filtlen = 10; % Filter length in symbols
rolloff = 0.25; % Filter rolloff factor
% Generate random binary data
dataIn = randi([0 1], numBits, 1);
% Apply convolutional encoding
constrlen = [5 4]; % Code constraint length
genpoly = [23 35 0; 0 5 13]; % Generator polynomials
tPoly = poly2trellis(constrlen, genpoly);
dataEnc = convenc(dataIn, tPoly);
% Modulate using 16-QAM
dataMod = qammod(dataEnc,M,InputType='bit');
% Transmit filter
rrcFilter = rcosdesign(rolloff,filtlen,sps);
txSignal = upfirdn(dataMod,rrcFilter,sps);
% Add AWGN (simulate noisy channel)
SNR_dB = 10; % Signal-to-noise ratio in dB
rxSignal = awgn(txSignal, SNR_dB, 'measured');
% Receive filter
rxSignalFilt = upfirdn(rxSignal,rrcFilter,1,sps); % Apply receive filter
rxSignalFilt = rxSignalFilt(filtlen+1:end-filtlen); % Account for filter delay
% Demodulate 16-QAM
dataSymbolsOut = qamdemod(rxSignalFilt, M, 'OutputType', 'bit');
% Viterbi decoding
decodedData = vitdec(dataSymbolsOut, tPoly, 100, 'trunc', 'hard');
% Calculate bit error rate
bitErrors = biterr(dataIn, decodedData);
bitErrorRate = bitErrors / numBits;
fprintf('Bit Error Rate: %.4f\n', bitErrorRate);
You might want to take a look at the Wireless Communications Onramp course.

カテゴリ

Help Center および File ExchangeTest and Measurement についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by